Hello every1.......
I'm using USB CDC class for the comunication between my lpc1769 device and the host. A C# form application is developed to handle host communication. So usb port / connection enumerate as a com port on host side. First I need to confidure my device. It's a data logger. From the host I send configuration details of the data logger channels to the device by sending few characters (if char1 = v, it says channel1 = voltage).
After the configuration is done record command will be sent and device starts to log data. Upto this point my application works fine. Now I need to transfer logged data to the host. So data should be trasmitted continously. For the above cases I use only
2 methods in form application.
delegate void SetTextCallback(string text);
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e){
try{
SetText(serialPort1.ReadExisting());
}
catch{
btnClose_Click(this, null);
}
}
private void SetText(String text){
inCom = text.ToCharArray(0, 1);
if (inCom[0] == 'A'){
if (txtDataReceived.InvokeRequired){
SetTextCallback d = new SetTextCallback(SetText);
Invoke(d, new object[] { text });
}else{
txtDataReceived.Clear();
txtDataReceived.Text = "Configure...";
}
}else if (inCom[0] == 'B'){
if (txtDataReceived.InvokeRequired){
SetTextCallback d = new SetTextCallback(SetText);
Invoke(d, new object[] { text });
}else{
txtDataReceived.Clear();
txtDataReceived.Text = "Load...";
}
}else{
}
}
Now Im sending 64 bytes per millisecond from the device to host, and at each receive
host app should store/ append them to a text file. So how to recieved continous data via the serial port ? full application is attached to this, any code examples ideas would be appreciated.
My App:
https://dl.dropbox.com/u/16049803/Csharp%20Simple%20CDC%20Demo.rar[
^]