Serial Communication send / receive hex

17 Ansichten (letzte 30 Tage)
James Townley
James Townley am 11 Feb. 2015
Beantwortet: sai vallikat am 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..

Antworten (1)

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

Kategorien

Mehr zu Historical Contests finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by