LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

control array of callback functions?

Solved!
Go to solution

Apologies for my basic question.

 

I am experimenting with control arrays and so far am able to collect data in string controls that are inside control arrays.  Works well.  Naturally, none of these controls need callback functions.

 

Now I have need of some momentary command buttons in a control array as well.  So my question is, should I use a single callback function for all of the button controls in that single array?  And if so, how do I go about identifying which element in the control array called the function?  From reading on the forums, it seems as if use of the callback data parameter might get me there.

 

Just wanted to ask before I get off track.  Thanks!

0 Kudos
Message 1 of 3
(3,414 Views)
Solution
Accepted by topic author ElectroLund

Yes, callbackData can be of help in such a situation, but if you can limit to switch on array index to discriminate what to do your button callback could be something on this line:

 

int CVICALLBACK BtnAttayCallback (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
    int    handle, index;

    switch (event) 	{
        case EVENT_COMMIT:
            handle = GetCtrlArrayFromResourceID (panel, control);
            GetCtrlArrayIndex (handle, panel, control, &index);
            switch (index) {
                // Your code here
            }
    }
    return 0;
}

 (No CVI install here so I cannot test it: double check the code but it should reasonably work)



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,405 Views)

Ahh, that works very nicely.  It was the index function that I was missing.  I didn't realize that GetCtrlArrayIndex could start with a UIR controlID to unpack the array index.  Very handy function!

 

Here is my code:

 

int CVICALLBACK unitSetup (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
	int enabledArray;
	int SNArray;
	int index;
	char serialNumber[50];

	switch (event)
	{
		case EVENT_LOST_FOCUS:
			
			// get the handles for the control arrays
			enabledArray = GetCtrlArrayFromResourceID(panel,ENABLE);
			SNArray = GetCtrlArrayFromResourceID(panel,SN);
			
			// get the index of the serial number control
			GetCtrlArrayIndex(SNArray, panel, control, &index);
			
			GetCtrlVal(panel,GetCtrlArrayItem(SNArray,index),serialNumber);
			// disable the enable checkbox if the serial number has not been setup
			if (*serialNumber == NULL)
				SetCtrlAttribute(panel,GetCtrlArrayItem(enabledArray,index),ATTR_DIMMED,TRUE);
			else
				SetCtrlAttribute(panel,GetCtrlArrayItem(enabledArray,index),ATTR_DIMMED,FALSE);
			break;
	}
	return 0;
}

 

0 Kudos
Message 3 of 3
(3,392 Views)