Documentation Center

  • Trial Software
  • Product Updates

Contents

Disconnecting and Cleaning Up

Disconnecting a Serial Port Object

When you no longer need to communicate with the device, disconnect it from the serial port object with the fclose function.

fclose(s)

Examine the Status property to verify that the serial port object and the device are disconnected.

s.Status
ans =
closed

After fclose is issued, the serial port associated with s is available. Now connect another serial port object to it using fopen.

Cleaning Up the MATLAB Environment

When the serial port object is no longer needed, remove it from memory with the delete function.

delete(s)

Before using delete, disconnect the serial port object from the device with the fclose function.

A deleted serial port object is invalid, which means that you cannot connect it to the device. In this case, remove the object from the MATLAB® workspace. To remove serial port objects and other variables from the MATLAB workspace, use the clear command.

clear s

Use clear on a serial port object that is still connected to a device to remove the object from the workspace but leave it connected to the device. Restore cleared objects to MATLAB with the instrfind function.

Was this topic helpful?