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

Serial communication is the most common low-level protocol for communicating between two or more devices. Typically, one device is a computer, while the other device can be a modem, a printer, another computer, or a scientific instrument such as an oscilloscope or a function generator. For many serial port applications, you can communicate with your instrument without detailed knowledge of how the serial port works. Communication is established through a serial port object, serial, which you create in the MATLAB workspace. For information about creating the serial object, see Create a Serial Port Object.

Before you can write or read data, both the serial port object and the instrument must have identical communication settings. For information, see Configure Communication Settings.


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


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.