09-25-2017 12:36 PM
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!
Solved! Go to Solution.
09-25-2017 01:32 PM
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.
09-25-2017 01:33 PM
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.
09-25-2017 02:23 PM
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.
09-25-2017 02:39 PM - edited 09-25-2017 02:44 PM
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.
get
set
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.
09-25-2017 02:49 PM - edited 09-25-2017 02:50 PM
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..." ![]()
Unfortunately this attitude has led me to be a complete noob at Labview OOP.
09-25-2017 03:12 PM - edited 09-25-2017 03:13 PM
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.
09-25-2017 06:25 PM - edited 09-25-2017 06:29 PM
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.
09-26-2017 05:15 AM
Instead of the Oven State Controls[] property you'll need to create a function in your class that looks something like this:
/Y
09-26-2017 09:13 AM
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)