One way to get around the fact that only one process can read from a specific serial (COM) port at a time, is by using virtual COM ports.
Faking an RS232 Serial Port
Described in the above post, the software lets you create virtual COM port pairs on windows. Virtual COM pairs work in a way that when you send data trough COM-A, it will be received on COM-B and vice versa.
In turn this allows you to do the following in your program:
- Listen for data on a real COM port (Process 1)
- Read from a real COM port (Process 1)
- Store what you read (Process 1)
- Send the stored data on trough a virtual COM port pair (Process 1)
- Listen for incoming data on virtual COM port pair (Process 2)
- Read, store and use the received data (Process 2)
This way you can use the data that came trough the real COM port in both processes, without running into the problem of one process blocking the other from reading the COM port. You can use the same steps in reverse to write data back to the real COM port from process 2. The only down side of this is that there will be a short delay for process 2 to receive or send the data.
I'm using this solution in a situation where I need to intercept and process data from a COM port, that another application is connected to. So I simply connected the application to a virtual COM port to which my process is forwarding the original data received from a real COM port.
Hope this helps.
NOTE: The above program works for Windows, not sure if there is a version for Linux, but maybe you can find something similar for Linux.