Reputation: 4620
I have a .NET application that listens on a COM port. The other side of the connection is a UDOO board running lubuntu.
After the udoo board is rebooted, the COM port temporarily goes missing and then re-appears on the device manager. However, when I call the "Open" function of the SerialPort object, I get an exception which says "The port COM4 does not exist". The full exception stack trace is as follows.
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
Even when this exception is thrown, device manager shows the very same COM port as visible as in the following screenshot.
And yes I did refresh the device list. Unplugging and plugging the cable back to the computer solves this problem but, it isn't elegant.
Are there any thoughts on how I could work around this problem ?
Upvotes: 0
Views: 1519
Reputation: 1084
As soon as your application detects that COM port is missing you should Close() connection to it. Than you will not have problems with opening it back when it is again available in the system.
I had similar problem with ELMO driver. We were using 2 logical pipes on USB connection serial (COM) and HID. COM was opened in one process and HID in second. After HW reset and re-initialization of USB, COM and HID ports were listed back in device manager but we could not open it any more. Usually only PC reset helps. We spend some time trying to figure out where the problem was and we find out that HID process did not close connection when USB was not available any more. After introducing this simple fix all starts to work without problems.
Upvotes: 0
Reputation: 167
Try Disable serial port from and then reenable. Also check whether problem with hardware. You can check it by inserting usb device in serial port. If works proper. Use debugger to check code.
Upvotes: 1