This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

fclose (serial)

Disconnect serial port object from device




fclose(obj) disconnects obj from the device, where obj is a serial port object or an array of serial port objects.


This example creates the serial port object s on a Windows® platform, connects s to the device, writes and reads text data, and then disconnects s from the device using fclose.

s = serial('COM1');
fprintf(s, '*IDN?')
idn = fscanf(s);

At this point, the device is available to be connected to a serial port object. If you no longer need s, you should remove from memory with the delete function, and remove it from the workspace with the clear command.


If obj was successfully disconnected, then the Status property is configured to closed and the RecordStatus property is configured to off. You can reconnect obj to the device using the fopen function.

An error is returned if you issue fclose while data is being written asynchronously. In this case, you should abort the write operation with the stopasync function, or wait for the write operation to complete.

Introduced before R2006a