Serial Communication send / receive hex

6 次查看(过去 30 天)
Trying to use serial communication to receive measurements from this sensor
All documentation is included free on the website.
The sensor requires bytes of hex to be sent and then it will reply with more bytes of hex information that must be converted to 11 distance measurements. The sensor is connected to my laptop via an RS232 to USB convertor.
Here is the code that I have
--------------------------------------------------------------------------
s = serial('COM4', 'BaudRate', 115200, 'DataBits',8,'StopBits',1);
flushoutput(s);
flushinput(s);
fopen(s);
h = hexToBinaryVector(['0xde','0x01','0x05','0x59','0x83'],40);
h1 = mat2str(h);
fwrite(s, h1,'uint8');
pause(0.05)
a = fread(s); %will read bytes and create a vector
pause (2);
fclose(s);
-----------------------------------------------
I am of the understanding that MATLAB cannot send hex so this is why I have converted the data to binary.
When I open (a) which I thought would be the data I get a list of 225 numbers that range from 91 to 191.
Does anyone have any advice on how I can get it working properly?
Thanks..

回答(1 个)

sai vallikat
sai vallikat 2017-6-29
Hello,
Did you get the logic working ??

类别

Help CenterFile Exchange 中查找有关 Vehicle Network Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by