User`s manual

Disconnecting and Cleaning Up
8-69
Disconnecting and Cleaning Up
When you no longer need your serial port object, you should disconnect it from
the device, and clean up your MATLAB environment by removing the object
from memory and from the workspace. These are the steps you take to end a
serial port session.
Disconnecting a Serial Port Object
When you no longer need to communicate with the device, you should
disconnect it from the serial port object with the
fclose function.
fclose(s)
You can 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. You can
now connect another serial port object to it using
fopen.
Cleaning Up the MATLAB Environment
When you no longer need the serial port object, you should remove it from
memory with the
delete function.
delete(s)
Before using delete, you must 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, you should 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
If you use clear on a serial port object that is still connected to a device, the
object is removed from the workspace but remains connected to the device. You
can restore cleared objects to MATLAB with the
instrfind function.