locked
IOException when exiting "Main" after USB device (recognized as device on COM port) is unplugged RRS feed

  • Question

  • Using VS 2005 /  .NET 2.0 SP2

    An IOException of "The device does not recognize the command" is generated when my application exits after a USB device is unplugged. Using a USB device driver which presents the device as a COM port when it is connected. My application uses System.IO.Ports.SerialPort to communicate with the device. 

    When the device is plugged into the USB port, it registers as connected to the COMx correctly. I start my application which enumerates through all of the COM ports looking for my device. The application correctly locates the device and starts communicating with it. This is all done using SerialPort methods (i.e. Open, ReadLine, ...)

    If I disconnect the device from the USB port while my application is running, of course the virtual COMx port is now gone (device manager shows the COM port is gone) . My program senses that the device connected to the COM port is no longer responding (it has been polling it for information), it closes the COM port and displays a MessageBox to relate the condition and exits the application when the user presses OK.

    Here is the odd part, the IOException occurs after leaving Main(). What am I missing in regards to this being a USB device (which is a serial device connected to a COM port from the perspective of the application) which is pulled from the PC while the application is running? Is there a SerialPort event I should be monitoring so that no further communication be sent to the SerialPort object?     

    [

    STAThread]

     

    static void Main()

    {

     

       Application.Run(new MainForm());

    }  <-- The IOException occurs here after leaving Main()

     

    • Moved by SamAgain Monday, September 27, 2010 1:58 AM not BCL question (From:.NET Base Class Library)
    Wednesday, September 22, 2010 7:34 PM

Answers

  • Hello,

     

    Thank you for your post!  I would suggest creating a new thread for your question in the ASP forums located here:  http://forums.asp.net


    Have a great day!

    Thanks!


    SachinW Tier 2 Application Support Server and Tools Online Operations Team
    Wednesday, October 6, 2010 11:08 AM

All replies

  • Hello,

     

    Thank you for your post!  I would suggest creating a new thread for your question in the ASP forums located here:  http://forums.asp.net


    Have a great day!

    Thanks!


    SachinW Tier 2 Application Support Server and Tools Online Operations Team
    Wednesday, October 6, 2010 11:08 AM
  • Were you able to resolve this error?

    I'm receiving the same error so any help would come in handy!

    Thx

    Thursday, July 7, 2011 8:46 AM