11-12-2015 05:05 AM
Hi,
Only the UIR Ctrl constant name know when my aplication is running. I need to change some UIR Ctrl value based on the constant name.
I need the Ctrl ID to able to change the Ctrl value as far as I know.
- Is there any function to get the UIR Ctrl ID from constant name?
- Is there any function in CVI like Evaluate() in TestStand, so I could get the CTRL ID specified in a string (PANEL_CONSTANTNAME)?
Is there any other way to set a UIR Ctrl value using Ctrl constant name instead of the Ctrl ID?
Thanks!
11-12-2015 05:31 AM
I am not sure I understand you right, but does this answer your question?
11-12-2015 07:32 AM
Dear Wolfgang,
I would like to get the Ctrl ID from the Constant name when my application running without browsing the header file.
Regards,
11-12-2015 07:52 AM
So you have a UIR file called uir_file_name, you load it using LoadPanel (uir_file_name, PANEL, &panel_handle ); this user interface resource file contains all the assignments between the constant names and their values, i.e., control IDs.
So if you have, for instance, a LED control, you can set its attributes using SetCtrlAttribute (panel_handle, PANEL_LED, attribute_value ); the second parameter, PANEL_LED, is the control ID.
So if you wish LoadPanel is browsing the header file for you, after LoadPanel you can access the control IDs using the constants found in the uir file.
Sorry if I misunderstand your request
11-12-2015 08:18 AM
This is an example:
I have an uir with many LEDs. The LEDs constant name LED_0, LED_1, LED_2...etc.
I would like to set the LEDs based on different events. The event IDs are match to the LED numbering.
So if event 3 occurs then I would like to set LED_3 in a way to generate a sting represent the Ctrl ID. e.g.: "PANEL_LED_" + event ID = "PANEL_LED_3"
Is it possible to use this string somehow to set the Ctrl?
11-12-2015 08:39 AM
Thanks for the explanation
So there are at least three options:
One is to use control arrays, I think this is the preferred way, see here
You can also build your controls programmatically, this is the way I usually do it.
And of course you can make this assignment after loading the panel manually, maybe not elegant but quick, something like:
int led_control [ 10 ];
LoadPanel (); // provides the constants
led_control [ 0 ] = PANEL_LED_0;
led_control [ 1 ] = PANEL_LED_1;
...
led_control [ 9 ] = PANEL_LED_9;
the you can access your LED i using led_control [ i ]..
11-12-2015 08:42 AM
You can find the constant name (as a string) as one attribute of a control (I think it's ATTR_CONST_NAME but I don't have CVI open right now). So you COULD iterate on all controls of a panel until you find the one you want but there's usually no need to do that, since you can already use the const name directly. For instance:
int Leds[]={PNL_LED_0, PNL_LED_1, PNL_LED_2}; SetCtrlVal(Pnl, Leds[1], 1);
to turn on the 2nd one.
11-12-2015 08:43 AM
Ha! 3 minutes late on Wolfgang...