LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Object Oriented programming not sure how it works

Solved!
Go to solution

Not sure if I could find OO LabVIEW tutorials, if they are there. I used a lot of C++ OO tutorials, long before it was possible in LabVIEW, so I never did any LabVIEW OO tutorials.

 

There is of course the (online) NI OO course, but I don't think it's free. You\your university might have a subscription though.

 

Just to mention, a state machine and producer consumer architecture doesn't rule out OO. OO works well in both. I'd go for a state pattern, the OO variant of a state machine, but there are no rules for that.

 

IMHO, you're better of focusing on OO Analysis and OO Design, not OO Programming.

 

Every OO program should be preceded by OOA and OOD. OOA and OOD are more general, as in not language specific. That means more resources, and better material. You'll learn the LabVIEW OO merits as you go.

 

I learned a lot from Booch's Object-Oriented-Analysis-Design-Applications. The 2nd edition is a few bucks, but it misses the part on UML.

Message 11 of 20
(1,293 Views)

As weibe stated, concentrate on learning OO concepts.  Then you can figure out how to do that in LabVIEW.  In other words, learn WHY before you learn HOW.  So on that note, I very highly recommend reading The Object-Oriented Thought Process.


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
Message 12 of 20
(1,289 Views)

@crossrulz wrote:

I very highly recommend reading The Object-Oriented Thought Process.


Yes, also very good.

0 Kudos
Message 13 of 20
(1,280 Views)

I know Object Oriented Programming in C++. So I think I know the concepts. Thats where my problem comes, in C++, I create a private data it is accessible through objects and a method that lets you access the data. I try this in LabVIEW where I create a private data which is inside the cluster of the class and I try to access that using subVIs nothing is happening. Also I know inheritance and polymorphism in C++. But I will never use C++ because I dont want to be a C++ programmer. I want to be a LabVIEW programmer. So I am trying to learn Object Oriented Programming in LabVIEW and MATLAB for my career. But I have a long way to go before I start OOP in MATLAB. But I need to get good in LabVIEW OOP now atleast the basics, command pattern and actor framework, they are just too complicated. The remaining basic stuff in LabVIEW OOP that is what I want to learn. How to access data using method VIs in OOP. This is my goal for now. If anyone could guide me the path to achieve this, it would be helpful. 

0 Kudos
Message 14 of 20
(1,271 Views)
Solution
Accepted by govindsankar

The OO concepts are the same in LabVIEW and C++. The biggest issue you are probably running into is that LabVIEW is a by-value language. If you branch a wire in LabVIEW you have effectively cloned the data. Updates on the two branches of the wire are not reflected on the other branches. You can work around this by using by-reference objects. As mentioned earlier your cluster of private data in the class definition would need to contain a Data Value Reference (DVR) to your data. A DVR is like a pointer in C. It simply points to the data. With a DVR you only have one copy of your data so updates will be seen by all branches of the wire. Of course, you can run into race conditions with operations occurring in parallel.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 15 of 20
(1,261 Views)

@Mark_Yedinak wrote:

The OO concepts are the same in LabVIEW and C++. The biggest issue you are probably running into is that LabVIEW is a by-value language. If you branch a wire in LabVIEW you have effectively cloned the data. Updates on the two branches of the wire are not reflected on the other branches. You can work around this by using by-reference objects. As mentioned earlier your cluster of private data in the class definition would need to contain a Data Value Reference (DVR) to your data. A DVR is like a pointer in C. It simply points to the data. With a DVR you only have one copy of your data so updates will be seen by all branches of the wire. Of course, you can run into race conditions with operations occurring in parallel.


Which is exactly why you can use the Inplace Elements Structure with a mark to allow concurrent read access on later versions of LabVIEW. 

 


"Should be" isn't "Is" -Jay
0 Kudos
Message 16 of 20
(1,250 Views)
Solution
Accepted by govindsankar

@govindsankar wrote:

I know Object Oriented Programming in C++. So I think I know the concepts. Thats where my problem comes, in C++, I create a private data it is accessible through objects and a method that lets you access the data. I try this in LabVIEW where I create a private data which is inside the cluster of the class and I try to access that using subVIs nothing is happening. Also I know inheritance and polymorphism in C++. But I will never use C++ because I dont want to be a C++ programmer.


