Main Content

Serial and USB Communication

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. Normally, one device is a computer, while the other device can be a modem, a printer, Arduino® hardware, 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 through a serial port is established with a serialport object, which you create in the MATLAB® workspace. For information about creating a serialport object, see Create Serial Port Object.

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

Funktionen

alle erweitern

serialportlistList of serial ports connected to your system (Seit R2019b)
serialportfindFind serial port connections (Seit R2024a)
serialportConnection to serial port (Seit R2019b)
configureTerminatorSet terminator for ASCII string communication with serial port (Seit R2019b)
configureCallbackSet callback function and trigger condition for communication with serial port device (Seit R2019b)
readRead data from serial port (Seit R2019b)
readlineRead line of ASCII string data from serial port (Seit R2019b)
writeWrite data to serial port (Seit R2019b)
writelineWrite line of ASCII data to serial port (Seit R2019b)
serialbreakSend break to device connected to serial port
flushClear serial port device buffers (Seit R2019b)
getpinstatusGet serial pin status (Seit R2019b)
setRTSSet serial RTS pin (Seit R2019b)
setDTRSet serial DTR pin (Seit R2019b)

Apps

Serial ExplorerCommunicate with devices connected to serial port (Seit R2021b)
Hardware ManagerDiscover and get started with your hardware (Seit R2022a)

Themen

Fehlersuche

Troubleshooting Serial Port Interface

Troubleshoot the Serial Port interface.

Resolve Serial Port Connection Errors

Troubleshoot connecting to a serial port device.

Serialport Warning - Unable to Read All Data

Try these remedies when you receive some data, and you get the warning message: 'serialport' unable to read all requested data.

Serialport Warning - Unable to Read Any Data

Try these remedies when you receive no data, and you get the warning message: 'serialport' unable to read any data.