To set serial device speed (rs 232, /dev/ser1) I’m using
cfsetispeed(), cfsetospeed() and tcsetattr().
Calling cfgetospeed() or tcgetattr()
always returns the same value that I put into tcsetattr().
How to get real speed (baudrate) of serial device ?
I don’t understand the question.
I think he means that cfgetospeed() is not changing the baud rate.
When I was developing a serial driver, I came across a problem.
The serial device did not support split input/output baud rates.
So if someone set the input and output differently, what was the driver to do?
When using cfsetispeed() and cfsetospeed(), it is not possible to
change both baud rates at the same time.
So there are three options that I can think of.
- Don’t support cfsetispeed() and cfsetospeed(), return an error.
- When calling these routines, always change both input and output baud rates.
- Record the changes, but if both input and output are not both
changed to the same value, have the port malfunction, and I/O calls
return an error until the problem is fixed.
To a programmer who doesn’t know which choice I’ve made,
the first is annoying, the second is misleading, and
the third could be downright frustrating.
I think I ended up choosing 2) as the lessor
Having said all this, I wonder what QNX has done
with their driver. I’ve only changed the baud rate
with stty, and tcsetattr() so I don’t know, but maybe
they decided on 1)?
I can put into cfsetospeed() / tcsetattr() any* value baudrate
( *any value within allowable range of course ),
but the real serial speed (whatever: in or out)
strongly depends on hardware -
- serial driver frequency timing and clock divider;
…and my question applies to serial device real speed:
- How to get it ?
You cannot get the “real” speed, you can only get the driver best guess. The driver has no way to measure the real speed. It tries to set the hardware at what it things is the speed, but if the speed (baudrate) is different because of hardware, there is no way for the driver to know.
That being said you can write application to measure the real baud rate.
Real speed you may get only with read specification on this device(qurtz and available divisors)…