|MATLAB Function Reference|
Create a serial port object
||The serial port name.
||A serial port property name.
||A property value supported by
||The serial port object.
obj = serial('port')
creates a serial port object associated with the serial port specified by
port does not exist, or if it is in use, you will not be able to connect the serial port object to the device.
obj = serial('port',' creates a serial port object with the specified property names and property values. If an invalid property name or property value is specified, an error is returned and the serial port object is not created.
When you create a serial port object, these property values are automatically configured:
Typeproperty is given by
Nameproperty is given by concatenating
Serialwith the port specified in the
Portproperty is given by the port specified in the
You can specify the property names and property values using any format supported by the
set function. For example, you can use property name/property value cell array pairs. Additionally, you can specify property names without regard to case, and you can make use of property name completion. For example, the following commands are all valid.
Refer to Configuring Property Values for a list of serial port object properties that you can use with
Before you can communicate with the device, it must be connected to
obj with the
fopen function. A connected serial port object has a
Status property value of
open. An error is returned if you attempt a read or write operation while the object is not connected to the device. You can connect only one serial port object to a given serial port.
This example creates the serial port object
s1 associated with the serial port COM1.
Port properties are automatically configured.
To specify properties during object creation