Advertisement

01.03.2007 at 08:11AM PST, ID: 22109578
[x]
Attachment Details

Visual Studio C++ Windows Form Application - Threading.

Asked by banana_split in Microsoft Visual C++.Net

Tags: , , ,

Hi everyone Got a problem with understanding how this works. I am trying to read in the data values of a P5 GAME glove, And i want to create a Windows form to display the data that i have retrieved from my P5 GAME GLOVE. But the problem that i am facing is that i do not know how to read the data from my glove to the form application in real time.

So temporary i created a button, and when i want to see the data values i would have to click on the button and it would release the data values.

this is my code for it :

private: System::Void btnGet_Click(System::Object^  sender, System::EventArgs^  e) {
                        
                        int finger1bent = 1100;
                        int finger2bent = 1100;
                        int finger3bent = 1100;
                        int finger4bent = 1400;
                        int tumbbent = 0;

                        P5_Init();
                        P5_SetUnits(P5_CM);

                        P5State *state = P5_GetStatePointer(0);
                        P5Info *info = P5_GetInfoPointer(0);

                        lblValue1->Text = state->FingerAbsolute[1].ToString();
                        lblValue2->Text = state->FingerAbsolute[2].ToString();
                        lblValue3->Text = state->FingerAbsolute[3].ToString();
                        lblValue4->Text = state->FingerAbsolute[4].ToString();
                        lblValue5->Text = state->FingerAbsolute[5].ToString();

                        lblFP0->Text = state->FilterPos[0].ToString();
                        lblFP1->Text = state->FilterPos[1].ToString();
                        lblFP2->Text = state->FilterPos[2].ToString();
                        lblFP3->Text = state->FilterPos[3].ToString();
                        lblFP4->Text = state->FilterPos[4].ToString();

                        lblDeviceId->Text = info->DeviceID.ToString();
                        
                        if (state->FingerAbsolute[1] > finger1bent && state->FingerAbsolute[2] > finger2bent && state->FingerAbsolute[3] < finger3bent && state->FingerAbsolute[4] < finger4bent ){
                              lblHandStatus->Text = "SISSORS";
                        }
                        if ( state->FingerAbsolute[1] < finger1bent && state->FingerAbsolute[2] < finger2bent && state->FingerAbsolute[3] < finger3bent && state->FingerAbsolute[4] < finger4bent ){
                              lblHandStatus->Text = "STONE";
                        }
                        if ( state->FingerAbsolute[1] > finger1bent && state->FingerAbsolute[2] > finger2bent && state->FingerAbsolute[3] > finger3bent && state->FingerAbsolute[4] > finger4bent ){
                              lblHandStatus->Text = "PAPER";
                        }
                        P5_Close();
       }


When i try to put it into a while loop at the Form_Load part to try to get the values dynamically, the program with just hang:

The attempted codes are:

private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
            
                  /*
                  int finger1bent = 1100;
                  int finger2bent = 1100;
                  int finger3bent = 1100;
                  int finger4bent = 1400;
                  int tumbbent = 0;

                  P5_Init();
                  P5_SetUnits(P5_CM);

                  P5State *state = P5_GetStatePointer(0);
                  P5Info *info = P5_GetInfoPointer(0);

                  int counter = 0;
                  while (counter =0) {

                        lblValue1->Text = state->FingerAbsolute[1].ToString();
                        lblValue2->Text = state->FingerAbsolute[2].ToString();
                        lblValue3->Text = state->FingerAbsolute[3].ToString();
                        lblValue4->Text = state->FingerAbsolute[4].ToString();
                        lblValue5->Text = state->FingerAbsolute[5].ToString();

                        lblFP0->Text = state->FilterPos[0].ToString();
                        lblFP1->Text = state->FilterPos[1].ToString();
                        lblFP2->Text = state->FilterPos[2].ToString();
                        lblFP3->Text = state->FilterPos[3].ToString();
                        lblFP4->Text = state->FilterPos[4].ToString();

                        lblDeviceId->Text = info->DeviceID.ToString();

                        if (state->FingerAbsolute[1] > finger1bent && state->FingerAbsolute[2] > finger2bent && state->FingerAbsolute[3] < finger3bent && state->FingerAbsolute[4] < finger4bent ){
                              lblHandStatus->Text = "SISSORS";
                        }
                        if ( state->FingerAbsolute[1] < finger1bent && state->FingerAbsolute[2] < finger2bent && state->FingerAbsolute[3] < finger3bent && state->FingerAbsolute[4] < finger4bent ){
                              lblHandStatus->Text = "STONE";
                        }
                        if ( state->FingerAbsolute[1] > finger1bent && state->FingerAbsolute[2] > finger2bent && state->FingerAbsolute[3] > finger3bent && state->FingerAbsolute[4] > finger4bent ){
                              lblHandStatus->Text = "PAPER";
                        }
                  }//end of while loop
                  */
            }

After searching around the net, i found out that i should use a thread to solve this problem. But i am not sure how. Could any one point me in the right direction? or could someone advice me on what should i do, to be able to view the datas from my glove on the windows form, dynamically.

Thanks a million.Start Free Trial
[+][-]01.03.2007 at 08:21AM PST, ID: 18236343

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual C++.Net
Tags: visual, form, windows, studio
Sign Up Now!
Solution Provided By: AlexFM
Participating Experts: 1
Solution Grade: A
 
 
[+][-]01.03.2007 at 09:43PM PST, ID: 18241169

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32