Documentation

fclose (serial)

Disconnect serial port object from device

Syntax

fclose(obj)

Description

fclose(obj)disconnectsobjfrom the device, whereobjis a serial port object or an array of serial port objects.

Examples

This example creates the serial port objectson a Windows®platform, connectssto the device, writes and reads text data, and then disconnectssfrom the device usingfclose.

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 needs,你应该从内存中删除deletefunction, and remove it from the workspace with theclearcommand.

Tips

Ifobjwas successfully disconnected, then theStatusproperty is configured toclosedand theRecordStatusproperty is configured tooff. You can reconnectobjto the device using thefopenfunction.

An error is returned if you issuefclosewhile data is being written asynchronously. In this case, you should abort the write operation with thestopasyncfunction, or wait for the write operation to complete.

Introduced before R2006a

Was this topic helpful?