LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

reading a control value from a tabbed panel

Hi!

I have used the easytab/simpdemo sample which was shipped with LabWindows and wanted to simply get values from different tabbed panels. However the two different data i read is the same, and it shows some weird behavior when experienced more (moved the string control to the secound tab and i couldnt even set its content).

Here is a snippet from the source code (i'm attaching the whole demo):

#include /* Needed if linking in external compiler; harmless otherwise */
#include
#include "easytab.h"
#include "simpdemo.h"

int panel, tabCtrl;

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

if (InitCVIRTE (0, argv, 0) == 0) /* Needed if linking in external compiler; harmless otherwise */
return -1; /* out of memory */

panel = LoadPanel(0, "simpdemo.uir", PANEL);

/* Two function calls and, Voila!, a tab sheet dialog */
tabCtrl = EasyTab_ConvertFromCanvas(panel, PANEL_CANVAS);
EasyTab_LoadPanels (panel, tabCtrl, 1, "simpdemo.uir", __CVIUserHInst, CONTROL, 0,
VALVES, 0, MONITOR, 0, CONFIG, 0, HELP, 0, 0);

InstallPopup(panel);
RunUserInterface();

return 0;
}

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

int prb1, prb2;
char prba1[20], prba2[20];
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (panel, CONTROL_PROCESS_STATE, &prb1);
GetCtrlVal (panel, VALVES_INTAKE1 , &prb2);
sprintf(prba1, "%d", prb1);
sprintf(prba2, "%d", prb2);
SetCtrlVal (panel, CONTROL_STRING, prba1);
SetCtrlVal (panel, CONTROL_STRING_2, prba2);
break;
}
return 0;
}

Thanks for your help.
0 Kudos
Message 1 of 3
(3,827 Views)
This problem arise due to incorrect panel handle in your SetCtrlVal functions.

When loading the child panels, the example explicitly discards the handles for the panels:

EasyTab_LoadPanels (panel, tabCtrl, 1, "simpdemo.uir", __CVIUserHInst, CONTROL, 0,
VALVES, 0, MONITOR, 0, CONFIG, 0, HELP, 0, 0);

I quote from the help on "Panel IDs and Handle Pointers" in EasyTab_LoadPanels function:

"A zero-terminated list of argument pairs, one pair for each panel to load into the tab control. Each pair consists of a
panel resource ID and a pointer to an integer in which to store the panel handle.

The resource IDs and integer pointers are listed in pairs, with the resource ID preceding the integer pointer.

If you do not need the panelHandle for a particular panel, you may pass 0 instead of the integer pointer."


That is, to manipulate controls located on the tabbed panels you must retrieve panel handles when loading the panels into the tab control and use those handles in subsequent functions. Otherwise you are trying to manipulate controls located on the main panels which holds the tab control.

Your code needs then to be modified as follows:

// When loading the panels
EasyTab_LoadPanels (panel, tabCtrl, 1, "simpdemo.uir", __CVIUserHInst, CONTROL, &ctrlH,
VALVES, &vlvH, MONITOR, 0, CONFIG, 0, HELP, 0, 0);

// When using controls on the panels:
GetCtrlVal (ctrlH, CONTROL_PROCESS_STATE, &prb1);
GetCtrlVal (vlvH, VALVES_INTAKE1 , &prb2);
sprintf(prba1, "%d", prb1);
sprintf(prba2, "%d", prb2);
SetCtrlVal (ctrlH, CONTROL_STRING, prba1);
SetCtrlVal (ctrlH, CONTROL_STRING_2, prba2);


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 3
(3,821 Views)
Thank you very much for your help, its working now. I looked over it in the help.
0 Kudos
Message 3 of 3
(3,818 Views)