zam664
zam664

Reputation: 767

SerialPort Does Not Exist After Exception

I am using C#'s SerialPort class to communicate over a USB COM port. The SerialPort opens fine and works fine until an exception occurs. After the exception when I try to use the port through my application I get another exception: "The port 'COM6' does not exist." I keep on getting the exception after closing the application, restarting Visual Studio, etc. The only way to get the port back is to restart the computer.

Has anyone seen this problem and know a way around it? I need this to be more durable.

Upvotes: 2

Views: 1486

Answers (1)

Muditha sumanathunga
Muditha sumanathunga

Reputation: 601

Typically this kind of an issue occur due to your USB to serial driver is not properly written to handle exceptions.

Rather than rebooting the machine, try to unplug and plug it again ( after few seconds). By doing that previous instance may unload, and when plugging it, it will load the relevant driver again.

This will enumerate a com number ( in your case Com6) in the device manager.

There is a way that you can restart the USB connection using "devcon.exe" as given in following link.

http://digital.ni.com/public.nsf/allkb/1D120A90884C25AF862573A700602459

You can integrate it to console application and reconnect your USBTOSerial without restarting your machine

Upvotes: 0

Related Questions