LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Iterate Over class object controls

Solved!
Go to solution

If I have a cluster I can obtain a array reference that allows me to iterate over its controls.  If I have a LV class however, I don't seem to be able to do this.  Is it not possible, or am I missing a step? 

 

Thanks!

 

LV_ref.png

0 Kudos
Message 1 of 14
(5,679 Views)

I don't see a way to do that but at the same time, I don't see why you would need to do this.  Can you clarify what you are trying to do?  Maybe there is a different approach to solve your problem. 

 

I'm a total noob when it comes to Labview classes but in my mind, class data is just that....data.  There aren't technically any controls to speak of, in the sense of a front panel control that you can change properties, hide/show, etc.  They are only there to define the datatype.  Use a Unbundle Cluster (In Place Element structure) if you want to view/modify the data.

aputman
0 Kudos
Message 2 of 14
(5,648 Views)

Actually I am pleased you can't do this. Don't forget that one of the key ideas of the implementation of OOP in LabVIEW is that the classes data is private and can only be exposed through a method (or a property wrapper over a method).

 

If you want to access the classes private data then you need to expose it via a method in the class.

0 Kudos
Message 3 of 14
(5,645 Views)

And let's not forget the mess that would come out due to Dynamic Dispatch.  Should that property return only what is in the defined class, the passed class, or the passed class with any parent's class data.  Like I said, a big mess would ensue.

 

As already said, use a method to pass the data you want out.  Even then, it is bad OOP practice to let outside processes alter your data.  That is the point of the methods: to allow access to updating and/or acting on the private data.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 14
(5,624 Views)

This class (formerly a custom control/typedef) reflects the state of an attached piece of hardware.  To update the LV representation of the hardware state I iterate over the custom control cluster.  The text label is used to generate a VISA (serial in this case) query.  The return value of the query is used to update the values in the control. Conversely the same scheme can be used to set the hardware state based on the control. See below for an block diagram. 

 

    getget

 

 

 

setset

This is nice because all I need to do to add an additional piece of state is update the translator VI. The only VI that needs to be updated is the 'CTRL to SPCI' in that case.

 

Open to suggestions for improvement. Thanks all.

 

 

0 Kudos
Message 5 of 14
(5,617 Views)

Why do you want to change it to OOP?  If what you are currently using is working well, I'd say stick with what is currently working.  The old adage comes to mind "if it ain't broke..."  Smiley Wink

 

Unfortunately this attitude has led me to be a complete noob at Labview OOP.

aputman
0 Kudos
Message 6 of 14
(5,607 Views)

If you really want to convert this to OOP (and there is not that much incentive in this instance) then each of your cluster items could be in your class private data; you then create a property for each which allows you to use one (albeit stacked) property node write in your client calling code to write to all the properties at once or alternatively read them all at once.

 

However I would suggest that a class doesn't really help you here the way you are trying to implement this. You are after a data-only class that doesn't really have any methods. This is what clusters and typdefs are designed to help you do. If you ever want to add real functionality to the data you are protecting (perhaps a method that generates the VISA query as a string for the caller so it doesn't need to know how) or add dynamic dispatch (if you have more than one implementation) then implementing a class for this offers more tangible gains.

0 Kudos
Message 7 of 14
(5,598 Views)

Thanks for the feedback everyone. Suffice it to say there are some sound reasons for wanting to convert this. The scope extends beyond the snippets presented.

 

It seems as if there may be no analog to the 'controls[]' property. unfortunate, but the problems crossrulez mentions make sense. 

0 Kudos
Message 8 of 14
(5,568 Views)

Instead of the Oven State Controls[] property you'll need to create a function in your class that looks something like this:

GetObjectItems.png

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 9 of 14
(5,541 Views)

Have you gotten this to work Yamaeda?  It can be wired as you instruct, but the outputs are always empty.  (I'm on LV2017 btw)

 

lv_followup.png

0 Kudos
Message 10 of 14
(5,526 Views)