LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Using control constant name to get its handle

When one creates a control, LabWindows defines a constant for it (#define  MASTER_LED_SYSTEM  2). Is there a function that will take this name as a string "MASTER_LED_SYSTEM", and returns the defined constant integer for it ?

The second question is the following. Is there a function that returns the handle of the panel that contains the control with the specified constant string name ("MASTER_LED_SYSTEM")?

Thanks.
0 Kudos
Message 1 of 10
(4,940 Views)
Edgar,

In response to your first question, I'm not sure how you would use such a function. Unless you are parsing the header file yourself, I'm curious as to when you would handle the #defined constants as strings. Because #define is a C preprocessor directive, by the time your program is compiled, every instance of the "name" (MASTER_LED_SYSTEM, for example) of a control IDs is gone from the code, replaced instead with the actual numeric value. This means that it is not possible to know at compile- or run-time what names mapped to what values.

As for your second question, again, the original "names" of the control constants are gone by the time you would have a panel handle.  Panel handles are generated at run-time by LoadPanel and NewPanel.  Nor can you use the control constant (integer value) to look up the containing panel, since multiple panels can have controls with the same constant values.  When specifying controls in CVI, you will always use both a panel handle and a control ID.

I hope that clears things up a bit.

Mert A.
National Instruments
0 Kudos
Message 2 of 10
(4,931 Views)
Hi Edgar.
 
I believe that the answers to your questions are "No" and "No".
 
However, you may find some useful pointers here (watch for minor errors in the content of the last message).
 
If you want your code to work exactly as you describe, you could scan through your loaded panels and controls, concatenate the panel and control ATTR_CONSTANT_NAME values, and compare. You could do this once, when the panels are loaded, and hold the info in an array or a list.
 
Regards,
Colin.
 
0 Kudos
Message 3 of 10
(4,930 Views)
That is correct. I had forgotten about ATTR_CONSTANT_NAME. Sorry for the confusion.
0 Kudos
Message 4 of 10
(4,926 Views)

Thanks for the reply.

The reason I need to have those types of functions is the following. I recevie a message from a softwarte in the following format. "PANEL_CONTROL_NAME:value" I need to set the specified value into the specified name. In order to do that I need to get the handle of that control and panel. So I have the name as a string and I need to get the handles in order to use SetCtrlVal().

We can not use PANEL_CONTROL_NAME as a defined integer as control specifiers in incoming messages because they are not unique. If you have multiple uir files you will have the same integer value for two different controls.

Your recommendations are highly appreciated.

0 Kudos
Message 5 of 10
(4,892 Views)
If You don't need to do it dynamically, i.e. the program does 'know' all the available panels and controls at compile time, I'd do it using a constant look up table like

struct
{
    char *name,
    int  id;
}
const id_lut[] =
{
  { "PANEL_CONTROL_NAME1", PANEL_CONTROL_DEFINE1 },
  { "PANEL_CONTROL_NAME2", PANEL_CONTROL_DEFINE2 },
  { 0, -1 }
};

Extended by a uir 'identifier' (maybe an enum) or whatever else you need to do an unambiguous look up.

Message Edited by CVI-User on 10-14-2005 10:02 AM

-----------------------
/* Nothing past this point should fail if the code is working as intended */
0 Kudos
Message 6 of 10
(4,882 Views)

Thanks.

Currently I use constant look up table. But it takes too much time to compare the strings to get a match. (2000 records) I thought LabWindows will provide a function for it.

0 Kudos
Message 7 of 10
(4,865 Views)

If lookup speed is an issue a lookup table is probably still one of the best ways to go.  You want to organize the table in a more efficient form for searching.  The two structures that come to mind for me are a hash table or a binary tree.  This should eliminate search time as an issue.

 

On a side note, if you wanted to build the lookup table dynamically you could do this by scanning each control of each panel and storing an entry in the table using the control's label value matched to the control id and panel handle.  CVI does provide ways to get the number and types of controls on a panel and scan through them.  This of course assumes that the label strings of each control match the string name you receive in the “software message”.   If they do not, you would need a way to match a controls label to the "software message" to identify which control is the target of which message.

 

Good Luck! 

Message Edited by mvr on 10-14-2005 04:56 PM

0 Kudos
Message 8 of 10
(4,860 Views)

Hi.

If you don't want to set up a hash table, I suggest you check out the "Lists..." item in the Programmer's Toolbox library. It has built-in functionality for binary searches, so much of the hard work is done for you. You just need to create a comparison function which is used for item insertion and retrieval. I have used this successfully with quite large lists.

Regards,
Colin.

 

0 Kudos
Message 9 of 10
(4,841 Views)

Edgar,

Another option that might be easier and faster would be to identify controls by a Panel ID and Control ID pair rather than the control constant name.  You are correct that Control IDs are not unique across panels, but the combination of Panel ID and Control ID will uniquely identify a control.  You could pass Panel ID and Control ID in your message and the receiving application would convert the Panel ID into a panel handle via a lookup table/list/etc.

-Jeff

 

 

0 Kudos
Message 10 of 10
(4,792 Views)