This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Serial Port Devices

Read and write to devices connected to a serial port


delete (serial)Remove serial port object from memory
fclose (serial)Disconnect serial port object from device
fgetl (serial)Read line of ASCII text from device and discard terminator
fgets (serial)Read line of text from device and include terminator
fopen (serial)Connect serial port object to device
fprintf (serial)Write text to device
fread (serial)Read binary data from device
fscanf (serial)Read ASCII data from device, and format as text
fwrite (serial)Write binary data to device
get (serial)Serial port object properties
isvalid (serial)Determine whether serial port objects are valid
readasyncRead data asynchronously from device
serialCreate serial port object
serialbreakSend break to device connected to serial port
seriallistList of serial ports connected to your system
set (serial)Configure or display serial port object properties
stopasyncStop asynchronous read and write operations
clear (serial)Remove serial port object from MATLAB workspace
disp (serial)Serial port object summary information
instrcallbackEvent information when event occurs
instrfindRead serial port objects from memory to MATLAB workspace
instrfindallFind visible and hidden serial port objects
load (serial)Load serial port objects and variables into MATLAB workspace
length (serial)Length of serial port object array
recordRecord data and event information to file
save (serial)Save serial port objects and variables to file
size (serial)Size of serial port object array


BaudRateSpecify the rate at which bits are transmitted
BreakInterruptFcnSpecify the callback function to execute when a break-interrupt event occurs
ByteOrderSpecify the byte order of the device
BytesAvailableNumber of bytes available in the input buffer
BytesAvailableFcnSpecify the callback function to execute when a specified number of bytes is available in the input buffer, or a terminator is read
BytesAvailableFcnCountSpecify the number of bytes that must be available in the input buffer to generate a bytes-available event
BytesAvailableFcnModeSpecify if the bytes-available event is generated after a specified number of bytes is available in the input buffer, or after a terminator is read
BytesToOutputNumber of bytes currently in the output buffer
DataBitsNumber of data bits to transmit
DataTerminalReadyState of the DTR pin
ErrorFcnSpecify the callback function to execute when an error event occurs
FlowControlData flow control method to use
InputBufferSizeSize of the input buffer in bytes
NameDescriptive name for the serial port object
ObjectVisibilityControl access to serial port object
OutputBufferSizeSize of the output buffer in bytes
OutputEmptyFcnSpecify the callback function to execute when the output buffer is empty
ParitySpecify the type of parity checking
PinStatusState of the CD, CTS, DSR, and RI pins
PinStatusFcnSpecify the callback function to execute when the CD, CTS, DSR, or RI pins change state
PortSpecify the platform-specific serial port name
ReadAsyncModeSpecify whether an asynchronous read operation is continuous or manual
RecordDetailSpecify the amount of information saved to a record file
RecordModeSpecify whether data and event information are saved to one record file or to multiple record files
RecordNameName of the record file
RecordStatusIndicate if data and event information are saved to a record file
RequestToSendState of the RTS pin
StatusIndicate if the serial port object is connected to the device
StopBitsNumber of bits used to indicate the end of a byte
TagLabel to associate with a serial port object
TerminatorTerminator character
TimeoutWaiting time to complete a read or write operation
TimerFcnSpecify the callback function to execute when a predefined period of time passes.
TimerPeriodPeriod of time between timer events
TransferStatusIndicate if an asynchronous read or write operation is in progress
TypeObject type
UserDataData you want to associate with a serial port object
ValuesReceivedTotal number of values read from the device
ValuesSentTotal number of values written to the device


Capabilities and Supported Interfaces and Platforms

Serial port capabilities, supported interfaces, and supported platforms.

Overview of the Serial Port

The serial port interface standard, signals and pin assignments, the serial data format, and finding serial port information for your platform.

Getting Started with Serial I/O

These examples help you get started with the serial port interface.

Create a Serial Port Object

Create a MATLAB® object that represents the serial I/O device. You can configure property values during object creation.

Connect to the Device

Establish a connection between MATLAB and the serial I/O device.

Configure Communication Settings

You can set values for baud rate, serial data format, parity checking, and other serial properties.

Write and Read Data

You can write data to the device and read data from the device. The data can be text or binary.

Events and Callbacks

You can enhance the power and flexibility of your serial port communication by using events. An event occurs after a condition is met and might result in one or more callbacks.

Control Pins

You can use control pins to signal the presence of connected devices and control the flow of data.

Debugging: Recording Information to Disk

Recording information to disk provides a permanent record of your serial port session, and is an easy way to debug your application. While the serial port object is connected to the device, you can record information, such as number of values, data, and event information, to a disk file.

Save and Load

You can save and load serial port objects.

Disconnect and Clean Up

After the serial communication is complete, you should disconnect the serial port object from the device and remove the object from memory and the workspace.

Property Reference

You can use serial port properties for reading and writing data, configuring the communication, performing callbacks, and other tasks. The properties are described here in detail.

Properties — Alphabetical List

You configure BaudRate as bits per second.

Was this topic helpful?