Click here to Skip to main content
13,143,628 members (30,875 online)
Rate this:
Please Sign up or sign in to vote.
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.

delegate void SetTextCallback(string text);
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e){
         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 });
                    txtDataReceived.Text = "Configure...";
            }else if (inCom[0] == 'B'){                        //load recorded data
                if (txtDataReceived.InvokeRequired){
                    SetTextCallback d = new SetTextCallback(SetText);
                    Invoke(d, new object[] { text });
                    txtDataReceived.Text = "Load...";

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:[^]
Posted 7-Jul-12 7:49am
Updated 7-Jul-12 7:54am
Wes Aday 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.......
Wes Aday 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 ??


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 7 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100