Create serial port object
obj = serial('
port
')
obj = serial('port
','PropertyName
',PropertyValue,...)
obj = serial('
creates a serial port object associated with the serial port specified
by port
')port
. If port
does
not exist, or if it is in use, you will not be able to connect the
serial port object to the device.
Port
object name will depend upon
the platform that the serial port is on. The Instrument Control Toolbox™ function instrhwinfo
('serial')
provides a list of available serial ports. This list is an example
of serial constructors on different platforms:
Platform | Serial Port Constructor |
---|---|
Linux® 64 | serial('/dev/ttyS0'); |
Mac OS X 64 | serial('/dev/tty.KeySerial1'); |
Windows® 64 | serial('com1'); |
obj = serial('
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.port
','PropertyName
',PropertyValue,...)
This example creates the serial port object s1
associated
with the serial port COM1 on a Windows platform.
s1 = serial('COM1');
The Type
, Name
, and Port
properties
are automatically configured.
get(s1,{'Type','Name','Port'}) ans = 'serial' 'Serial-COM1' 'COM1'
To specify properties during object creation
s2 = serial('COM2','BaudRate',1200,'DataBits',7);