Can matlab be used to decode and interpret ANSI characters including non-printable characters?
15 views (last 30 days)
Show older comments
I am trying to decode and interpret an ANSI character response from a GPS receiver. Within ANSI, there are regular characters(found on a keyboard) and non-printable control characters(represented as certain spaces within the response line). The non printable characters are represented in Hexadecimal from 00-31 that represent command features from the receiver and can not be typed. How can I use MATLAB to interpret this data and convert it to binary, hexadecimal, or etc? Ultimately I would like to create a script that can read lines ANSI of characters and translate them to either hexadecimal or binary formats.
An example of the response I receive is:
MACM Øi «ıT##AkûOù£©É9ȵˇ¿tz «#AlèwπZ@Å˙ ª á°" ±·"Aki[j?sÄäÀBˇ,ÈK A“$Ai∂1⁄,Z8xü¯ôˇÄ?ò ∏‡
After receiving this response, I copied and pasted it into a ANSI convertor software called Hex-Editor. A conversion for the above response to hexadecimal using the software would be:
4D 41 43 4D 20 06 14 AF 69 20 C7 F5 54 23 13 02 05 23 41 6B 9E 4F 9D A3 A9 0C 83 39 E9 B5 FF C0 74 7A 20 20 C7 06 06 02 05 23 41 6C 8F 77 0F B9 5A 40 81 FA 20 BB 20 87 A1 22 20 03 B1 E1 04 02 05 22 41 6B 69 5B 6A 3F 73 80 8A 0F CB 42 FF 2C E9 4B 20 20 41 D2 15 02 05 24 41 69 B6 31 DA 2C 5A 38 78 9F F8 99 FF 80 3F 98 20 06 B8 19 10 E0 20
Any numbers from 00 to 31 that are above are represented as control characters and can not be typed. An online link of ANSI printable and non printable characters converted to hexadecimal and other formats can be found here:
0 Comments
Answers (1)
Walter Roberson
on 27 Oct 2015
fread() for binary data, fgetl() or fgets() for line-oriented data even if it includes non-printable characters. dec2hex() or sprintf() with '%x' or '%X' format for hex output
2 Comments
Walter Roberson
on 29 Oct 2015
fid = fopen('YourFile.txt', 'r');
tline = fgetl(fid);
A = dec2hex(tline);
B = sprintf('%2x', tline);
See Also
Categories
Find more on Automated Driving Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!