User avatar
Posts: 285
Joined: Fri Mar 04, 2016 10:15 am

Seeking for the best way to interface with another app over serial.

Sun Mar 24, 2019 9:33 pm

I am currently seeking for the best way to interface with another app over serial.

The other app is a blackbox that expects to get every second an incoming byte from a parametrable "serial connection" (e.g. /dev/ttyS0)
At the beginning we get an initial short handshake with a control byte sent from the app which must be responded by a given byte before the (slow) data stream starts.

The pty — Pseudo-terminal utilities looked promising to create a symbolic serial device that could act as a real one.

But it turned out to be tougher than it appeared. The code...

Code: Select all

master,slave = pty.openpty() #open the pseudoterminal
s_name = os.ttyname(slave) #translate the slave fd to a filename

print ("Pseudo serial name is: ")
print (s_name)
ser = Serial(s_name, 9600, timeout=1)
...reveals that the Pseudo-terminal utilities do create a quasi random device which name is /dev/pty/[n], whereas n is variable.
I could not find a way to configure a fixed device name.
Morever the device is always created with restricted rights, so I could not even read the stream with Minicom.

Apparently the library does not allow to change that.

These two unwanted behaviours act for me as a showstopper.
Has someone got either a clue on how to manage predictable and open devices with the pty library, or know another library to get the job done in Python3?

Thank you for your advices...

Return to “Python”