Hello Forum,
I am hoping one of you kind folks can help me out with with a CDC to serial port bridge issue.
I have a windows forms application with 6 trackbars that emulate an audio mixer.
When the trackbar/slider is moved, the trackbar id and trackbar position (0 to 63) is sent to my Fez Domino. For now, I just want the Domino to echo the trackbar id and position back to my Windows application. (ie: a wrap-around test to validate what I am sending is being received).
If I move a trackbar very slowly (1 step/second),the trackbar position and id is echo’d back correctly. If I move the trackbar a little faster, the data retreived starts to lag behind the data sent.
For example, if I send 1,2,3,4,5 if get back 1,2,3.
If I move the trackbar one more step to 6, I get back 4.
Given the CDC bridge runs at 12M, I figure I do not have a timing or latency issue.
I suspect I am doing something stupid, but after hours of looking, I can not find it.
I am hoping one of you kind folks can help me out. I provided pigeon code below demonstrating my approach.
Thanks much for your help,
Larry Scott,
Walnut Creek, CA
==============================================
== CSHARP WINDOWS ‘FORMS’ APPLICATION
// When trackbar is moved, this method is invoked.
// I can see here the command being written to the listbox and serial port.
private void trackBarS1A_Scroll(object sender, EventArgs e)
{
Control control = (Control) sender;
String name = control.Name;
String nm = "";
int position = 0;
if (name.Equals("trackBarS1A")) { position = trackBarS1A.Value; nm="P1A"; } else
if (name.Equals("trackBarS1B")) { position = trackBarS1B.Value; nm="P1B"; } else
if (name.Equals("trackBarS2A")) { position = trackBarS2A.Value; nm="P2A"; } else
if (name.Equals("trackBarS2B")) { position = trackBarS2B.Value; nm="P2B"; } else
if (name.Equals("trackBarS3A")) { position = trackBarS3A.Value; nm="P3A"; } else
if (name.Equals("trackBarS3B")) { position = trackBarS3B.Value; nm="P3B"; } else
if (name.Equals("trackBarS4A")) { position = trackBarS4A.Value; nm="P4A"; } else
if (name.Equals("trackBarS4B")) { position = trackBarS4B.Value; nm="P4B"; }
listBox1.Items.Add(name + ": " + position);
if (!(serialPort == null))
{
String cmd = nm + "~" + position;
listBox1.Items.Add("Send: " + cmd);
serialPort.Write(cmd + "\n");
}
}
==============================================
== FEZ DOMINO CODE
public static void Main()
{
boolean usbFound = false;
if (Configuration.DebugInterface.GetCurrent() == Configuration.DebugInterface.Port.USB1) usbFound = true;
if (usbFound) cdc = USBClientController.StandardDevices.StartCDC_WithDebugging();
while (true)
{
String rcvd = ReadString(cdc);
if (rcvd.Length > 0) cdcWrite(rcvd + "\n");
}
} // main
---------------------
#region cdcread
public static string ReadString(USBC_CDC cdc)
{
String s = "";
while (true)
{
byte[] CDCBuffer = new byte[256];
int USBread = cdc.Read(CDCBuffer, 0, 256);
if (USBread <= 0) return s;
else
for (int i = 0; i < USBread; i++)
s += ((char)CDCBuffer[i]).ToString();
}
}
#endregion
---------------------
#region cdcwrite
static void cdcWrite(String s)
{
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(s);
cdc.Write(bytes, 0, bytes.Length);
}
#endregion