LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

reference in oop

Hi

 

I have built a class that shuld handle a schneider advantys modbus modules, but I have some trouble with the referene for the modbus vi's (NI Modbus Library).

I got a parrent clas and a lot of childs, one for each module.

 

 

top BD.PNG 

 

This is where I obtain a reference for TCP master .

new TCP master BD.PNG

 

Here I select the child:

Child selector BD.PNG

 

This is the child:

Child BD.PNG

And here is the error I got from the Modbus read vi:

Error.PNG

 

 

Is it not possible to carrie the modbus reference in the class?

 

regards Bjarne

0 Kudos
Message 1 of 10
(4,836 Views)

It looks like you are ontaining reference in New TCP master, but you never pass that reference to child object in the Child selector.

 

 

--
Marko H

OptoFidelity - Enabling Smarter Future

Tampere - Espoo - Oulu - Cupertino - Redmond - Zhuhai

0 Kudos
Message 2 of 10
(4,830 Views)

Yes, but why?
I thought that the reference should be on the class wire?

0 Kudos
Message 3 of 10
(4,812 Views)

When I started learning OOP few years ago, it took me a while to understand the difference between class and object.

You have the reference in Parent object,  then you ignore that and take (new) Child object. Which dosen't have that reference, because it was in the parent object. Data is not magically shared between objects.

--
Marko H

OptoFidelity - Enabling Smarter Future

Tampere - Espoo - Oulu - Cupertino - Redmond - Zhuhai

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

Should it not inherit it from the parrent?

I have tried this but with no luckSmiley Sad

selector.PNG

0 Kudos
Message 5 of 10
(4,791 Views)

There should only be 1 reference, right?  If that is the case, then you need to set it up once.  I think I would not have that reference in an object, but in a global variable that the other classes can access.


GCentral
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
0 Kudos
Message 6 of 10
(4,765 Views)
This might answer some questions for you:

http://www.notatamelion.com/2015/04/06/objectifying-labview/

The thing to remember is
object = wire
class = particular kind of wire

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 7 of 10
(4,735 Views)

@Briton wrote:

Should it not inherit it from the parrent?

I have tried this but with no luckSmiley Sad

selector.PNG


 

 

 

You're still accessing the parent's data in this case. In that case structure I assume you have multiple cases with multiple objects. If you use that (try to merge different classes into one wire, either through a case structure, build array, or similar) the wire automatically gets converted up the hierarchy into the parent class. This is difficult to see so what I find helpful is:

-Hover over each segment of the wire with context help up -- this will show you where the wire changes from Child.lvclass to Parent.lvclass.

-Change the color of each class' wire (in class properties, from the project window). This makes your code look nicer and will help you see where classes change.

 

So anyway, labview is changing the wire type on you and so you're pulling parent.instance out and then writing back to parent.instance NOT child.instance.

 

Thats another important point. In LabVIEW as in other object oriented languages, children inherit the data of their parent. So by having parent.instance you automatically have child.instance without adding any data to your class (you can see this in context help). The thing that I think people get confused about and really makes classes in labview kind of a pain is that parent data is by default not accessible to children. So that child wire has a modbus instance in it, and that one is the one you want, but you aren't allowed to get at it. To get around this, you need to make an accessor method for your parent class which gives the child class access to the modbus instance. In this case (and 90% of other cases), I'd recommend just read accessors. If you aren't familiar with this, the help can walk you through it:

http://zone.ni.com/reference/en-XX/help/371361K-01/lvhowto/creating_mem_vis/#member_access

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

Thanks everybody:)

 

I made to VI's (VI for data member access) one read and one write in the parrent class:

 

Read Parrent data.PNG

 

 

Write Parrent data.PNG

 

After that I made a "VI for override" in parrent and all child classes:

 

Data to child.PNG

 

That did the trickSmiley Wink 

 

Regards Bjarne

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

A cleaner OO solution would be to create the specific child instance you need before creating the connection, then call the connection method from the parent class on the child class's wire.

0 Kudos
Message 10 of 10
(3,932 Views)