读
从串行设备读取数据
描述
返回从串行设备读取的数据字节数。出
=阅读(serialdevObj
,numBytes
)
还指定数据精度。出
=阅读(serialdevObj
,numBytes
,精度
)
例子
从Arduino硬件上的串行设备读取数据
创建一个arduino
连接。
arduinoObj = arduino(“COM16”,“达芬奇”,“库”, {SPI的,“串行”,“I2C”});
在Arduino硬件上创建到串行设备的连接。
serialdevObj = device(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字节的数据。
write(serialdevObj,[88 99 65]);
检查是否有数据可读。
numBytes = serialdevObj。NumBytesAvailable
numBytes = 3
从串行设备读取数据。
读(serialdevObj, 3)
ans =1×388 99 65
在Arduino硬件上指定从串行设备读取数据的精度
创建一个arduino
连接
arduinoObj = arduino(“COM16”,“达芬奇”,“库”, {SPI的,“串行”,“I2C”});
在Arduino硬件上创建到串行设备的连接。
serialdevObj = device(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引脚。向串行设备写入数据。
写(serialdevObj, 256,“uint16”);
检查是否有数据可读。
numBytes = serialdevObj。NumBytesAvailable
numBytes = 2
从串行设备读取数据,精度为uint16。
读(serialdevObj 1“uint16”)
Ans = 256
输入参数
serialdevObj
- - - - - -串行设备连接
设备对象
串行设备连接,指定为设备
对象。
numBytes
- - - - - -要读取的字节数
标量
从串行设备读取的数据字节数,指定为标量
.
请注意
对于Arduino®Mega2560, Mega ADK, Leonardo和Micro板读
由于Arduino库不将数据读入串行接收缓冲区的最后一个字节,因此仅适用于最多63字节的数据。看到这个链接欲知详情。
精度
- - - - - -数据精度
“uint8”
(默认)|“int8”
|“uint16”
|“int16”
|“uint32”
|“int32”
|“uint64”
|“int64”
数据精度,指定为以下字符向量之一:
“uint8”
“int8”
“uint16”
“int16”
“uint32”
“int32”
“uint64”
“int64”
更多关于
使用代码生成MATLAB功能块
使用
读
在MATLAB中®函数块。金宝app®金宝appArduino硬件支持包生成可以部署在Arduino硬件上的代码。
版本历史
R2019b引入
Abrir比如
Tiene una versión modificada de este ejemplo。¿Desea abrir este ejemplo con sus modificaciones?
MATLAB突击队
Ha hecho clic en unenlace que对应一个este commando de MATLAB:
弹射突击队introduciéndolo en la ventana de commandos de MATLAB。Los navegadores web no permission comandos de MATLAB。
您也可以从以下列表中选择一个网站:
如何获得最佳的网站性能
选择中国站点(中文或英文)以获得最佳站点性能。其他MathWorks国家站点没有针对您所在位置的访问进行优化。