LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

binary switch value

hey folks,
quick question.
I am trying to use values from a binary switch to control an 'if' statement, but it doesnt seem to be working right. so i just tried displaying values from a numeric indicator to figure what was happening with the switch values.
 
SetCtrlVal (panelHandle, PANEL_N22, PANEL_bs );   //bs-binary switch, N22-indicator
I noticed that once the switch was used the value on indicator stayed static even if it was toggled. i put multiple switches and noticed they all give different values for different switches but they never change while toggling, and the values are all over the place altho i set all the data types to 'int' and ON,Off to 1,0 respectively.
thx for n e help.
0 Kudos
Message 1 of 5
(4,908 Views)

nvm.... figured out

PANEL_bs is a pointer(altho i couldnt dereference it wit *)...I found i could display the  values using getctrlval to a variable then use that variable. isn't there a direct way to do it ?

0 Kudos
Message 2 of 5
(4,906 Views)

In fact, PANEL_bs and PANEL_N22 are constants (not pointers); you will find them #define'd in the header file which is automatically generated by the UIR editor, and included in your program.

You need to get the switch state into a variable, and use that variable to set the indicator, something like this:

int switchState;
...
GetCtrlVal (panelHandle, PANEL_bs, &switchState);
SetCtrlVal (panelHandle, PANEL_N22, switchState);

I believe that's about as direct as it gets Smiley Happy

Regards,
Colin.

0 Kudos
Message 3 of 5
(4,890 Views)

btw im a noob in labwindows, altho i love coding in C, matlab.

 the weird part is you can use setctrlval to toggle the switch using 1 or 0 directly, or a variable.

SetCtrlVal (panelHandle, PANEL_bs, (1 or 0 or temp) ); // temp =1 or 0   

soit seems logical to handle PANEL_bs as an int variable which changes while toggling.

0 Kudos
Message 4 of 5
(4,886 Views)
For CVI to modify or read the value of a control, it must know which control and which panel (window) it is operating on. At runtime, panelHandle (an integer variable) uniquely identifies the panel instance*, and panelHandle and PANEL_bs (an integer constant) together uniquely identify the control.

How can CVI find a control if the value of its identifier in your code changes between calls?

Regards,
Colin.

* Note that the same panel may be loaded multiple times in your program.

0 Kudos
Message 5 of 5
(4,869 Views)