5

I have two python programs that need to read from the same serial port via pySerial API.

From what I understand, you can not have two programs reading from the same serial port. So what I plan on doing is have one python program read from a physical serial port, and then have it copy the EXACT data it received from the serial port to the virtual serial ports, where the other python programs can read it via pySerial API.

Of the two python progarms that will be using pySerial, only one of them will respond back with anything.

Any ideas how to do this?

user5062278
  • 51
  • 1
  • 2
  • Do they have to read the same data from the same serial port? – Iron Fist Jun 29 '15 at 17:44
  • yes, one is for processing data and one is for monitoring data. – user5062278 Jun 29 '15 at 17:46
  • Why don't you make it such that the script who reads from Physical Serial is the one to send the same data to the other script...like share data between the two scripts without making a Virtual Serial Port, was that clear? – Iron Fist Jun 29 '15 at 18:03

1 Answers1

2

Creating virtual serial port may be trivial or complicated depending on your requirements.

If you only need to propagate data from real port to virtual port (and vice versa), you can use tools like socat, remserial, or conserver. See usage examples here: 1, 2, 3.

Such tools create a pty (pseudo-tty) and transfer data between real port and pty in both directions. However, they do not propagate other APIs, includig various termios and ioctl() calls specific to serial port.

If it's not enough, you need more advanced tools like tty0tty or ser2net andsercd (based on RFC 2217) and others. See this post.

Community
  • 1
  • 1
gavv
  • 4,649
  • 1
  • 23
  • 40