Click here to Skip to main content
15,889,200 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I've got two buzzers hooked up to one serial port on different pins. I've got a program which can spawn two instances. I want each instance to drive one buzzer each. The problem I'm facing is that the second instance cannot get a handle to the comport (COM1) using CreateFile method, as this returns access denied error.

I cannot find an authoritative source for this, but I've come across a few people saying that COM port handle cannot be shared in Google searching. Now I'm trying to somehow duplicate the COM port handle in the second instance and use it.

Is it possible at all and how would you do it? I'm looking for the simplest solution to achieve the desired results. Sorry for not having example codes; I'm absolutely lost in how to attack this problem.
Posted

1 solution

Quote:
I cannot find an authoritative source for this, but I've come across a few people saying that COM port handle cannot be shared
As far as I know that's true on Windows. As a workaround you could code a server application that takes care of serial communication with several clients sending requests to it (using the IPC technique you prefer). Server could then serialize the requests in order to send meaningful data to the serial port.
 
Share this answer
 
Comments
[no name] 5-Aug-15 19:15pm    
Thanks for a quick answer. Is it not possible to duplicate the handle using duplicatehandle method and have both processes use it?
CPallini 6-Aug-15 2:34am    
I don't know. Anyway I suppose it wouldn't be practical, because you have to serialize access anyway.
[no name] 6-Aug-15 3:36am    
Do I need to serialize access? One process only sets and clears DTR and the other sets and clears RTS.
CPallini 6-Aug-15 3:43am    
If it is that way, then no, you don't actually need.

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