How can I read hexidecimal data via rs485?
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I need to read force/torque data from a sensor that uses rs-485 to communicate. So far I've been able to get pretty close but the readings are inconsistent or just nonexistent.
Right now my code looks like this:
------------------------------------------------
% Establish serial connection
FT = serial('COM18','BaudRate',115200);
fopen(FT);
FT.terminator = 'CR/LF';
fprintf(FT,'r'); % serial command that reads instantaneous force/torque data
fgets(FT); % prints force/torque readings in hexidecimal format
fclose(FT);
delete(FT);
-------------------------------------------------
The output for fgets() should look like this:
ans =
200000000FFFFFFFFFFFF0000 % The first digit is a counter. Each 4 characters after that are 4 digit hex readings for %Fx,Fy,Fz,Tx,Ty,Tz which I will convert later.
But right now I'm getting 1 of 3 things when I run it. These will be received in no particular order when running the code multiple times in a row.
- ans = ' '
- ans = ' Command not found ' % This is the error the sensor returns when an unknown command is sent.
- ans = ' 000100010005FFFF00000000 ' % This is close to what I should be getting except for the first 2 characters not showing up.
Is this because I'm using rs-485? I read online that using serialport() will support rs-485 but reading/writing data is limited to certain data types, none of which are hexidecimal.
2 Kommentare
James Tursa
am 17 Nov. 2020
Are you sure you are not simply getting integer values that you can interpret as hexidecimal numbers?
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!