LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Get the value of a control attribute set in the uir

Solved!
Go to solution

Maybe this is a stupid question, but is there a way to get the value of a control attribute that has been set in the uir?

I try to explain better with an example.

  • I set the ON color for a led to VAL_RED in the uir
  • in the code I change the ON color to VAL_GREEN
  • GetCtrlAttribute() returns the current ON color (i.e. VAL_GREEN)
  • how can I get the value originally set in the uir (i.e. VAL_RED)?

 

Vix
-------------------------------------------
In claris non fit interpretatio

-------------------------------------------
Using LV from 7
Using LW/CVI from 6.0
0 Kudos
Message 1 of 7
(2,614 Views)
Solution
Accepted by topic author vix

Not so stupid a question!

I could think to a couple alternatives to obtain what you want.You could for example try calling DefaultCtrl and get the attribute value you want. Unfortunately, DefaultCtrl is more aimed to operate on the control value rather than its attributes so this is possibly a dead end. Besides it, should it works you'll have then to restore all modified attributes one by one!

As an alternative, you could load a second instance of the panel in memory and get attributes from the correspondent control in this offline copy. Of course, there is no need to display this panel.



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 7
(2,609 Views)

Hi vix,

what I do (not for LEDs, but numeric controls) to see if a value has changed is to save the old value before getting the new one:

old_value = current_value;

current_value = GetCtrlVal ();

if .....

(for an explanation of why I am not relying on the EVENT_VAL_CHANGED see here)

You can easily adapt this procedure for your case as well

 

0 Kudos
Message 3 of 7
(2,605 Views)

@RobertoBozzolo  wrote:
You could for example try calling DefaultCtrl ...

Looking to DefaultCtrl documentation I don't think this is a realistic option, unfortunately.

 


As an alternative, you could load a second instance of the panel in memory and get attributes from the correspondent control in this offline copy. Of course, there is no need to display this panel.

This seems to be an effective approach "at run time" (I mean, this involves calling a function during execution of the code). This involves reading an uir file from disk to get the information, so I can't estimate the performance (especially with big uir files).

 

Since the default values for attributes should be known at compile time, I wonder if there is an option to get this info "at compile time" (I mean, through a macro or something like that, that can be evaluated at compile time).

Unless CVI architecture allows changing the values inside the uir without recompiling the executable (I'm not sure if this is possible and/or allowed and/or recommended).

If this is the case, the only way would be "at run time" and so I think the best approach would be another call to LoadPanel.

Vix
-------------------------------------------
In claris non fit interpretatio

-------------------------------------------
Using LV from 7
Using LW/CVI from 6.0
0 Kudos
Message 4 of 7
(2,596 Views)

Well, I have never benchmarked calls to LoadPanel so I cannot say anything on that.

 

A different approach could be to maintain a list in memory of attributes changed and their default value. A structure like this one:

typedef struct {
    int panelHandle;
    int controlID;
    int   attribute;
    int    valType;     // int, double, char...
    int iVal;
    double    dVal;
    char    cVal[64]
} attrL;

(I very well imagine it can be optimized a lot when actually implementing it)

 

Every time you change an attribute:

- Look for a record in the list for the given panel/control

- If not existing, create one with the default attribute value

 

When you restore the attribute to the default:

- Read the default value from the list

- Delete the record afterwards

 

Not exactly a simple task, but I imagine you are not doing this ten times / sec on dozen of controls, aren't you? Smiley Wink



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 5 of 7
(2,590 Views)

I think that the best approach is to call another LoadPanel(), as suggested above.

Vix
-------------------------------------------
In claris non fit interpretatio

-------------------------------------------
Using LV from 7
Using LW/CVI from 6.0
0 Kudos
Message 6 of 7
(2,573 Views)

@vix  ha scritto:

This involves reading an uir file from disk to get the information, so I can't estimate the performance (especially with big uir files).

In order to minimize performance issues, the second panel instance could have the same lifespan as the operative one (i.e. be loaded and discarded together with it): normally the memory footprint of a panel is small and you'll have the "shadow panel" ready for access at any time.



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 7 of 7
(2,560 Views)