Main Content

本页对应的英文页面已更新,但尚未翻译。 若要查看最新内容,请点击此处访问英文页面。

串行端口设备

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

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

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

函数

全部展开

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

主题

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 serialport instead of serial.

疑难解答

Troubleshooting Serial Port Interface

Try these tips if you have problems using the toolbox with the Serial Port interface. Includes information about Serial Port supported platforms, adaptor requirements, configuration and connection, and other interface-specific tips.

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.

特色示例