串行和 USB 通信
串行通信是在两个或更多设备之间进行最常见的低级别协议通信。通常,一个设备是一台计算机,另一个设备可以是调制解调器、打印机、Arduino® 硬件、另一台计算机或科学仪器,如示波器或函数生成器。对于许多串行端口应用,您无需深入了解串行端口的工作原理,即可实现与仪器的通信。只需在 MATLAB® 工作区中创建一个 serialport
对象,即可通过串行端口建立通信。有关创建 serialport
对象的信息,请参阅Create Serial Port Object。
serialport
对象和设备必须具有相同的通信设置,才能写入或读取数据。有关信息,请参阅 配置串行端口通信设置。
函数
App
主题
- 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.
- 配置串行端口通信设置
设置与设备波特率和串行数据格式相关联的属性。
- 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.
- Get Started with Hardware Manager
Get the apps and add-ons to access your hardware from MATLAB.
- Transition Your Code to serialport Interface
Connect to serial port devices using
serialport
instead 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.