Exception when reading from USB-to-Serial converter

The device is a FEZ Panda II with a FEZ Connect on top.
The Panda II is modified to enable USB host.

To the USB Host is a USB-to-Serial converter connected and the USBH_DeviceType.Serial_Prolific2 driver is used to communicate.

Communicating is without any problems, but once in a while the following exception occurs (from within 5 minutes to several hours). Where should I start to find the cause?


    #### Exception System.Exception - 0xffffffff (6) ####
    #### Message: 
    #### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read_Helper [IP: 0000] ####
    #### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read [IP: 001a] ####
    #### MyProject.Serial::Read [IP: 000a] ####
    #### MyProject.Serial::SerialWorker [IP: 0028] ####

In the past we used some Domino boards to do the same and never experienced such errors.

There is no difference beside what you modified.

The exception itself, is there any chance of finding out what happens exactly, why does it except?
What does the Read_Helper do, and what can cause it to except?

Bad data on USB bus. I think there is get last error for USB Host but that wouldn’t help you much.

You said it could be bad data on the bus. I was suspecting the device was disconnected, cause disconnecting the USB-to-Serial throws the same exception. But when the error occurs, the Disconnected event has not fired, so it’s still connected.

I took your advise and added some extra lines of code in a try catch around the read statement.
Hoping to see some more, and expecting the next read it would read again without an exception.

A read wrapper is used to sync on the first byte of a message.


        private int Read(byte[] buffer, int offset, int count)
        {
            int bytesRead = 0;
            try
            {
                // Sync on first byte. 
                bytesRead = _serialUsb.Read(buffer, offset, 1);
                if (bytesRead == 1 && count > 1)
                {
                    bytesRead = _serialUsb.Read(buffer, offset + 1, count -1);
                    bytesRead++;
                }
            }
            catch (Exception ex) 
            {
                Logger.WriteLine("Read exception", _loggerCategory);
                Logger.WriteLine(ex.Message, _loggerCategory);
                USBH_ERROR err = USBHostController.GetLastError();
                Logger.WriteLine(err.ToString(), _loggerCategory);
            }
            return bytesRead;
        }

Output is


2012-03-29 15:52:44.5176287 Serial   Rx 58 bytes
    #### Exception System.Exception - 0xffffffff (6) ####
    #### Message: 
    #### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read_Helper [IP: 0000] ####
    #### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read [IP: 001a] ####
    #### MyProject.Serial::Read [IP: 000c] ####
    #### MyProject.Serial::SerialWorker [IP: 0028] ####
2012-03-29 15:56:07.6139867 Serial   Read exception
2012-03-29 15:56:07.6306617 Serial   Exception was thrown: System.Exception
2012-03-29 15:56:07.6712757 Serial   268435461
    #### Exception System.Exception - 0xffffffff (6) ####
    #### Message: 
    #### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read_Helper [IP: 0000] ####
    #### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read [IP: 001a] ####
    #### MyProject.Serial::Read [IP: 000c] ####
    #### MyProject.Serial::SerialWorker [IP: 0028] ####
2012-03-29 15:56:07.7757725 Serial   Read exception
2012-03-29 15:56:07.7924602 Serial   Exception was thrown: System.Exception
2012-03-29 15:56:07.8139479 Serial   268435461

  • Is the number of some use to determine what is the cause?
  • Is there a way to clear the error on the USB bus and to continue, although some data over the bus may be lost?

You should be able ot continue using the device after the exception. In worst case, you can reset the devices and reuse it.

The Panda is no problem to use. Reading from the USB device will continue to give exceptions after it ran into the first.

When I disconnect the USB cable from the Panda, the error number changes to 4. Afterwards the Read gives an exception, what is locigal cause there is no device attached anymore. Sometimes the Panda II restarts completely after the USB cable is removed.

Connecting the USB device again will reestablish a connection and data is received again. Although the synchronising is not working anymore, what indicates data is coming in very slowly?


2012-03-30 08:58:16.6265481 Serial   Rx 58 bytes
2012-03-30 08:58:24.0965479 Serial   Rx 58 bytes
    #### Exception System.Exception - 0xffffffff (6) ####
    #### Message: 
    #### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read_Helper [IP: 0000] ####
    #### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read [IP: 001a] ####
    #### MyProject.Serial::Read [IP: 000c] ####
    #### MyProject.Serial::SerialWorker [IP: 0028] ####
2012-03-30 08:58:31.9790656 Serial   Read exception
2012-03-30 08:58:31.9957764 Serial   Exception was thrown: System.Exception
2012-03-30 08:58:32.0506872 Serial   268435461
    #### Exception System.Exception - 0xffffffff (6) ####
    #### Message: 
    #### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read_Helper [IP: 0000] ####
    #### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read [IP: 001a] ####
    #### MyProject.Serial::Read [IP: 000c] ####
    #### MyProject.Serial::SerialWorker [IP: 0028] ####
.....
2012-03-30 09:03:44.6789352 Serial   Read exception
2012-03-30 09:03:44.6956022 Serial   Exception was thrown: System.Exception
2012-03-30 09:03:44.7361696 Serial   268435461
    #### Exception System.Exception - 0xffffffff (6) ####
    #### Message: 
    #### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read_Helper [IP: 0000] ####
    #### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read [IP: 001a] ####
    #### MyProject.Serial::Read [IP: 000c] ####
    #### MyProject.Serial::SerialWorker [IP: 0028] ####
.....
2012-03-30 09:03:44.8155236 Serial   USB disconnected
.....
2012-03-30 09:03:45.0470788 Serial   Read exception
2012-03-30 09:03:45.0637454 Serial   Exception was thrown: System.Exception
2012-03-30 09:03:45.0883764 Serial   4
    #### Exception System.Exception - 0xffffffff (6) ####
    #### Message: [0xD][0xA]    #### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read_Helper [IP: 0000] ####
    #### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read [IP: 001a] ####
    #### MyProject.Serial::Read [IP: 000c] ####
    #### MyProject.Serial::SerialWorker [IP: 0028] ####
.....
2012-03-30 09:03:58.1355642 Serial   Read exception
2012-03-30 09:03:58.1522796 Serial   Exception was thrown: System.Exception
2012-03-30 09:03:58.1928894 Serial   4
    #### Exception System.Exception - 0xffffffff (6) ####
    #### Message: 
    #### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read_Helper [IP: 0000] ####
    #### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read [IP: 001a] ####
    #### MyProject.Serial::Read [IP: 000c] ####
    #### MyProject.Serial::SerialWorker [IP: 0028] ####
.....
2012-03-30 09:03:58.4757493 Serial   USB connected
.....
2012-03-30 09:04:07.5145479 Serial   Rx 57 bytes
2012-03-30 09:04:07.5355726 Serial   Rx 1 bytes
2012-03-30 09:04:16.8425479 Serial   Rx 66 bytes
2012-03-30 09:04:16.9025592 Serial   Rx 50 bytes
2012-03-30 09:04:26.2395456 Serial   Rx 7 bytes
2012-03-30 09:04:26.2805509 Serial   Rx 109 bytes
2012-03-30 09:04:28.7935549 Serial   Rx 58 bytes
2012-03-30 09:04:36.3405456 Serial   Rx 8 bytes
2012-03-30 09:04:36.4035591 Serial   Rx 50 bytes

How can the USB device be reset?