USB CDC Serial Exception

We are developing a solution that communicates to USB CDC devices over their emulated serial port via the USB host controller. We already have one device working and can read / write bytes to it no problem. We are attempting to add an ezLCD-313 screen which is also a CDC device that uses serial communications. I can create the device fine, open the port, and write to it. However the device seems un-responsive to the commands, and as soon as I write to the port my reading thread starts throwing an exception every time it attempts to read.

#### Exception System.Exception - 0xffffffff (4) ####
#### Message: 
#### GHI.Premium.USBHost.USBH_SerialUSB::Read_Helper [IP: 0000] ####
#### GHI.Premium.USBHost.USBH_SerialUSB::Read [IP: 001a] ####
#### Test.Program::SerialUSBThread [IP: 001f] ####

A first chance exception of type ‘System.Exception’ occurred in GHI.Premium.USBHost.dll

Calling USBHostController.GetLastError(), gives me this error code:

Description: 268435460

Which is, CompletionCode_Stall - Transfer error. USB device refused the transfer. Check sent USB packet.

I know Im sending the correct packet, because Ive sent the same bytes on a terminal emulator on Windows. Im just wondering how common it is for devices to support hardware serial port emulation. It works fine under windows using the default Windows CDC device driver. Could it be that the USB stack on the screen only works with a software driver? Im starting to think we may have just gotten lucky with our first USB device working right off the bat. The screen is using a PIC24 microcontroller, if that helps at all.

I should mention I’ve tried this on a Spider and a Cobra 2

Here’s the little bit of test code which works fine on our other device.



using System.Threading;
using GHI.Premium.System;
using GHI.Premium.USBHost;
using Microsoft.SPOT;
using System;
using System.Text;

namespace Test
{
  internal class Program
  {
    private static USBH_SerialUSB serialUSB;
    private static Thread serialUSBThread; 

    public static void Main()
    {
      // Subscribe to USBH event.
      USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;

      // Sleep forever
      Thread.Sleep(Timeout.Infinite);
    }

    private static void DeviceConnectedEvent(USBH_Device device)
    {
      Debug.Print("Device connected");

      switch (device.TYPE)
      {
        case USBH_DeviceType.Serial_CDC:
          device = new USBH_Device(device.ID, device.INTERFACE_INDEX, USBH_DeviceType.Serial_CDC, device.VENDOR_ID, device.PRODUCT_ID, device.PORT_NUMBER);
          serialUSB = new USBH_SerialUSB(device, 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
          serialUSB.Open();
          serialUSBThread = new Thread(SerialUSBThread);
          Thread.Sleep(100);
          serialUSBThread.Start();
          byte[] command = Encoding.UTF8.GetBytes("CLS WHITE\r");
          serialUSB.Write(command, 0, command.Length);
          break;
      }
    }

    private static void SerialUSBThread()
    {
      byte[] data = new byte[1000];
      while (true)
      {
        Thread.Sleep(10);
        try
        {
          int bytesRead = serialUSB.Read(data, 0, data.Length);

          if (bytesRead > 0)
          {
            Debug.Print("Bytes Recieved");
          }
        }
        catch (Exception)
        {
          USBH_ERROR err = USBHostController.GetLastError();
          Debug.Print("Description: " + err.ToString());
        }
      }
    }
  }
}


Your device is stalling the communication pipe for some reason. We wouldn’t know without some investigations on the actual device you are trying to connect to. This falls under GHI’s consulting service. Please contact us directly if interested.