J
JDS
I have an application that interfaces with a USB device using the .Net
serial port. The code works fine, displaying live data on the screen;
that is until the USB lead is pulled out from the PC when the program
hangs.
The obvious answer is not to pull the lead out, but unfortunately the
application is one in which there is a high possibility the lead will
be pulled out so the code needs to be more robust.
The form has a timer (System.Windows.Forms.Timer) that sends a request
to the device for data. The returning data is handled by the
DataReceived event of the serial port and uses a delegate to process
the data, ultimately displaying it on the form.
The timer code first checks to ensure the port exists (Not IsNothing)
and that it is open (IsOpen) before sending the request data command.
I am struggling to see what I can do to prevent the application from
hanging when the lead is disconnected (and the port is open).
Any help greatly appreciated.
Jeremy.
serial port. The code works fine, displaying live data on the screen;
that is until the USB lead is pulled out from the PC when the program
hangs.
The obvious answer is not to pull the lead out, but unfortunately the
application is one in which there is a high possibility the lead will
be pulled out so the code needs to be more robust.
The form has a timer (System.Windows.Forms.Timer) that sends a request
to the device for data. The returning data is handled by the
DataReceived event of the serial port and uses a delegate to process
the data, ultimately displaying it on the form.
The timer code first checks to ensure the port exists (Not IsNothing)
and that it is open (IsOpen) before sending the request data command.
I am struggling to see what I can do to prevent the application from
hanging when the lead is disconnected (and the port is open).
Any help greatly appreciated.
Jeremy.