串行端口接口
串行通信是两个或多个设备之间通信的最常见的低级协议。通常,一个设备是计算机,而另一个设备可以是调制解调器、打印机、Arduino® 硬件、另一台计算机或科学仪器(例如示波器或函数发生器)。对于许多串行端口应用程序,您无需详细了解串行端口的工作原理即可与仪器进行通信。通过串行端口进行的通信是使用您在 MATLAB® 工作区中创建的 serialport 对象建立的。有关创建 serialport 对象的信息,请参阅 Create Serial Port Object。
在写入或读取数据之前,serialport 对象和仪器必须具有相同的通信设置。有关信息,请参阅 Configure Serial Port Communication Settings。
函数
App
| 串行通信管理器 | Communicate with devices connected to serial port (自 R2021b 起) |
模块
| Serial Configuration | Configure parameters for serial port |
| Serial Receive | Receive binary data over serial port |
| Serial Send | Send binary data over serial port |
主题
- Serial Port Overview
Basic features of serial port communication.
- Create Serial Port Object
Establish a connection between MATLAB and the device using the serial port.
- Configure Serial Port Communication Settings
Set properties associated with the device baud rate and serial data format.
- Write and Read Serial Port Data
Write and read both text and binary data with a serial port device.
- Use Callbacks for Serial Port Communication
Enhance instrument communication by executing a callback function when a specified event occurs on the device.
- Use Serial Port Control Pins
Signal the presence of connected devices and control the flow of data using control pins.
- Transition Your Code to serialport Interface
Connect to serial port devices using
serialportinstead ofserial.
疑难解答
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.



