Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Serial Port Devices

Read and write to devices connected to a serial port

Functions

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
instrcallback Event information when event occurs
instrfind Read serial port objects from memory to MATLAB workspace
instrfindall Find visible and hidden serial port objects
isvalid (serial) Determine whether serial port objects are valid
readasync Read data asynchronously from device
record Record data and event information to file
serial Create serial port object
serialbreak Send break to device connected to serial port
set (serial) Configure or display serial port object properties
stopasync Stop asynchronous read and write operations
clear (serial) Remove serial port object from MATLAB workspace
load (serial) Load serial port objects and variables into MATLAB workspace
save (serial) Save serial port objects and variables to file
disp (serial) Serial port object summary information
length (serial) Length of serial port object array
size (serial) Size of serial port object array

Properties

BaudRate Specify the rate at which bits are transmitted
BreakInterruptFcn Specify the callback function to execute when a break-interrupt event occurs
ByteOrder Specify the byte order of the device
BytesAvailable Number of bytes available in the input buffer
BytesAvailableFcn Specify the callback function to execute when a specified number of bytes is available in the input buffer, or a terminator is read
BytesAvailableFcnCount Specify the number of bytes that must be available in the input buffer to generate a bytes-available event
BytesAvailableFcnMode Specify 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
BytesToOutput Number of bytes currently in the output buffer
DataBits Number of data bits to transmit
DataTerminalReady State of the DTR pin
ErrorFcn Specify the callback function to execute when an error event occurs
FlowControl Data flow control method to use
InputBufferSize Size of the input buffer in bytes
Name Descriptive name for the serial port object
ObjectVisibility Control access to serial port object
OutputBufferSize Size of the output buffer in bytes
OutputEmptyFcn Specify the callback function to execute when the output buffer is empty
Parity Specify the type of parity checking
PinStatus State of the CD, CTS, DSR, and RI pins
PinStatusFcn Specify the callback function to execute when the CD, CTS, DSR, or RI pins change state
Port Specify the platform-specific serial port name
ReadAsyncMode Specify whether an asynchronous read operation is continuous or manual
RecordDetail Specify the amount of information saved to a record file
RecordMode Specify whether data and event information are saved to one record file or to multiple record files
RecordName Name of the record file
RecordStatus Indicate if data and event information are saved to a record file
RequestToSend State of the RTS pin
Status Indicate if the serial port object is connected to the device
StopBits Number of bits used to indicate the end of a byte
Tag Label to associate with a serial port object
Terminator Terminator character
Timeout Waiting time to complete a read or write operation
TimerFcn Specify the callback function to execute when a predefined period of time passes.
TimerPeriod Period of time between timer events
TransferStatus Indicate if an asynchronous read or write operation is in progress
Type Object type
UserData Data you want to associate with a serial port object
ValuesReceived Total number of values read from the device
ValuesSent Total number of values written to the device

Topics

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?