Search code examples
gnu-screenstty

GNU Screen terminal line settings


I want to use GNU screen to monitor to a serial USB port like this:

$ screen /dev/ttyUSB0 115200

But I need to tweak a few terminal line settings. I have made several attempts but none seem to work. For example, to send NL+CR for a newline character, not just NL, the terminal line setting is onlcr.

Attempt 1 - without any special settings:

$ screen /dev/ttyUSB0 115200
# only sends NL

Attempt 2 - via screen:

$ screen /dev/ttyUSB0 115200,onlcr
# still only sends NL

Attempt 3 - via ssty:

$ stty -F /dev/ttyUSB0 onlcr
$ screen /dev/ttyUSB0 115200
# still only sends NL

Attempt 4 - via both:

$ stty -F /dev/ttyUSB0 onlcr
$ screen /dev/ttyUSB0 115200,onlcr
# still only sends NL

Attempt 5 - in the other order:

$ screen /dev/ttyUSB0 115200,onlcr
# then ctrl+a, ctrl+z to pause the screen session
$ stty -F /dev/ttyUSB0 onlcr
stty: /dev/ttyUSB0: Device or resource busy

In all cases, if I run stty to check the terminal line settings I get this:

Before running screen - note the -onlcr is present:

$ stty -F /dev/ttyUSB0 
speed 115200 baud; line = 0;
kill = ^H; min = 100; time = 2;
-icrnl -imaxbel
-opost -onlcr
-isig -icanon -echo

Changing the stty setting - note the -onlcr has gone:

$ stty -F /dev/ttyUSB0 onlcr
$ stty -F /dev/ttyUSB0 
speed 115200 baud; line = 0;
kill = ^H; min = 100; time = 2;
-icrnl -imaxbel
-opost 
-isig -icanon -echo

After running screen - note the -onlcr is back again:

$ stty -F /dev/ttyUSB0 
speed 115200 baud; line = 0;
kill = ^H; min = 100; time = 2;
-icrnl -imaxbel
-opost -onlcr
-isig -icanon -echo

It's as if screen ignores any stty settings and resets them to it's own defaults. And this the same on both machines I tested it on; Debain 8.7 and macOS Sierra 10.12.4

I have seen posts with other people facing similar problems but none give a definitive answer. Many people end up recommending an alternative to screen like minicom but now I'm interested.

Can stty settings, like onlcr, be used with screen?


Solution

  • I just went through much the same process, only to find out the screen clobbers the stty settings no matter what. One comment here suggests changing the screen source code: How to toggle CR/LF in gnu screen?

    In the end, I was very happy to find a more minimal dumb-terminal program that allows passing stty-style arguments on the command line: https://github.com/npat-efault/picocom

    It also pretty-prints the serial port settings when it starts so you can easily check them.

    Packages exist in Debian-derived distros (sudo apt-get install picocom), and for others it seems that compilation is straightforward. One dependency is the linenoise library, which can be disabled.