How can I read hexidecimal data via rs485?
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
James Tursa
2020-11-17
Are you sure you are not simply getting integer values that you can interpret as hexidecimal numbers?
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!