When I try to write to the USB buffer in multiples of 64 bytes, I get an exception:
#### Exception System.Exception - CLR_E_PIN_UNAVAILABLE (1) ####
#### Message:
#### GHIElectronics.TinyCLR.Devices.UsbClient.Provider.UsbClientControllerApiWrapper::Write [IP: 0000] ####
#### GHIElectronics.TinyCLR.Devices.UsbClient.RawDevice+RawStream::Write [IP: 006f] ####
#### GHIElectronics.TinyCLR.Devices.UsbClient.Cdc+CdcStream::Write [IP: 0014] ####
#### GHIElectronics.TinyCLR.Devices.UsbClient.RawDevice+RawStream::Write [IP: 0021] ####
#### UsbSendBlank.Program::Main [IP: 00bd] ####
"System.Exception" in GHIElectronics.TinyCLR.Devices.UsbClient.dll
An exception is thrown when trying to send a terminating ZERO-LENGTH DATA PACKET.
Packets not multiples of 64 bytes are transmitted without exceptions.
Code:
static void Main()
{
var usbclientController = UsbClientController.GetDefault();
var usbClientSetting = new UsbClientSetting()
{
Mode = UsbClientMode.Cdc,
ManufactureName = "Manufacture_Name",
ProductName = "Product_Name",
SerialNumber = "12345678",
};
var cdc = new Cdc(usbclientController, usbClientSetting);
cdc.DeviceStateChanged += (a, b) => Debug.WriteLine("Connection changed.");
cdc.DataReceived += (a, count) => Debug.WriteLine("Data received:" + count);
cdc.Enable();
while (cdc.DeviceState != DeviceState.Configured) { Thread.Sleep(100); }
Debug.WriteLine("UsbClient Connected");
// The example will read data from port to dataR array
// Copy dataR to dataW array, plus 1 for each element
// Write dataW array back to port
var buffer = new byte[256];
for (int i = 0; i < buffer.Length; i++)
{
buffer[i] = (byte) i;
}
while (true)
{
try
{
cdc.Stream.Write(buffer);
Thread.Sleep(1000);
}
catch { }
}
}