I’m using the USBC_CDC class and having issues sending more than 64 bytes at a time. If I send less than 64 bytes they are sent right away, however if I send 64 or more they won’t be sent until I send less than 64 bytes.
I’m using a Mini with the SD card extension and the mode pin grounded for debug over serial.
I’ve created a demonstration project which cycles through sending strings of bytes with a 1 second pause between them. They are 60, 61, 62, 63, and 64 bytes in length. When I run it the the 60 - 63 byte strings send out as expected but the 64 byte string isn’t sent until the 60 byte string is sent again. Also the debug output is as would be expected.
Thanks.
using System;
using System.Threading;
using System.Diagnostics;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.USBClient;
namespace CDCTest2
{
public class Program
{
static USBC_CDC Client = USBClientController.StandardDevices.StartCDC();
public static void Main()
{
while (true)
{
SendString("000000000000000000000000000000000000000000000000000000000000");
Thread.Sleep(1000);
SendString("1111111111111111111111111111111111111111111111111111111111111");
Thread.Sleep(1000);
SendString("22222222222222222222222222222222222222222222222222222222222222");
Thread.Sleep(1000);
SendString("333333333333333333333333333333333333333333333333333333333333333");
Thread.Sleep(1000);
SendString("4444444444444444444444444444444444444444444444444444444444444444");
Thread.Sleep(1000);
}
}
/// <summary>
/// Sends a string to the remote host.
/// </summary>
/// <param name="toSend">The string to send.</param>
static void SendString(string toSend)
{
Debug.Print(Client.Write(GetBytes(toSend), 0, toSend.Length).ToString());
//Debug.Print(string.Concat("CDC->\"", toSend, "\""));
}
//use this as UTF8 encoding stops at null char, chars above 127
private static byte[] GetBytes(char[] from)
{
byte[] to = new byte[from.Length];
for (int i = 0; i < from.Length; i++)
{
to[i] = (byte)from[i];
}
return to;
}
//use this as UTF8 encoding stops at null char, chars above 127
private static byte[] GetBytes(string from)
{
return GetBytes(from.ToCharArray());
}
}
}