Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C# USB CDC application help

Status
Not open for further replies.

ranaya

Advanced Member level 4
Full Member level 1
Joined
Jan 22, 2012
Messages
101
Helped
4
Reputation
8
Reaction score
9
Trophy points
1,298
Location
Kelaniya
Activity points
2,164
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.

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
 

In what format is the data to be transmitted to the host, integer, float, text all of above?

Can you provide an example data stream?

BigDog
 

hi.. thanx for the response...

device sends a byte array to the host. MCu code looks like :
Code:
res = f_read(&File, buffer, sizeof(buffer), &br);
USB_WriteEP(CDC_DEP_IN,(unsigned char *)&buffer[0],64);

Read a 64byte (buffer) from the sd card and write them to the endpoint. If I print the byte array read from sd card in lpcxpresso ide it displays

1.00
2.00
3.00........

Now I need to transfer them to the host. Send 1 data stream (64 byte array) and from the host it will be stored somewhere and continue next transmission. :)
 

Hi...... I could solve the data receiving problem. Now my c# application can receive the data sent by the MCU. But there's another problem. Received data sequence is not correct. Expected sequence is 0.00, 1.00, 2.00....., 49.00, 0.00, 1.00........

Instead i received this :-
0.00
1.00
2.00
3.00
4.00
5.00
6.00
7.00
8.00
9.00
10.

14.00
15.00
16.00
17.00
18.00
19.00
20.00
21.00
22.00

1.00
2.00
3.00
4.00
5.00
6.00
7.00
8.00
9.00
10.00

.00
39.00
40.00
41.00
42.00
43.00
44.00
45.00
46.00
47
.00
15.00
16.00
17.00
18.00
19.00
20.00
21.00
22.00
23
0
27.00
28.00
29.00
30.00
31.00
32.00
33.00
34.00
35.0
7.00
28.00
29.00
30.00
31.00
32.00
33.00
34.00
35.00
3

So definitely the problem might be in my c# code. I reduce the data sending rate to the host inside the MCU. result's same. I use above c# event handling code. what could be the mistake ? i didn't use timeout parameters for the serial port in c#. pls can some1 explain me

Thanx
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top