Click here to Skip to main content
15,886,799 members

C# usb cdc application help

Ranabasu asked:

Open original thread
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[^]
Tags: Gridview, USB

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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