LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

GetUserEvents

Hello,

 

I am running Lab Windows CVI getting 10 channel data and displaying it on the screen.

I have a few buttons on the same screen and am using the GetUserEvents to see which button is pushed. If I stop reading and displaying data then everything is ok. But when the data is read and displayed then GetUserEvents does not see the button pushed all the time. It works most of the time but 30% of the time it does not see the button pushed.

I have to keep pushing any of the buttons for a response. I am using the "ProcessSystemEvents". But it did not make any difference.

Any ideas?

 

Thansk

0 Kudos
Message 1 of 8
(3,506 Views)

Hi bobby_y, 

 

1.) When is GetUserEvent getting called (such as in a while loop or every second etc.)?

2.) Are your buttons currently linked to a callback function? If so, would it be possible to use that callback function to record the button press?

 

Regards,

Vincent

0 Kudos
Message 2 of 8
(3,490 Views)

Hello,

 

It is called inside a WHILE loop.

The buttons are not linked to any callback function. I use the following routine

GetUserEvent (0, &handle_returned, &ControlID_returned)

switch (ControlID_returned)

{

       case Panel_TOGGLEBUTTON:

                    RGB();

       break;

       case Panel_TOGGLEBUTTON_2:

                    RGB1();

       break;

     case Panel_TOGGLEBUTTON_3:

                    RGB3();

       break;

printf ("hello\n");

 }

 

I have about 15 of these cases. I just showed you 3 of them.

I added a printf ("hello\n"); inside to see if pushing the button gets into the switch.

It does 60 to 70% of the time. I also added a ProcesSystemEvents() but it did not help.

 

Thanks

 

 

0 Kudos
Message 3 of 8
(3,485 Views)

Hi Bobby,

 

Have you tried setting the "waitMode" in GetUserEvent to 1? I am thinking that having a value of 0 for the waitMode might be causing GetUserEvent to return too early before keypress is registered, which is why the buttons seem to be working 70% of the time. 

 

Referring to http://zone.ni.com/reference/en-XX/help/370051V-01/cvi/uiref/cvigetuserevent/

 

    int GetUserEvent (int waitMode, int *panelOrMenuBarHandle, int *controlOrMenuItemID);

 

waitMode int If you specify a nonzero value or select wait in the function panel, GetUserEvent does not return until a commit event or programmer-defined event occurs.

If you specify 0 or select no wait in the function pane, GetUserEvent returns immediately, whether or not a commit event or programmer-defined event has occurred.

 

I look forward to your results!

 

Regards,

Vincent

0 Kudos
Message 4 of 8
(3,482 Views)

Hello Vincent

 

I can not set it to 1 because then the program hangs up there and waits for the operator to click on one of the buttons. The program needs to go through and do the the other functions such as display the data coming in, record the data, and so on. All these function need to be done in a dynamic fashion.

So if I change the value to a 1, then nothing will be displayed, data will not get updated, or anything else. The program just waits until the operator pushes one of the buttons.

 

Thanks

 

Bobby

0 Kudos
Message 5 of 8
(3,457 Views)

Hi Bobby, 

 

I tried using GetUserEvent in a while loop thread using CmtScheduleThreadPoolFunction, but unfortunately with no luck. It doesn't seem that any EVENT_COMMITs are obtained in the threaded loop. 

 

For the mean time, instead of using GetUserEvent to monitor button presses, would it be possible to link the buttons to a control callback? For example: 

 

int CVICALLBACK GetEventCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)

{

    switch (event)

    {

        case EVENT_COMMIT:

            if (control == Panel_TOGGLEBUTTON)

                RGB(): 

            else if (control == Panel_TOGGLEBUTTON_2)

                RGB1(); 

            else if (control == Panel_TOGGLEBUTTON_3)

                RGB3();

            else

                printf("You are using an invalid control.\n"); 

            printf ("hello\n");

        break; 

    }

    return 0; 

 }

 

I will check to see if it is possible to use GetUserEvent in your program and am curious to see if the community has had successful uses with GetUserEvent in a thread. I look forward to your results!

 

Regards,

Vincent

 

 

0 Kudos
Message 6 of 8
(3,448 Views)

Hello Vincent,

 

I got rid of the GetUserEvent.

I used the control callback function for each button pushed and it works fine.

So every time a button is called, it calls a callback function.

 

I have used "GetUserEvent" for many years before. It works okay if the loop is slow enough.

 

Thank You for your time

 

0 Kudos
Message 7 of 8
(3,442 Views)

Hi Bobby, 

 

Happy to hear your program is working!

 

Regards,

Vincent

0 Kudos
Message 8 of 8
(3,438 Views)