Coming with USB Serial Port unexpected removal

Jul 14, 2011 at 3:42 AM

Hi there

I made a small change to the C# code to make it report to the main application that a USB Serial port has being removed unexpectedly.

In the worker thread CommEventThread there was already code to detect error 995.

(if e == 995) ....

I had to change this IF Statement so that instead of doing a "return" it now does a "throw new CommPortException(error_string)"
This lets the main program know that the worker thread has failed.

The main program can then handle it however it wants.
In my case my main program has a background loop that tries to re-open() the device every second, in case the user plugs it back in again!