Click here to Skip to main content
15,884,010 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have a requirement to know the COM port out of available system com ports to which a particular device (say Humidity USB transmitter) is connected.
How to connect only to that COM port whenever the device is connected ? Please any body help me with programming solutions or related links .
Posted
Comments
Sergey Alexandrovich Kryukov 2-Jul-15 1:54am    
Not clear. COM or USB?
—SA
Ralf Meier 2-Jul-15 3:24am    
Additional to the question of Sergey :
If you search for an USB-Device which provides you a COM-Port then it is very much easier because you could contact the Driver and get (or perhaps not if not availible) the required Information ...
[no name] 2-Jul-15 3:36am    
Is it a proper USB device or a serial device going through a USB adaptor?

1 solution

There is no a programmatic way to detect if some device is connected until you actually try to communicate with the device. The device may specify a special detection protocol or not. If not (believe me, the developers of most such devices are so-oo sloppy, in addition to limited capabilities of such hardware), detection may become problematic.

Here is why: let's assume that the protocol assumes some response to some of your initial commands sent to port. Your communication thread (always try to use a separate thread for any kinds of communications) tries to read the response and hangs for certain time. But how do you know why? The device may need some more time, or no device is connected. But how much time to wait? You don't know exactly. Efficient detection is, in general, not very feasible.

That said, most things depends on the device you have on the device on the other end of your RS-232 cable. I hope I gave you some ideas. Consult the documentation and/or ask customer service your question, experiment a bit with the device, try to learn how it behaves. Generally, you may have to detect the presence of the device by some timeout. This is not nice, but what would you expect from such outdated hardware?

—SA
 
Share this answer
 

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