LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, I am trying to find out how to use the callback functions when attempting to check the status of multiple toggle buttons(checkboxes). Thank you very much for your help.

I am using the toggle button (checkbox) to control which analog output valve will be sent to the FP-AO-200. The checkbox is supposed to represent the user�s choice between using
a. manual mode (Here the user inputs a value between 4 and 20mA to send to the FP-AO-200) or
b. automatic mode (Here the input supplied to the FP-AO-200 is gathered from a text file)
When the box is checked the program is suppose to go into automatic mode.
My problem is that I am having trouble with the following:
I am trying to develop a way for the program multiple checkboxes are checked. I have eight channels that need to be checked by the checkbox. Currently the program only reads one checkbox. I have come up with two ways to work the problem. I needed to know if these ideas are right, and some help to implement them. Below I have provided the two ideas I am trying to implement:

The Applications engineer, Mr. Roberto Bozzdo told me to use this. I had some trouble trying to decide to get this command to read to read all eight channels. I wanted to know is it was legal to use a for-loop in the call back function. I thought would cause another problem because the valve of val is continuously changing. Is val representing a true false command to read 1/0?

int CVICallback read (int panel, int control, int event,
void*callbackData, int eventData1, int eventData)
{
int val;
switch (event) {
case EVENT_COMMIT;
GetCtrlVal (panel, control, &val); // Read the control status
if (val) { // Box checked: put your program in automatic mode }
else { // Box uncheked: ask the user the value}
err=FP_Read (FP_handle,IO_handle,value,256,�tamp);
if (err) {
printf (�passed\n�);}
}
return 0;
}
The second way using the GETCtrlVal ( ) with a different for-loop, but I don�t know if I am using the correct callback function. Here I tried to combine the commands for the manual mode with the commands for the automatic mode of the program. Below is a sample of my source code:

int CVICallback read (int panel, int control, int event,
void*callbackData, int eventData1, int eventData)
{
IAStatus status = IA_SUCCESS;
int i; //For-loop counter variable
float temp; //Temorary hold value
int val; //Is this a bool value

switch (event) {
case EVENT_COMMIT;
//Get status of the check boxes
for ( i=0; i{ GetCtrlVal(panHandle, i+PANEL_CHECKBOX, &val)
if (val)
{ //Go to automatic mode }
else
{ for ( i=0; i {
GetCtrlVal(panelHandle, i+PANEL_NUMERICO, &temp)
Memcpy (value(+_I*4).&temp, 4);
}
status=FP_Write (FP_handle, IO_handle, valve, BUFFER_SIZE);
}
Thank you very much for your help.
0 Kudos
Message 1 of 2
(3,029 Views)
I assume that in your panel you have 8 checkboxes, each of them with a numeric logically associated with it, so when the user unchecks a checkbox, the program must read the correspondent numeric value and pass it to the FP.
If this is the case, your second solution is not good, 'cause you are using the same index for the inner and outer loop. That way the source code will be read as follows:
- read the first checkbox. If checked, pass to the next
- if unchecked: enter the inner loop
- reinitialize the for index 'i' to 0
- scan all numerics
- at the end of the inner loop i=POINTS
- then the program starts a new iteration of the outer loop but founds i=POINTS+1 and exits it. That is: at the first box unchecked, the scanning of checkboxes will end.

Second
point: you are relying on the order of the controls in the panel to decide which control to read in the loops. This is dangerous because if you insert a new control or change the tab order of the panel's controls the program could point to the wrong control and you will catch a lot of errors. In this case I am used to create an array of control names and use the array elements to address the desired controls, like in the sample code attached.

Should you desire some more help, feel free to write directly to me at roberto.bozzolo@eltra.net

Roberto


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?
Message 2 of 2
(3,029 Views)