Clear Filters
Clear Filters

Serial Communication send / receive hex

6 views (last 30 days)
James Townley
James Townley on 11 Feb 2015
Answered: sai vallikat on 29 Jun 2017
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..

Answers (1)

sai vallikat
sai vallikat on 29 Jun 2017
Hello,
Did you get the logic working ??

Community Treasure Hunt

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

Start Hunting!