Main Content

fclose (serial)

(To be removed) Disconnect serial port object from device

This serial object function will be removed in a future release. Use serialport object functions instead. For more information on updating your code, see Compatibility Considerations.

Syntax

fclose(obj)

Description

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

Examples

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');
fopen(s)
fprintf(s, '*IDN?')
idn = fscanf(s);
fclose(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.

Tips

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.

Version History

Introduced before R2006a

collapse all

R2021a: serial object interface will be removed

Use of this function with a serial object will be removed. To access a serial port device, use a serialport object with its functions and properties instead.

The recommended functionality has additional capabilities and improved performance. See Transition Your Code to serialport Interface for more information about using the recommended functionality.

See Also

Functions