locked
Detecting removal of virtual COM port (USB-COM port) RRS feed

  • Question

  • Hi everybody,

    I'm wondering if there is a way to detect the removal of a virtual COM port.

    The thing is, when using CreateFile, you get an invalid handle if the COM port doesn't exit. That's fine, but what, if you program opens the COM port, because at this time it is connected to the USB port. The program sends and receives data, and suddenly the user removes the virtual COM port from the USB socket. I was hoping to get any error or exception, but nothing happens. However, when I reconnect the USB COM port, the connection between handle and device is not automatically rebuild.

    Thus leeds be to the question: How do I know when to close and reopen the COM port connection in such a situation?

    How can I detect, that the virtual COM port was removed?

    Many thanks in advance

    Wednesday, December 9, 2009 8:56 PM

Answers

  • There is nothing send from the driver, if the virtual COM port driver simulate a real COM port to 100%. Back in the old days COM ports are stationary on the motherboard and you can not unplug it from the motherboard.

    The particular driver may implement its own proprietary APIs to notify if the underline device of the COM port is removed. Ask the developer of the particular driver for more information.


    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    • Marked as answer by Wesley Yao Tuesday, December 15, 2009 4:17 AM
    Wednesday, December 9, 2009 9:52 PM
  • If it is a USB device, then you should be able to monitor the device stack to see if it appears or disappears.
    In any case, your best bet would be to ask on the groups on www.osronline.com
    Many device driver experts hang out there, and they should be able to give you a good answer.
    • Marked as answer by Wesley Yao Tuesday, December 15, 2009 4:17 AM
    Friday, December 11, 2009 1:03 PM

All replies

  • There is nothing send from the driver, if the virtual COM port driver simulate a real COM port to 100%. Back in the old days COM ports are stationary on the motherboard and you can not unplug it from the motherboard.

    The particular driver may implement its own proprietary APIs to notify if the underline device of the COM port is removed. Ask the developer of the particular driver for more information.


    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    • Marked as answer by Wesley Yao Tuesday, December 15, 2009 4:17 AM
    Wednesday, December 9, 2009 9:52 PM
  • If it is a USB device, then you should be able to monitor the device stack to see if it appears or disappears.
    In any case, your best bet would be to ask on the groups on www.osronline.com
    Many device driver experts hang out there, and they should be able to give you a good answer.
    • Marked as answer by Wesley Yao Tuesday, December 15, 2009 4:17 AM
    Friday, December 11, 2009 1:03 PM
  • Hi,

    In another forum to use the enumeration methods of the COM port to find out, if the used COM port is still listed. I assume, that this is the way you are suggesting, too.

    I think I will give it a try next week.

    Thank you
    Friday, December 11, 2009 3:54 PM