• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

display data in VC++ labelbox

Not open for further replies.


New Member
hope you can help me with this .

Trying to read switch state
Interface USB - PIC Microcontroller.

The PIC part sends OutputPacketBuffer , and The PC Part recevies 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
each time I press the switch.

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 Switch without clicking the mouse , nothing happens.

What I want is to override the mouse click as event handler.

What can I do to see this counter incremented when I just push 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
a: i=tmp;
label1->Text = i.ToString();//call display number in Label1


I hope you can help me.
Carlos Muñoz.
Not open for further replies.

Latest threads

EE World Online Articles