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일

0 개 추천

Hello,
Did you get the logic working ??

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2015년 2월 11일

답변:

2017년 6월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by