ranaya
Advanced Member level 4
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.
How to recieved continous data via the serial port ? any code examples ideas would be appreciated.
Thank you
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.
Code:
delegate void SetTextCallback(string text);
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e){
try{
SetText(serialPort1.ReadExisting()); //delegate one
}
catch{
btnClose_Click(this, null);
}
}
private void SetText(String text){
inCom = text.ToCharArray(0, 1);
if (inCom[0] == 'A'){ //ready to configure
if (txtDataReceived.InvokeRequired){
SetTextCallback d = new SetTextCallback(SetText);
Invoke(d, new object[] { text });
}else{
txtDataReceived.Clear();
txtDataReceived.Text = "Configure...";
}
}else if (inCom[0] == 'B'){ //load recorded data
if (txtDataReceived.InvokeRequired){
SetTextCallback d = new SetTextCallback(SetText);
Invoke(d, new object[] { text });
}else{
txtDataReceived.Clear();
txtDataReceived.Text = "Load...";
}
}else{
}
}
How to recieved continous data via the serial port ? any code examples ideas would be appreciated.
Thank you