Hi,
We have some issues with the USBH_SerialUSB CDC driver which I hope you can help us with.
In one case we have integrated an external IO board (KTA-223 USB/RS485 Relay IO Board , http://www.sparkfun.com/products/9526) and we are polling for information 2 times pr. second.
Very often we get an Exception during read:
Exception was thrown: System.Exception
GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read_Helper
GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Read
What is this exception really? Is this a timeout ? Is this some low level IO error ? What should we do when we get this error? How can we get more details about what REALLY is the problem ?What Exceptions exists (ioerror, timeout, ++?)
What we have done is that after a number (>3) of such errors (without any successfull read or write in between) we delete the SerialUSB object , and re-create it. This is something that very often doesnt work. So to get the CDC communication to work we need to execute USBHostController.Reset().
I am not happy with this code, so I am hoping you can help me with some feedback on what the correct way should be to re-initalize the USB device after a failure.
And if you know about common problems with USB CDC please let me know.
bold]Write code:[/b]
len_sent = _io.Write(data, 0, len_data);
Read code:
count = _io.Read(buffer, 0, 1); // read 1 character
Reset USB code:
foreach (USBH_Device device in USBHostController.GetDevices())
{
if ((device.TYPE >= USBH_DeviceType.Serial_FTDI) && (device.TYPE <= USBH_DeviceType.Serial_Sierra_C885))
{
this.Detach(device);
}
}
Logger.Warn("Resetting USBHostController!");
USBHostController.Reset(); // Reset the controller
Thread.Sleep(1000);
USB event handler code:
void USBHostController_DeviceDisconnectedEvent(USBH_Device device)
{
if ((device.TYPE >= USBH_DeviceType.Serial_FTDI) && (device.TYPE <= USBH_DeviceType.Serial_Sierra_C885))
{
this.Detach(device);
}
}
void USBHostController_DeviceConnectedEvent(USBH_Device device)
{
if ((device.TYPE >= USBH_DeviceType.Serial_FTDI) && (device.TYPE <= USBH_DeviceType.Serial_Sierra_C885))
{
this.Attach(device);
}
}
Attach code:
private void Attach(USBH_Device device)
{
try
{
_io = new USBH_SerialUSB(device, 9600, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.None);
_io.ReadTimeout = 100;
Logger.Debug("Attached IOController on USBDevice, device type =" + device.TYPE.ToString() + ", VendorID = " + device.VENDOR_ID.ToString());
}
catch (Exception ex)
{
Logger.Error("Failed to attach SerialUsbIOController!", ex);
}
}