0

If I open a serial port in thread 1 and then close it, I can open it in thread 2 and use it. In that way, I can allow multiple threads to communicate with the same port, as long as each thread closes the port and the next thread opens it.

But would it be possible to open a port in thread 1 and then communicate with it in thread 2, without closing it in thread 1 and without opening it in thread 2? Particularly for Windows?

Cerran
  • 2,087
  • 2
  • 21
  • 33
  • possible duplicate of [How can I allow thread 2 to communicate on the port I opened in thread 1?](http://stackoverflow.com/questions/21525516/how-can-i-allow-thread-2-to-communicate-on-the-port-i-opened-in-thread-1) – Paul R Feb 03 '14 at 13:23
  • @PaulR I created a more specific question to find out whether this possible, independent of any other constraints such as the code in the other question. This question does not ask *how* to do it. – Cerran Feb 03 '14 at 13:27
  • 2
    Yes, you can use serial port handle in any thread. Of course, you need to implement application-specific synchronization according to your needs. – Alex F Feb 03 '14 at 13:44
  • @AlexFarber Does your answer only apply to Windows? – Cerran Feb 03 '14 at 21:12
  • AFAIK, it should work also in Linux/Unix. There are no thread restriction on file handle. – Alex F Feb 04 '14 at 08:00

1 Answers1

0

Yes, it's possible to open a serial port once and let multiple threads communicate on it. Each thread needs to know the handle of the serial port, though.

Cerran
  • 2,087
  • 2
  • 21
  • 33