Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Windows Threading
Hey guys
 
Is it possible that two threads/processes do I/O through one RS232 port?
Does Microsoft Windows synchronize the RS232 port access with the threads?
 
In other words:
I do have a microcontroller which is connected to a PC using RS232.
The microcontroller sends every ASCII symbol back it receives.
 
On the PC, I have two threads running.
Thread/Process A sends ASCII "A" to the microcontroller and waits for a response.
Thread/Process B sends ASCII "B" to the microcontroller and waits for a response.
 
Can I assume that Thread A only receives "A"s back? In case Windows does not synchronize the port, there would be a possibility for Thread A to receive a "B".
 
Do you know of whether Windows synchronizes the RS232 access, so that two threads/processes can communicate "simultaneously" with e.g. a microcontroller without receiving each other's answers?
 
Thank you so much.
Posted 6-Jun-10 9:54am
Edited 6-Jun-10 10:55am
Moak11.4K
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Absolutely not.
The only ways to do this, are:
1) To open the port in a thread, send your data, receive the answer and release the port, so another can access it. You may want to provide some locking.
2) To create another third thread which handles all communications between the port and the two active threads. It decides where data is to go, and when.
 
I would personally lean toward the second option as it is cleaner and probably safer, but there is a reasonable amount of work involved.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Yes, this is very commonly done now. google for "virtual serial port". I believe there is at least one project on SourceForge to do this, maybe more.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,853
1 Sergey Alexandrovich Kryukov 7,107
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 6 Jun 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100