Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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'){                               //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{
                
            }
  }


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[^]
Posted
Updated 7-Jul-12 7:54am
v2
Comments
[no name] 7-Jul-12 14:08pm    
"So how to recieved continous data via the serial port ?" You already are via serialPort1_DataReceived. So what is your actual question? And no I am not downloading an exe from an unknown source.
Ranabasu 8-Jul-12 7:12am    
I uploaded my c# application just to give a clear idea, not to harm any one. If u're not sure about it, better use an AV. This data receive function fires at first time and then no data is received though I send them continuously.......
[no name] 8-Jul-12 7:23am    
It does not matter what your intentions are, no one with any sense at all is going to download an exe from an unknown source and run it on their system. It would not do any good anyway unless someone that had the same equipment as you just happened by and saw this.

From the sound of this, your port is not configured correctly, or you are disabling the datareceived event in some manner, there is no data to receive, there is not enough data in the buffer to trigger the event, the server is not sending data. could be a host of things but you have not provided enough information to say.

Hook up a serial sniffer to your setup to see what is being transmitted back and forth and see if that will provide a clue.
Ranabasu 8-Jul-12 10:14am    
Hi thanx for the responses :) mm... ok I want to clear few things.

As u said I've already used the serialPort1_DataReceived function. So when the data's present each time this function get called. Am i right ? But I'vnt use an event handler for the port. And a separate thread. How to use a separate thread for the port ??

Thanx



This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900