文档帮助中心文档
从串行设备读取数据
=阅读(serialdevObj numBytes)
=阅读(serialdevObj、numBytes、精密)
例子
出=阅读(serialdevObj,numBytes)返回从串行设备读取的数据的字节数。
出=阅读(serialdevObj,numBytes)
出
serialdevObj
numBytes
出=阅读(serialdevObj,numBytes,精度)还指定数据精度。
出=阅读(serialdevObj,numBytes,精度)
精度
全部折叠
创建一个arduino连接。
arduino
arduinoObj = arduino (“COM16”,“达芬奇”,“库”, {SPI的,“串行”,“I2C”});
在Arduino硬件上创建一个到串行设备的连接。
serialdevObj =设备(arduinoObj“串口”, 1“波特率”, 115200,“DataBits”8“StopBits”, 1“平价”,“甚至”)
serialdevObj = device with properties: Interface: 'Serial' SerialPort: 1 TxPin: 'D1' RxPin: 'D0' BaudRate: 115200 (bits/s) NumBytesAvailable: 0显示所有属性,功能
在环回连接Rx和Tx引脚。向串行设备写入3字节的数据。
写(serialdevObj (88 99 65));
检查数据是否可用来读取。
numBytes = serialdevObj。NumBytesAvailable
numBytes = 3
从串行设备读取数据。
读(serialdevObj, 3)
ans =1×388 99 65
创建一个arduino连接
在环回连接Rx和Tx引脚。向串行设备写入数据。
写(serialdevObj, 256,“uint16”);
numBytes = 2
从串行设备读取数据,精度为uint16。
读(serialdevObj 1“uint16”)
ans = 256
串行设备连接,指定为设备对象。
设备
要从串行设备中读取的数据字节数,指定为标量.
标量
请注意
Arduino的®Mega2560, Mega ADK, Leonardo和Micro板读工作仅为多达63字节的数据,Arduino库不读取数据到串行接收缓冲区的最后一个字节。看到这个链接为更多的细节。
读
“uint8”
“int8”
“uint16”
“int16”
“uint32”
“int32”
“uint64”
“int64”
数据精度,指定为以下字符向量之一:
从串行设备读取的数据,返回为标量或向量基于精度.
向量
使用读在MATLAB®函数块万博1manbetx®万博1manbetxArduino硬件支持包生成可以部署在Arduino硬件上的代码。
arduino|设备|写
写
您有这个示例的一个修改版本。要用编辑打开这个例子吗?
您点击了一个对应于这个MATLAB命令的链接:
通过在MATLAB命令窗口中输入该命令来运行该命令。Web浏览器不支持MATLAB命令。万博1manbetx
选择一个网站来获得可用的翻译内容,并看到当地的活动和提供。根据您所在的位置,我们建议您选择:.
你也可以从以下列表中选择一个网站:
请选择表现最佳的中国网站(中文或英文)。MathWorks的其他国家网站并没有针对您所在位置的访问进行优化。
与当地办事处联系