10

I typically use screen(1) to open a serial port with the command:

sudo screen /dev/ttyUSB2 115200

I've tried setting parenb (and a number of other things) using the following command:

sudo screen /dev/ttyUSB2 115200,cs8,parenb,-parodd,-cstopb

However, the system doesn't seem to respect this. Here are the settings as reported by stty while I'm in screen with the above command:

$ sudo stty -F /dev/ttyUSB2 -a
speed 115200 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^H; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S;
susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 100; time = 2;
-parenb -parodd cs8 -hupcl -cstopb cread clocal -crtscts
-ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

Note the -parenb despite the fact that I enabled it at the command line.

If I make the change manually to ttyUSB2 it isn't respected after (nor while) running screen.

Set parenb:

$ sudo stty -F /dev/ttyUSB2 parenb

Check its value:

$ sudo stty -F /dev/ttyUSB2 -a
speed 115200 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^H; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S;
susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 100; time = 2;
parenb -parodd cs8 -hupcl -cstopb cread clocal -crtscts
-ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

You can see parenb is set properly.

Run screen:

$ sudo screen /dev/ttyUSB2 115200,cs8,parenb,-parodd,-cstopb

Check parenb again:

$ sudo stty -F /dev/ttyUSB2 -a
speed 115200 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^H; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S;
susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 100; time = 2;
-parenb -parodd cs8 -hupcl -cstopb cread clocal -crtscts
-ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

Oops, it's back to being -parenb.

What's going on?

How would I modify this command to use even parity (specifically 8e1 instead of the default 8n1)?

OS is Ubuntu 12.04.5 LTS with the latest HWE.

2
  • Try creating another shell in the same window, while the original shell is still running, to run stty: exec ! stty parenb -parodd. This is derived from an example (for baud rate) in the man page.
    – sawdust
    Sep 12, 2014 at 20:12
  • see Screen command set baud rate for terminal transmission - nixCraft for some syntax help, but no clue where it comes from: screen /dev/ttySX baud_rate,cs8|cs7,ixon|-ixon,ixoff|-ixoff,istrip|-istrip.
    – Stefan
    Mar 20, 2023 at 17:53

2 Answers 2

4

Long story short, it looks as if screen doesn't support setting those flags. The alternative would be to run stty to set the flags while screen is connected to the port, as you've done. Alternately, you could run kermit or another terminal emulator program inside a conventional screen command-line session, instead of having screen connect directly to the serial port.

The screen source code is at http://git.savannah.gnu.org/cgit/screen.git. It looks like the file of interest is tty.sh. This is shell script which runs during the build process to produce "tty.c". tty.c contains the code for accessing serial ports.

The function SttyMode() appears to be what parses the tty options and sets the tty mode. It appears to me that it handles a small, fixed set of options. "parenb" and "parodd" aren't among them.

It looks like it'd be straightforward for a developer experienced with C to add support for these options, if that's an option for you.

9

Try sudo screen /dev/ttyUSB2 115200,cs8,parenb,-parodd,-cstopb

From the man page for stty:

  • csN - set character size to N bits, N in [5..8]
  • [-]parenb - generate parity bit in output and expect parity bit in input
  • [-]parodd - set odd parity (even with '-')
  • [-]cstopb - use two stop bits per character (one with '-')
1
  • Unfortunately this didn't work. I updated my question with many more details.
    – Tom Hennen
    Sep 12, 2014 at 19:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .