I am very happy to know that. HOW???
On Spider client I have configured the switches to Serial Debug; then, using an UsbClientDP, I initialized [em]USBC_CDC cdc[/em] as [em]USBClientController.StandardDevices.StartCDC()[/em]
When its state got Running, I started writing on it.
On Spider Host I have a UsbHost, which is not configured in the designer to avoid a warning message, but handled using
[em]USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;[/em]
where
private void DeviceConnectedEvent(GHI.Premium.System.USBH_Device device)
{
Debug.Print(“Device connected”);
switch (device.TYPE)
{
case USBH_DeviceType.Serial_CDC: // CDC connected
if (UsbClient != null) return;
UsbClient = new USBClientController(device);
return;
…
}
}
As suggested by Jeff, this is the device handling class:
public class USBClientController : USBH_Device
{
private USBH_RawDevice raw;
private USBH_RawDevice.Pipe readPipe, writePipe;
private byte[] readBuffer = new byte[32];
private byte[] writeBuffer = new byte[8];
private Thread Client_Thread;
bool terminateThread = false;
public USBClientController(USBH_Device device)
: base(device)
{
raw = new USBH_RawDevice(device);
USBH_Descriptors.Configuration cd = raw.GetConfigurationDescriptors(0);
writePipe = raw.OpenPipe(cd.interfaces[0].endpoints[1]); // to write settings (LEDs, strobe...)
readPipe = raw.OpenPipe(cd.interfaces[0].endpoints[0]); // to read buttons
readPipe.TransferTimeout = 0;
raw.SendSetupTransfer(0x00, 0x09, cd.bConfigurationValue, 0x00);
USBHostController.DeviceDisconnectedEvent += USBHostController_DeviceDisconnectedEvent;
for (int i = 0; i < readBuffer.Length; i++)
readBuffer[i] = 0;
for (int i = 0; i < writeBuffer.Length; i++)
writeBuffer[i] = 0;
writeBuffer[1] = 0x08;
Client_Thread = new Thread(ReaderThread); // create the polling thread
Client_Thread.Priority = ThreadPriority.Highest; // we should read as fast as possible
Client_Thread.Start();
}
void USBHostController_DeviceDisconnectedEvent(USBH_Device device)
{
terminateThread = true;
USBHostController.DeviceDisconnectedEvent -= USBHostController_DeviceDisconnectedEvent;
}
private void ReaderThread()
{
// Read every bInterval
while (!terminateThread)
{
Thread.Sleep(readPipe.PipeEndpoint.bInterval);
try
{
[b]readPipe.TransferData(readBuffer, 0, readBuffer.Length);[/b]
}
catch(Exception ex)
{
}
}
}
}
The bold line is where I get the exception 