Please register or login. There are 0 registered and 1197 anonymous users currently online. Current bandwidth usage: 326.30 kbit/s December 12 - 06:22pm EST 
Hardware Analysis
      
Forums Product Prices
  Contents 
 
 

  Latest Topics 
 

More >>
 

    
 
 

  You Are Here: 
 
/ Forums / Programming /
 

  External event handler a real Challenge ¡ ¡ ¡ ¡ 
 
 Author 
 Date Written 
 Tools 
carlos muñoz Apr 23, 2009, 10:13am EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List

Edited: Apr 24, 2009, 04:51pm EDT

Replies: 1 - Views: 1576
Dear friends,

The project is a PIC based USB interface.
The PIC part is always sending OutputPacketBuffer, and The PC Part is always checking InputPacketBuffer. The only address I am testing is InputPacketBuffer´s first byte (switch on or off).
The PC part is a Vc++ program. A Form with a Label Box inside with default eventhandler "Label1click" and a little C++ code to increment a counter inside LabelBox
When I star the Vc++ program, the first step is to establish communication with the PIC, a succes communication open the Form1 with label1 inside.
Label1 displays number "0".
While Vc++ program is running, if I do not press the switch and clicking the mouse several times, the counter in Label remains 0 (zero).
If I leave the switch pressed, and I click the mouse , counter in label1 is incremented, I am sure PC is reading well at the PIC.
If I press the button without clicking the mouse , nothing happens.

What I want is to override the click as event handler so I have deleted some lines trying to increment the counter when I press the switch.
I really dont know how to associate this switch event to a Event handler.

Here is C++ code for getting data from PIC and increment the counter in Label1.

//+++++++++++++++++++++++
void getdata (void)
{
DWORD BytesWritten = 0;
DWORD BytesRead = 0;
unsigned char OutputPacketBuffer[65]; //Allocate a memory buffer equal to our endpoint size + 1
unsigned char InputPacketBuffer[65];
//The first byte is the "Report ID" and does not get transmitted over the USB bus. Always set = 0.
InputPacketBuffer[0] = 0;
//The first byte is the "Report ID" and does not get transmitted over the USB bus. Always set = 0.
OutputPacketBuffer[0] = 0;

//Blocking function, unless an "overlapped" structure is used
WriteFile(WriteHandle, &OutputPacketBuffer, 65, &BytesWritten, 0);
//Blocking function, unless an "overlapped" structure is used
ReadFile(ReadHandle, &InputPacketBuffer, 65, &BytesRead, 0);

i=InputPacketBuffer[1]; // i= sw state
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) { //++ CLICK EVENT HANDLER ++//

getdata(); // call getdata

if(i == 1)//if i eq 1,
{
goto a; //leave the number as is
}
else //increment it
{
tmp=tmp+1;
a: i=tmp;
label1->Text = i.ToString();//call display number in Label1

}
}
};
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++

The other part of C++ code just enable Form1 when PIC is connected to PC, it works well.
I have LowPinCount Board with debug header enabled.

Let me tell you that I have done flashing Leds sending data from PC to PIC, clicking buttons on a Vc++ Form.
PC to PIC communication it´s done.


Want to enjoy fewer advertisements and more features? Click here to become a Hardware Analysis registered user.
FingerMeElmo87 Apr 23, 2009, 10:29am EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: PIC to USB visual C++ Help ¡ ¡ ¡
you may want to ask a user here by the name of McFly. he's a bit of a programmer

Phenom II 720 BE @ 3.41Ghz w/ Zerotherm Nirvana NV120
G.Skill 2 x 2GB DDR2 1066 @ 5-5-5-15
GIGABYTE GA-MA790X-UD4
VisionTek HD 4850 512MB GDDR3
500GB Seagate 7200.12 - Windows 7 RC1
Hiper Type-R 580 WATT PSU

Write a Reply >>


 

    
 
 

  Topic Tools 
 
RSS UpdatesRSS Updates
 

  Related Articles 
 
 

  Newsletter 
 
A weekly newsletter featuring an editorial and a roundup of the latest articles, news and other interesting topics.

Please enter your email address below and click Subscribe.