1

Note: I am looking for an explanation, not for a solution.

I am trying to build a serial device emulator for testing programs that talk to serial devices. I'm quite the novice in serial programming and the way ttys work, so excuse the mistakes.

After getting the file descriptors from pty.openpty I cannot write to master and read the message from the slave fd from the same process; the other way around works just fine. Opening the file from another process with pyserial also works fine. This does not stop my program from working, but I was wondering why this happens. I could not find an explanation from the few answers and man pages I found on the topic.

I found this answer that does make it work, but the flags and actions done by pyserial is over my head.

Python code:

import pty, os

master, slave = pty.openpty()
os.write(master, b"Halloo")
os.write(slave, b'Hello')
os.read(master, 5)
os.write(master, b"Halloo")
os.read(slave, 6)
Community
  • 1
  • 1
Dumitru
  • 771
  • 2
  • 12
  • 23

0 Answers0