Click here to Skip to main content
15,886,840 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
hi all,

i am working on a application which gets data from a serial port . so far so good when a single port used for a single application . but i am in a situation that a single serial port connected to com port in pc must be used in multiple application.so that how to share this single COM Port for multiple application.can anyone guide me in this situation. my programming language is c...

thanks in advance
Posted

As far as I know, on Windows platform (assuming you are using Windows) the serial port HANDLE must be obtained in exclusive mode. That means just 1 application can old a serial port at time. In order to share such a resource you would have to build an application that actually uses the serial port and let it handle the communication requests of the other applications (a sort of 'serial port server').
 
Share this answer
 
Comments
pasztorpisti 19-Aug-13 6:14am    
+5 this is the same solution that came to my mind. Depending on the goals of OP a software multiplexer/demultiplexer implementation will be needed in order to provide software channels for separate applications.
CPallini 19-Aug-13 7:14am    
Thank you.
[no name] 19-Aug-13 6:52am    
Textbook client/server model
you cant share one com-port, so have have an architectual problem.

Somehow your apps need to know that the com-data is now from them. They can check that and than read or close the port and the nect app is to work.

Or you write a com-port reader app which reads all data and is sorting out to whom it belong. It can write it in a file, where it can be read from other apps.

Cant you extend the hardware, so you have more com-ports?
 
Share this answer
 
Serial ports can not be shared by multiple applications. Once a port is opened by one application, it is locked and trying to open it with another application fails.

The solution is to use a serial port splitter software. Such software opens a physical serial port and provides multiple virtual ports to be used by multiple applications. Google for 'serial port splitter' to find some products.
 
Share this answer
 
Comments
Philippe Mori 19-Aug-13 18:45pm    
For read only access, you can also do an hardware splitter. That can be useful for tracing or logging data in real time. In practice for such usage, it might be better to simply buy hardware/software designed for that purpose as it will already have basic tracing functionnality builtin as indicated in this answer.
Hope this is still relevant...

Just have a look at com2com, tcp2com and hub4usb. They are all on SourceForge, just start from http://com0com.sourceforge.net/[^].
It is a Null-modem emulator, COM port to TCP redirector, and HUB for communications.
Using hub4com you can redirect incoming messages from your COM ports to multiple virtual COM ports quit easily. This way you can have the best of all three solutions mentioned.

Happy coding ;-)
 
Share this answer
 
Comments
SoMad 15-Jun-14 3:03am    
You are a little late, but this sounds like a great solution, so I will give that my 5.
I see the project has a GPL license - what a shame.

Soren Madsen

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900