In C++ (I'm no expert), it works exactly the same as in LabVIEW. In C++ when you pass a calss by it's value to a function, a 2nd function will not get the update unless it's passed through the return value. But since C++ only allows one return value, often objects are passed by reference. That sill doesn't work well in parallelly executed parts (threads) as the objects are not automatically suited for asynchronous access.

 

IIRC, the new C++11\14 standard has much better options for specifying the exact behavior or passing values, with the event of L-Values. There are now L vaues, R values, values, pointers and references. I thing at the moment libraries are recommended to not use by reference objects anymore, allowing more compiler optimizations. But I could be wrong.

 


@govindsankar wrote:

I want to be a LabVIEW programmer.


Good choice. I think LabVIEW OO might actually be harder coming from a C++ background. 

 

You're current problem isn't something I'd recommend for a beginner. It is typically something beginners run into though.

 


@govindsankar wrote:

So I am trying to learn Object Oriented Programming in LabVIEW and MATLAB for my career. But I have a long way to go before I start OOP in MATLAB. But I need to get good in LabVIEW OOP now atleast the basics, command pattern and actor framework, they are just too complicated.


Command patterns aren't that complicated. Most patterns are really simple. You'll probably use only two or three. Different reasons for using inheritance or containment are sometimes even labeled as separate patterns. Some are so basic, you'll either use them without knowing, or learn about them and use them (or both in random order).

 

The actor framework is build on the actor pattern. I agree that it's complicated. Let's not go there.

 


@govindsankar wrote:

The remaining basic stuff in LabVIEW OOP that is what I want to learn. How to access data using method VIs in OOP. This is my goal for now. 


If you write private data in method A, you will be able to read it in method B. As long as method B acts on the same object. As soon as you split the wire, you get two objects. OO isn't different then any other object. Even splitting a reference will get you two references, but they point to the same data. 

 

The problem you're facing is this isn't really related to OO. If this data was a cluster, or a number, string, array, or whatever, you'd have the same problem. You though OO would fix this, it doesn't. It could help though, as you have more options with OO. You can make a class, and make a singleton child. Or make a DVR-ed child. Or put the object in a global\FGV\private global. Or put the private data in a DVR. These solutions are not related to OO per se. They are the solutions that solve asynchronous data access in general.

 


@govindsankar wrote:

If anyone could guide me the path to achieve this, it would be helpful. 


We gave quite a few pointer. I'd go for passing the objects in a queue, event or channel wire.

 

I think besides OO, there might be some things you'll learn from this: labview-basics.

 

If you (or your company\uni) has a SSP: self-paced-training

 

And of course (not free): Object-Oriented Design and Programming in LabVIEW

 

Message 17 of 20
(1,231 Views)

I've used OO in LabVIEW since 1998, and it started off as by reference, but it was an add-on to LV.

When LV 8.2 came out, it got native support by only By-value OO support.

So we had to add by-reference support on-top of the native OO.

Many people are using OpenGDS for this: http://opengds.github.io/

It makes it easier to go from other OO languages into LabVIEW since it by reference as text based languages uses.

The OpenGDS is a tool that helps you create classes in LV. It can create By value and By reference classes.

There are some training videos and other info here:

https://forums.ni.com/t5/GDS-Goop-Development-Suite/gp-p/5050

 

Videos:

http://www.youtube.com/watch?v=UcUj_Gl1JdI

https://www.youtube.com/watch?v=hdcHYS_ZFr8

http://www.youtube.com/watch?v=_BvIiU2VMAU

http://www.youtube.com/watch?v=ZWeO_wPe-VQ

http://www.youtube.com/watch?v=OunqB9UdR6o

http://www.youtube.com/watch?v=VncaD_pKe_s

http://www.youtube.com/watch?v=i77lHDIMs_s

Message 18 of 20
(1,207 Views)

@MikaelH wrote:

It makes it easier to go from other OO languages into LabVIEW since it by reference as text based languages uses.


No, most text based languages do not use by reference objects.

 

In C++ for instance, objects are not by reference.

 

C++ Objects are often passed by reference, but that doesn't make the objects by reference. In LabVIEW, you can make an object, and pass it by reference (e.g. a DVR). That doesn't make the object a by reference object.

 

C++ and LabVIEW objects are the same. It's just that passing objects by reference in C++ is facilitated in a more native way. You can simply decide when you call a function if you pass by value or by reference as a feature of the language. In LabVIEW, you can do that too, but it's less convenient.

 

Java does pass objects by reference as only option. So in Java, it makes more sense to say objects are by reference (although strictly speaking they are really just passed by reference). Pretty sure in most other text languages objects are not by reference.

Message 19 of 20
(1,197 Views)

And this is why I personally like LabVIEW.. Pointers to pointers to references of the data of an object.... Bull Doody!

 

The object is the wire. the data is there, DVRs also exist if you cannot deal with how LabVIEW did that memory management for you. Its abstracted away from the user because users make mistakes!


"Should be" isn't "Is" -Jay
0 Kudos
Message 20 of 20
(1,171 Views)