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.

New to PIC and USB. problem getting data from PIC in c#

Status
Not open for further replies.

mn75930

Newbie level 2
Newbie level 2
Joined
Jan 22, 2008
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,300
Hello, I’m new to pic and usb programming.
So I start to test the article Basic USB - Using Microchip Stack and C#.Net - Hardware form www.PICcoder.co.uk
This code works, but I got some trouble when I’m trying to receive more then 1byte from the microcontroller.
The thing I’m trying to do it that when I send the command 0x50 to the microcontroller, I need to get some data back from it. I’m using c# and ask for 4bit of data.
The problem is that the LED is working but I just get data back from the PIC every second time I run the command 0x50..
This is the code I have modified in to the PIC project:
Code:
case LED:
  mLED_4_Toggle();
 dataPacket._byte[1]= '1';
  dataPacket._byte[2]= '2';
  dataPacket._byte[3]= '3';
  counter=0x04;
break;
Then I use the SendReceivePacket function and it returns this STRING 50495051.
The next time I use SendReceivePacket I got the STRING 0000.
ExpectedReceiveLength = 4
ReceiveLength = 0

Why?? The LED4 is flashing every time, but I can’t get data from the CHIP more then every second time I hit my button in the form1.
Please help me?? What am I doing wrong???
 

hum it is the transparency of the state 1 2 3 you need to watch for

use 0x01 0x02 not '1' '2' remember zero is also a state so 1 is really 2

try that

case LED:
mLED_4_Toggle();
dataPacket._byte[1]= 0x01; // {really state '2' } also maybe you need to start 0x00
dataPacket._byte[2]= 0x02; // {really state '3' } 0x01
dataPacket._byte[3]= 0x03; // 0x02
.. missing paket here byte 4
counter=0x04; /{remember this is 5 states 0x00 0x01 0x02 0x03 0x04 maybe you need 0x03 here instead of 4}
break;

also watch for dataPacket_byte[0] ?? is this used somewhere else??

so given this

more like

case LED:
mLED_4_Toggle();
dataPacket._byte[0]= 0x00;
dataPacket._byte[1]= 0x01;
dataPacket._byte[2]= 0x02;
dataPacket._byte[3]= 0x03;
counter=0x03;
break;
 

Hello...

dataPacket_byte[0] ?? is used somewhere else.
So the total number of bytes to send is 4.
I have try'd to set it to 3 and 5 but it is the same resoulte.

The function in c# is geting the 4bytes. But the next time I ask for 4bytes it returns 1byte.. I have made a work around for this so its not a bigg problem, but it's stupid to do this when I down't thing it shod work like this.

I thing there has to bee some body else that have try the exemple to www.PICcoder.co.uk and got the same problem..???
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top