Using the Linux screen command as terminal emulator to serial console

I want to read the output of NuttX’s hexdump to see if a binary file was generated correctly. Unfortunately using “minicom” to select and read text it not an option.

Then I decided to use Linux “screen” command to see the serial console of my board running NuttX.

First install screen:

$ sudo apt-get install screen

Now you need to execute the “script” command to copy everything from your Linux console:

$ script
Script started, file is typescript

Then just run screen:

$ screen /dev/ttyUSB0 115200

In the NuttX prompt execute the hexdump command:

nsh> ls -l
/mnt:
 -rw-rw-rw-      13 TESTE.TXT
 -rw-rw-rw-   36160 TRKLOG.DB
 -rw-rw-rw-     640 HEADER.TXT
nsh> hexdump /mnt/TRKLOG.DB
...
01f0: 58 5e 3d c2 ec 96 82 94 ff a0 9c 8c b1 5a 04 6c X^=..........Z.l
/mnt/TRKLOG.DB at 00008c00:
0000: 13 82 ee 1e 8c 80 47 56 00 00 00 00 00 00 00 00 ......GV........
0010: 00 00 00 00 00 00 00 00 00 00 00 00 e0 2e 74 0e ..............t.
...

To exit from “screen” press the sequence: Ctrl + a + k
It will show>

Really kill this window [y/n] y
[screen is terminating]

Now leave the “script” command:

$ exit
exit
Script done, file is typescript

If you open typescript you will see the complete dump:

$ vi typescript

Script started on Sat 14 Nov 2015 05:23:08 PM BRST
$ screen /dev/ttyUSB0 115200^M
^[[r^[[m^[[2J^[[H^[[?7h^[[?1;4;6l^[[?1049h^[[4l^[[?1h^[=^[[0m^[(B^[[1;27r^[[H^[[2J^[[H^[[2J
nsh> ^[[Kls -l^M
/mnt:^M
 -rw-rw-rw-      13 TESTE.TXT^M
 -rw-rw-rw-   36160 TRKLOG.DB^M
 -rw-rw-rw-     640 HEADER.TXT^M
nsh> ^[[Khexdump TRKLOG.DB^M
nsh: hexdump: open failed: 2^M
nsh> ^[[Khexdump TRKLOG.DB^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[Khexdump TRKLOG.DB^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[Khexdump TRKLOG.DB^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[Khexdump TRKLOG.DB^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K/mnt/TRKLOG.DB^M
/mnt/TRKLOG.DB at 00000000:^M
0000: 13 82 ee 1e 33 06 93 b9 00 00 00 00 00 00 00 00 ....3...........^M
0010: 00 00 00 00 00 00 00 00 00 00 00 00 e0 2e 74 0e ..............t.^M
0020: cc 79 7e 45 25 9a 7b cb 2b 6e aa 00 00 00 00 aa .y~E%.{.+n......^M
0030: 58 5e 3d c2 ec 96 82 94 ff a0 9c 8c b1 5a 04 6c X^=..........Z.l^M

Nice, but we need to remove the header (use the editor to remove o header) and these lines starting with /mnt/TRKLOG.DB :

$ sed -i '/^\/mnt/d' typescript

Good, now we need to remove the first 6 characters at beginning of each line:

$ sed -i 's/^.\{,6\}//' typescript

Also the last 17 characters at end of line:

$ sed -i 's/.\{,17\}$//' typescript

Finally we have only the useful information:

13 82 ee 1e 8f 80 47 56 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 e0 2e 74 0e 
cc 79 7e 45 25 9a 7b cb 2b 6e aa 00 00 00 00 aa 
58 5e 3d c2 ec 96 82 94 ff a0 9c 8c b1 5a 04 6c 
13 82 ee 1e 90 80 47 56 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 e0 2e 74 0e 
cc 79 7e 45 25 9a 7b cb 2b 6e aa 00 00 00 00 aa 
58 5e 3d c2 ec 96 82 94 ff a0 9c 8c b1 5a 04 6c

One thought on “Using the Linux screen command as terminal emulator to serial console

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s