LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Understanding access (read/write) of a class control data (private)

Hi,

 

I'm new in LVOOP. I'm trying to understand a few concepts to change a code from using a lot of references and clusters to classes.

Please see attached picture for reference. I put everything in one pic.

 

My question is basic... I'm using the "VI from dynamic dispatch template" (Untitled 7) to read and write data from/to the main class control (Test.ctl) which includes a Ring and a Numeric control. I'm able to read the information from the Test.ctl, but not to write new values on it.

 

What is the correct way to overwrite the values on the main class control Test.ctl? This is private data, so I'm not sure if this can be overridden, and if not,

What is the main purpose of creating a write accessor?

 

Thanks,

0 Kudos
Message 1 of 3
(2,740 Views)

The code you show in the image works probably as you expect it to - the current values are displayed in the indicators and then the values from the controls are written into the class data.

 

I suspect the problem comes from your watching the private data (test.ctl). That's the default value you see - not the value of any particular object.

 

This is a crucial concept with LabVIEW OOP (and OOP in other languages more generally). When you write your class (.lvclass, the files in that class (ctl, vi, etc)) you are effectively writing a template for objects of that class. The wires on a block diagram can be of a class type - they carry objects of that class. However, when you write the values into an object, you don't change the template - you change the object.

 

Each time you drop a block diagram constant for a class, you create a new copy of it (a new object is instantiated) with the default values (as you see in the .ctl private data - you can modify these the same way you change a VI's default values: change the value in the control; select the control; choose Edit > Make Current Values Default).

 

The training available at the top of the forum has more detail about this, but feel free to ask more questions 🙂


GCentral
0 Kudos
Message 2 of 3
(2,680 Views)

Attached is a very simple example saved in LabVIEW 2015.

Hopefully this will show how an object can be retained using a Shift Register, or created anew with a Constant each time.

Example_VI.png

Class SubVI block diagramClass SubVI block diagram


GCentral
Message 3 of 3
(2,673 Views)