C# SerialPort.GetPortNames() behavior
        Posted  
        
            by Gunner
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Gunner
        
        
        
        Published on 2010-05-02T20:30:20Z
        Indexed on 
            2010/05/03
            10:58 UTC
        
        
        Read the original article
        Hit count: 523
        
In my C# 2008 application, I use the SerialPort.GetPortNames() function to retrieve the list of currently available ports. What I have noticed is, when ever I plug in a USB device, it's port number i s shown in the list on my Application and when I unplug it and refresh the list, the port number is no longer there.
One phase of the application involves reading/writing data from/to the device continuously. Now, my expectation is, If I unplug the device during the operation and get the current Port list using SerialPort.GetPortNames(), the Port Name will not be there and I can use that to make the decision that the device has been unplugged.
To my surprise, the Port name is still found despite having it removed
Why is the program behaving like this? The port name isn't listed when in no-communication mode. Does it have something to do with the device being removed when it's communicating?
© Stack Overflow or respective owner