LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

GetCtrlVal fails when migrating code from CVI 5 to CVI 7.1

Hi all,
I'm having problems moving working code over to CVI 7.1 from CVI 5.5. I have a .uir with a switch, and want to use GetCtrlVal to find the position of the switch. I have a panel handle that I define globally, as usual. However, with CVI 7.1, the callback generates warnings when the switch is hit. If I continue past the warnings and do not break, the switch changes position, but does nothing. The value of the panel handle is 0 at all times. However, if locally to that callback, I write "int panelHandle = panel", with "panel" being one of the variables used by the CVI-generated callback function, everything works without errors. Up to now, all I had to do was define "panelHandle" globally at the top of my program for the .uir functions to work. What's going on?
Thanks for your help.
0 Kudos
Message 1 of 7
(3,618 Views)
Hello Dima2882,

So from your post, are you saying that your basic setup is something like:

static int panelHandle;

int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "printtext.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
}

int CVICALLBACK SwitchCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int value;
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (panelHandle, PANEL_BINARYSWITCH, &value);
break;
}
return 0;
}

I would make sure when you call LoadPanel, that you assign the returned value to panelHandle. The value stored in the panel parameter of your callback is the same handle that was returned by the LoadPanel, NewPanel or DuplicatePanel functions. So you shouldn't have to redeclare panelHandle or assign it the value of panel. It might be helpful for you to post a small portion of your code so we can see what is going on.

Thanks.
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 2 of 7
(3,596 Views)
Ok,
I checked my code, and it is very similar to what was posted... and it works perfectly in CVI 5! The part that is commented out in the callback function is the code I have to add in CVI 7 in order for my switch to work correctly. Maybe there's somethig wrong with this, but I definetly can't see it. Thanks for your help.
My main function uses the .uir in the following way:

TroubleShoot = LoadPanel (0, "TROUBLESHOOT.uir", TROUBLE);
DisplayPanel(TroubleShoot);
RunUserInterface ();
DiscardPanel (TroubleShoot);

My callback function is:

int CVICALLBACK setUutPower (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int pos;
//int TroubleShoot = panel;
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (TroubleShoot, TROUBLE_POWER,&pos);
switch ( pos )
{
case 0: powerDownUUT(); break;
case 1: powerUpUUT(); break;
}
break;
}
return 0;
}
0 Kudos
Message 3 of 7
(3,584 Views)
Do you have TroubleShoot declared as a global?
If TroubleShoot is declared in main(), setUutPower() won't be able to see it and you need to delcare it and initialize it in setUutPower.
If TroubleShoot is declared as a global (before main()), setUutPower can see it and you won't need the declaration and initialization in setUutPower.
0 Kudos
Message 4 of 7
(3,572 Views)
Hello Dima2882,

So as you said previously, if you already have TroubleShoot declared globably as in:

static int TroubleShoot;

int main (int argc, char *argv[])
{
...
}

Then your code should work. You mentioned that you receive warnings when you run your application in CVI 7.1. Specifically what error messages/warnings are you receiving?
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 5 of 7
(3,567 Views)
My error occurs when I hi a switch, or press a button on the GUI panel. It is as follows:

Non-fatal runtime error
Library function error(return value == -4
Panel, pop-up, or menu bar handle is invalid

The library function n questio is GetCtrlVal. I have seen that the way to set up handles is indeed the way I have been doing it so far in my program... is there anything else that may prcelude a function such as GetCtrlVal from working properly?
0 Kudos
Message 6 of 7
(3,560 Views)
As AL S and Wendy mention, you might be running into some kind of issue with variable scopes. Try using DebugPrintf to print out the value of the panel handles and see if its the same as the one returned by LoadPanel for your UIR.
Bilal Durrani
NI
0 Kudos
Message 7 of 7
(3,554 Views)