1

I have some old code that was written in java for interfacing with a serial port that I'm attempting to convert to python. The following lines are found in a bash file that is run to setup the serial port dev device before the java code is executed in a daemon. Can anyone explain what these options mean as the man page for stty is impenetrable.

    stty -F /dev/ttyUSB0 1:0:9ad:0:3:1c:7f:15:4:5:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0 #9600 7E1
1

These are not documented options. This is the machine-readable serialized form of the device and line discipline state that is produced by stty -g. It is neither portable nor meaningful outwith passing it back in to the (same) stty program in this fashion.

You could decode the hexadecimal with your system's particular instance of the C language's termios.h header to hand.

Fortunately, you will find a comment on that line of shell script that indicates at least part of the author's intention:

#9600 7E1
Those are of course a line speed and the character framing of 7 bits, even parity, and 1 stop bit.

  • That would explain why I can't find any reference to it! Thanks for the insight. – Matt Phillips Oct 27 '17 at 16:11
1

It's not options, but data, probably generated by

stty -g

The manual page describes that as

   -g, --save
          Print all current settings in a form  that  can  be
          used  as  an  argument  to  another stty command to
          restore the current settings.

which comparing with the POSIX description provides no more insight:

Write to standard output all the current settings in an unspecified form that can be used as arguments to another invocation of the stty utility on the same system. The form used shall not contain any characters that would require quoting to avoid word expansion by the shell; see wordexp.

Various scripts use the feature (for example xterm's vttests scripts). Since it is an unspecified format, it is system-dependent (you can only rely on it being "something" written to the standard output).

If you used those settings to restore on a compatible system (i.e., one using the same implementation of stty), and did stty -a, it would show the settings in a more conventional format.

  • Luckily the device the code runs on is static, unluckily the reason for the port of the code is we are going to purchase new devices for it to run on. So I might have to use @JdeBP's answer to figure out what those settings in fact are :/ – Matt Phillips Oct 27 '17 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.