Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

串行和 USB 通信

对连接到串行端口的设备进行读取和写入

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

serialport 对象和设备必须具有相同的通信设置,才能写入或读取数据。有关信息,请参阅 配置串行端口通信设置

函数

全部展开

serialportlist连接到您的系统的串行端口列表
serialport连接到串行端口
configureTerminator为与串行端口的 ASCII 字符串通信设置终止符
configureCallback为与串行端口设备的通信设置回调函数和触发条件
read从串行端口读取数据
readline从串行端口读取 ASCII 字符串数据行
write将数据写入串行端口
writeline将 ASCII 数据行写入串行端口
flush清空串行端口设备缓冲区
getpinstatus获取串行引脚状态
setRTS设置串行 RTS 引脚
setDTR设置串行 DTR 引脚

App

串行通信管理器Communicate with devices connected to serial port
硬件管理器Discover and get started with your hardware

主题

疑难解答

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.