主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

串行端口接口

使用串行端口接口进行通信

串行通信是两个或多个设备之间通信的最常见的低级协议。通常,一个设备是计算机,而另一个设备可以是调制解调器、打印机、Arduino® 硬件、另一台计算机或科学仪器(例如示波器或函数发生器)。对于许多串行端口应用程序,您无需详细了解串行端口的工作原理即可与仪器进行通信。通过串行端口进行的通信是使用您在 MATLAB® 工作区中创建的 serialport 对象建立的。有关创建 serialport 对象的信息,请参阅 Create Serial Port Object

在写入或读取数据之前,serialport 对象和仪器必须具有相同的通信设置。有关信息,请参阅 Configure Serial Port Communication Settings

函数

全部展开

serialportlistList of serial ports connected to your system
serialportConnection to serial port
configureTerminatorSet terminator for ASCII string communication with serial port
configureCallbackSet callback function and trigger condition for communication with serial port device
serialportfindFind serial port connections (自 R2024a 起)
readRead data from serial port
readlineRead line of ASCII string data from serial port
readbinblockRead one binblock of data from serial port
writeWrite data to serial port
writelineWrite line of ASCII data to serial port
writebinblockWrite one binblock of data to serial port
writereadWrite command to serial port and read response
serialbreakSend break to device connected to serial port
flushClear serial port device buffers
getpinstatusGet serial pin status
setRTSSet serial RTS pin
setDTRSet serial DTR pin

App

串行通信管理器Communicate with devices connected to serial port (自 R2021b 起)

模块

Serial ConfigurationConfigure parameters for serial port
Serial Receive Receive binary data over serial port
Serial SendSend binary data over serial port

主题

疑难解答

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.

精选示例