I am using the latest version 4.3 (R3) in a raptor board. I connected a USB printer to the raptor board. 4.2 used to have a USBHostController.DeviceDisconnectedEvent. But it is missing UsbSerialDisconnected event in GHI.Usb.Host.Controller in 4.3. The printer works but when I power it off or unplug the USB port I got an exception in Visual Studio. I cannot catch this exception:
Exception System.Exception - 0xffffffff (7)
Message:
GHI.Usb.Host.UsbSerial::NativeRead [IP: 0000]
GHI.Usb.Host.UsbSerial::CheckEvents [IP: 0017]
An unhandled exception of type ‘System.Exception’ occurred in GHI.Usb.dll
This is part of my code:
// Subscribe to USBH event.
Controller.UsbSerialConnected += Controller_UsbSerialConnected;
I don’t get serialUSB.Disconnected event when I power off the printer or unplug the USB port . If I don’t run it in Visual Studio, just start the raptor board normally. When I unplug the USB port from the raptor board, the raptor board would reboot. It would be nice if I can get a disconnected event instead of an exception which I cannot catch so that the raptor board won’t reboot itself. Any help would be appreciated.
@ iamin - I was able to reproduce it, but it didn’t interrupt normal flow of the program. There’s a race condition between the internal workers that raise the events and the disconnect event. The workers fail because there is no device connected but the disconnect event has not yet arrived. The R4 SDK catches those exceptions internally, but you’re still notified of them like other caught exceptions in VS.
That said, the behavior is not ideal and it is something on our list to improve.
I am not sure, but I think when I have tried disconnecting it multiple times rapidly it cause my mainboard to hang. I could test this later.
I would prefer it to be consistent - if I don’t get any exceptions when, for example, mouse is disconnected, I would like to get no exceptions when serial device is disconnected, if possible.