External EventHandler a real Challenge ¡ ¡ ¡
Well, I am going to try to explain my problem.
Interfase USB PIC based.
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. It does not work ¡ ¡ ¡ ¡
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.