0

I'm looking for a way to detect when COM device is plugged into PC. I'm not limited to .NET but final application is written in .NET.

Best option would be to connect to some event, if exists. But in reality I can even list all devices in a loop.

Checking for new devices in a loop is acceptable as a delay of few seconds is not a real problem and application does it only one in a whole lifetime.

5
  • Do you want to detect COM port or USB port? Commented Sep 3, 2014 at 15:13
  • could you please explain the situation? what is being connected to the com port? are you looking to receive data from the port or send data out? Commented Sep 3, 2014 at 15:15
  • can you also not detect this using WMI I believe you can Commented Sep 3, 2014 at 15:16
  • something like: codeproject.com/Articles/14500/…?? Commented Sep 3, 2014 at 15:17
  • You can usually get the SerialPort.PinChanged event to fire, reporting a DsrChanged change. YMMV, handshaking isn't always consistently implemented. Commented Sep 3, 2014 at 17:52

1 Answer 1

1

I can read this question 2 different ways:

1. How to I detect when a USB->Serial adapter has been inserted.

In this case you could do SerialPort.GetPortNames in a loop and see when that changes

2. How do I detect when I'm connected to a device through my serial port.

There is no surefire way to be able to determine when something is connected to the com port without sending data. There are some additional pins that are meant to be used in this way, but it really depends on the cabling involved. See this post for more details on the types of cables, benefits, and drawbacks. If you can guarantee the pinout of the cable and that the device you're connecting sets DTR high, then this may be a viable approach.

If not, then you may have to poll each com port and send some data and see if you get any response.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I also think that checing port names is the only way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.