I am trying to figure out how to use the termios calls to configure the tty. Below I am playing with baudrate. I am able to call tcgetattr, change the values, see that they have changed in a print before I send them. However tcsetattr followed by tcgetattr shows that the hardware is not getting them.
I tried changing to su in case it was a permissions thing but that made no difference. I see that it is possible for the termios structure to be locked and unlocked by writing a special termios structure. How do I test it to see if it is locked, and if so, how do I unlock it?
import os
import termios
def TestTTY(tty):
fd = os.open(tty,os.O_RDWR | os.O_NONBLOCK)
if fd:
if os.isatty(fd):
tios = termios.tcgetattr(fd)
print("From tcgetattr")
print(tios)
#try to set the baud to B38400
tios[2] &= ~termios.CBAUD
tios[2] |= termios.B38400
print("To tcsetattr")
print(tios)
termios.tcsetattr(fd,termios.TCSANOW,tios)
print("Readback tcgetattr")
print(termios.tcgetattr(fd))
os.close(fd)
TestTTY("/dev/ttyS0")
From tcgetattr [0, 0, 6321, 0, 4097, 4097, [b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', 0, 0, b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00']]
To tcsetattr [0, 0, 2239, 0, 4097, 4097, [b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', 0, 0, b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00']]
Readback tcgetattr [0, 0, 6321, 0, 4097, 4097, [b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', 0, 0, b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00']]