Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 通过串行总线发送数据阵列_Matlab_Serial Port - Fatal编程技术网

Matlab 通过串行总线发送数据阵列

Matlab 通过串行总线发送数据阵列,matlab,serial-port,Matlab,Serial Port,我有一个名为COM1的串行端口,我想将一些数据同步写入该端口,但当使用多行数据时,会出现错误: test1 = randi([0,255],1,32); test2 = randi([0,255],2,32); fwrite(COM1, test1, 'int8', 'sync'); %successful fwrite(COM1, test2, 'int8', 'sync'); %unsuccessful 我在test2中遇到的错误只是说写入不成功:写入过程中发生错误。是否可以以这种方式将数

我有一个名为
COM1
的串行端口,我想将一些数据同步写入该端口,但当使用多行数据时,会出现错误:

test1 = randi([0,255],1,32);
test2 = randi([0,255],2,32);
fwrite(COM1, test1, 'int8', 'sync'); %successful
fwrite(COM1, test2, 'int8', 'sync'); %unsuccessful
我在
test2
中遇到的错误只是说
写入不成功:写入过程中发生错误。
是否可以以这种方式将数据作为数组发送?如果是这样,我怀疑问题在于行是如何终止的。如何确保阵列的终端与串行端口匹配?我知道
set(COM1,'Terminator',X)
,但不知道
X
应该是什么来匹配MATLAB数组


使用MATLAB版本9.3.0.713579(R2017b)。

这只是
fwrite/serial
的数据格式要求。数据
A
应该是向量,而不是数组。你应该试试

fwrite(COM1, test2(:), 'int8', 'sync');
但请确保列的主要顺序是您需要的。否则,你就可以了

test2 = test2.'; % will send in row order
fwrite(COM1, test2(:), 'int8', 'sync');

这只是
fwrite/serial
的数据格式要求。数据
A
应该是向量,而不是数组。你应该试试

fwrite(COM1, test2(:), 'int8', 'sync');
但请确保列的主要顺序是您需要的。否则,你就可以了

test2 = test2.'; % will send in row order
fwrite(COM1, test2(:), 'int8', 'sync');

接收端是什么?当它接收一个数组和一个向量时,它的行为是否应该有所不同?您是否可以以某种方式对数组进行编码(例如gzip或甚至
mat2str(…)
)并在另一端对其进行解码?接收端是什么?当它接收一个数组和一个向量时,它的行为是否应该有所不同?您是否可以以某种方式对数组进行编码(例如gzip或甚至
mat2str(…)
)并在另一端对其进行解码?