0

TLDR - I have onlcr configured in my terminal, but I don't see the \r getting added


If plug two FTDI serial converters together, and plug them both into my computer, I get two ports called /dev/ttyUSB0 and /dev/ttyUSB1

If I open them both with picocom in different terminals, I can make sure they are connected, properly, by sending messages back and forth, and if I quit using C-A C-Q it leaves the ports configured as follows:

$ stty -F /dev/ttyUSB0 -a
speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>;
swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V;
discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar 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 -flusho -extproc
$ stty -F /dev/ttyUSB1 -a
speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O;
min = 1; time = 0;
-parenb -parodd -cmspar 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 -flusho -extproc

Now if I open two terminals for listening to the two serial ports:

$ cat -v /dev/ttyUSB0
$ cat -v /dev/ttyUSB1

(actually I am only going to need one of them for this specific experiment, but it doesn't hurt to have both)

and then in a third terminal, send a single line like this:

$ echo this is a test > /dev/ttyUSB1

and then send one more line to prove that I am printing carriage returns:

$ echo -e 'this is another test\r' > /dev/ttyUSB1

then this is what I see:

$ cat -v /dev/ttyUSB0
this is a test
this is another test^M

Why don't I see ^M in line #1, and ^M^M in line #2?

icrnl is off on both devices, so it shouldn't be converting it back right?

Why is (or isn't) this happening?

1 Answer 1

1

Your stty shows -opost which switches off all output processing, so the onlcr has no effect.

2
  • How do you know which switch takes precedence over which switch? Is it laid out in the man page if I read it close enough? Or do you just know from experience? Or is there an order to options that makes it obvious after a while?
    – Alex028502
    Commented Apr 18, 2023 at 17:10
  • 1
    I think in this case it was a mix of "reading between the lines" and previous experience. Serial ports have been around so long that the control for them may be a bit non-optimal. You can also see man termios for the actual C calls that are behind the stty command.
    – meuh
    Commented Apr 18, 2023 at 19:47

You must log in to answer this question.

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