coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Questions related to stty(TOMITA)


From: Bob Proulx
Subject: Re: Questions related to stty(TOMITA)
Date: Sun, 24 May 2020 17:17:23 -0600

富田黎 wrote:
> I want to know the difference between stty command with "speed" and without 
> "speed".

With the "speed" command the stty program prints the speed.  Without
it there is no printing of the speed.

The Coreutils stty manual says:

  ‘speed’
     Print the terminal speed.

> When I change the baud rate of serial connected terminal (ttyS0), I
> don't know how the presence or absence of speed affects it as shown
> below.
> 
> $ stty -F /dev/ttyS0 [baudrate]

Sets the speed to "baudrate".

> $ stty -F /dev/ttyS0 speed [baudrate]

First prints the speed, due to the "speed" argument.  Then sets the
speed to "baudrate" due to the baudrate argument.

For example:

  rwp@angst:~$ stty speed
  38400

The terminal speed is 38400.

  rwp@angst:~$ stty speed 9600
  38400

The terminal speed wass 38400.  This was printed.  Then it was changed
to 9600.

  rwp@angst:~$ stty speed
  9600

The terminal speed is 9600.

  rwp@angst:~$ stty 38400 speed
  38400

  rwp@angst:~$ stty 9600 speed
  9600

  rwp@angst:~$ stty 4800 speed
  4800

In the above the speed is set to the value shown and then the printing
due to the "speed" argument occurs after it has been set.

> I know the official recommends the latter,

I am not aware of this recommendation.  Can you tell us the
documentation you are referring to?  The GNU Coreutils uses the in
program --help output, which generates the man page, and the full
manual is in the online info docs.

The full online info docs say exactly this:

  ‘speed’
     Print the terminal speed.

  ‘N’
     Set the input and output speeds to N.  N can be one of: 0 50 75 110
     134 134.5 150 200 300 600 1200 1800 2400 4800 9600 19200 38400
     ‘exta’ ‘extb’.  ‘exta’ is the same as 19200; ‘extb’ is the same as
     38400.  Many systems, including GNU/Linux, support higher speeds.
     The ‘stty’ command includes support for speeds of 57600, 115200,
     230400, 460800, 500000, 576000, 921600, 1000000, 1152000, 1500000,
     2000000, 2500000, 3000000, 3500000, or 4000000 where the system
     supports these.  0 hangs up the line if ‘-clocal’ is set.

Note that those are two separate program argument options.  Separate.
Independent.

> but even with the former you could change the baud rate in some
> cases and I'd like to know what the difference is.

Hopefully this helps to clarify the differences.

> For example, I was able to resolve the garbled ttyS0 with the
> former, but when I accessed ttyS0 with gpsd, I saw no change in
> baudrate.
> 
> Garbled characters
> $ cat /dev/ttyS0
> ->garbled text
> ->$ stty -F /dev/ttyS0 [baudrate]
> ->$ cat /dev/ttyS0
> ->Resolution of garbled characters

This shows the problem solved.  But there is a problem in the above
sequence.  Therefore I do not understand how it can be working.  Let
me repeat it so that I may comment upon each step.

  $ cat /dev/ttyS0
  ->garbled text

  $ stty -F /dev/ttyS0 [baudrate]

This changes the speed to baudrate.

  $ cat /dev/ttyS0
  Resolution of garbled characters

Good!

However if nothing has the /dev/ttyS0 open then the system will
immediately reset the speed back to the system default.  Therefore
simply doing the above will have no effect due to the lack of anything
holding the device open.

In order to have the stty change persist there must be a non-zero
reference count to the serial device.  It should work okay however if
there is something holding onto the device.

I will also take a moment to say that in the traditional usage stty
operates on the stdio file descriptor 0.

  $ stty 9600 < /dev/ttyS0

Both syntax formats should work the same however.  But traditionally
the redirection from stdin was used.

> About gpsd
> $ gpsmon /dev/ttyS0
> ->The default baudrate
> -> $ stty -F /dev/ttyS0 [baudrate]
> -> $ gpsmon /dev/ttyS0
> ->Keep the default baudrate.
> -> $ stty -F /dev/ttyS0 speed [baudrate]
> ->$ gpsmon /dev/ttyS0
> ->Confirm the changes to the baurate you set

Surely the 'gpsmon' command has the option to set the speed itself?
In the manual I see the options to do so.  Also it says that it will
search for the correct speed itself automatically.

Hope this helps to explain things. :-)

Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]