Send a hex block of data Serial port from matlab
44 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a problem, I have a serial device which should addressed using a block of data in specific format. The data I am trying to send is [7E 00 12 10 00 00 13 A2 00 40 8B 63 85 08 59 00 00 00 00 00 1A 0C], all in hexadecimal. How to send it in a single go? The command is correct since I am able to send the same via a serial terminal program and the device responds.
I can do the same using a arduino by the following command: Serial.write(array,sizeof(array));
How to do the same kind in matlab?
Kindly please help.
Thanks in advance, Mike
0 个评论
采纳的回答
Walter Roberson
2013-10-7
fwrite(fid, array)
3 个评论
Walter Roberson
2013-10-8
You do NOT want to transmit hex. You want to transmit 8 bit binary. The hex you see is from the monitoring program displaying the binary that way.
fwrite(s, h)
Have you set the serial port Terminator property to no terminator, and the BytesAvailableFcnMode to 'byte' ? And possibly the InputBufferSize as well?
更多回答(2 个)
Jan
2013-10-7
"All in hexadecimal" is not clear. You cannot store values in hexadecimal format like e.g.:
a = [7E 00 12 10 00 00 13 A2 00 40 8B 63 85 08 59 00 00 00 00 00 1A 0C]; % ERROR!
You would need e.g. a string (char vector):
a = ['7E', '00', '12', ...
But to send this, you would convert it to UINT8 values at first, most likely. So please explain this detail.
2 个评论
Jan
2013-10-8
"It does not work" is not useful to explain the occurring problems. Please tell us, what happens.
Michael Mathew
2013-10-8
3 个评论
Kritika Vashishtha
2020-5-8
Hey Michael, Can you post the answer. The link that you shared no more exists.
Ferran Gonzalez
2022-11-8
Hi @Yonathan @Kritika Vashishtha, you can read an archived version of the link here: https://web.archive.org/web/20151224041528/https://in.mathworks.com/matlabcentral/newsreader/view_thread/79757
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 National Instruments Frame Grabbers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!