LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Object Oriented programming not sure how it works

Solved!
Go to solution

In my previous doubts I have spoken about taking various measurements. With your help I was able to do it and I thank everyone who helped me. But my new problem is with object oriented programming. I am trying to do object oriented programming, but now it just looks like a project with many VIs. So as  mentioned one of my VI collect different measurements from a board and show it as a GUI. This data are temperature readings and the board is a thermo board and I have created a class for this called Thermoboard.lvclass and the VI that gets temperature readings is called Write Temp.vi and this vi is within the class. Now in the class as usual there is a cluster of private data and in this private data I put in an array indicator called temp. Now I put unbundle this cluster in my write temp vi and store the temp readings into the temp array in the cluster of the class. Then I created a VI for data member access for the temp data and created the read Vi for temp. But when I run that new VI for reading temp nothing happens. I thought all the data will be stored in Temp and by using data member access vi I will be able to access the data. But i am wrong. So my understanding of object oriented programming is wrong. Can anyone guide me or point to any material that can help me understand my mistake. Thanking you in advance. 

0 Kudos
Message 1 of 20
(3,330 Views)
Solution
Accepted by topic author govindsankar

@govindsankar wrote:

In my previous doubts I have spoken about taking various measurements. With your help I was able to do it and I thank everyone who helped me. 


Some references would be helpful, although we can do without.

 


@govindsankar wrote:

But my new problem is with object oriented programming. I am trying to do object oriented programming, but now it just looks like a project with many VIs. 


Many VIs is no problem. Tons of simple VIs are preferred over tons/10 VIs that are complex.

 

In OOP, you'll often end up making a VI that does almost nothing. That is only odd when you start. You'll get used to it, and when done properly, you'll grow to appreciate it.

 


@govindsankar wrote:

So as  mentioned one of my VI collect different measurements from a board and show it as a GUI. This data are temperature readings and the board is a thermo board and I have created a class for this called Thermoboard.lvclass and the VI that gets temperature readings is called Write Temp.vi and this vi is within the class. 


Nothing too obvious wrong here... A UML diagram would help (both you and us).

 

It's not rare to spend 25-40% of a project's time on analysis and design of the program. You'll get that time back though the power of OO (after getting experienced of course).

 


@govindsankar wrote:

Now in the class as usual there is a cluster of private data and in this private data I put in an array indicator called temp. Now I put unbundle this cluster in my write temp vi and store the temp readings into the temp array in the cluster of the class. Then I created a VI for data member access for the temp data and created the read Vi for temp. But when I run that new VI for reading temp nothing happens. I thought all the data will be stored in Temp and by using data member access vi I will be able to access the data. 


Did you put the object in a shift register? Even though you're using OO now, everything still works by wire.

 

Put some probes before and after the VI. Check if the VI works as expected. If it does, use object highlight to see what happens to the object.

 

Post some code for better guesses of the problem. It's not easy to give advice given just the executive summary.

 


@govindsankar wrote:

But i am wrong. So my understanding of object oriented programming is wrong. Can anyone guide me or point to any material that can help me understand my mistake. Thanking you in advance. 


Again, hard to advice anything except the usual (free) online courses.

 

I don't know if you're 100% of or just 5%.

 

Post some code...

0 Kudos
Message 2 of 20
(3,315 Views)

Everything works fine. Inside the write temp vi, I am able to get accurate 32 readings from the thermo board. Then as said i have wired from the shift register into the private cluster data called temp but I am not able to access that temp in another data member access vi. I am only able to access temp in the main write temp vi. Its a huge project so i cannot upload everything, but I have uploaded some pics and a vi which is simply the read temp vi which is the data member access vi which i am trying to make it work. Thanking you.

0 Kudos
Message 3 of 20
(3,303 Views)

Are you connecting the output class of your write temp vi to the input of your read temp? As Wiebe mentioned, classes are by value, so unless you connect the class instance returned by the write temp VI to the read method, you will not get the data.

0 Kudos
Message 4 of 20
(3,278 Views)

I haven't looked at your code.  But my magic 8-Ball is fairly good. 

 

Replacing a fgv with a class would usually be done by a DVR data value reference.

 

My clue here is that you have a vi called Write Temperature. Vi.  To me that action sounds illocigal.   Like, Change pi.vi

 

Set temp setpoint, read temp, get temp(last), get temp with history..  those sound like class members. Write temp sounds like you are trying to break the measurement source from the data accessor.  Nothing good would happen here.  Read temp should write the private data property intrinsically. 


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 20
(3,269 Views)

Read Temp.png

 

 

Iam sorry i didnt understand that line - the output class of your write temp vi to the input of your read temp. This is what I have done and also the value from the shift register goes into the private data temp which then goes into the thermo board out. In the read temp thermo board in is connected to a unbundle so that i can access temp. But I am not getting anything. The below photo shows the value coming in to the themo board out from the shift register.oop doubt.png

0 Kudos
Message 6 of 20
(3,232 Views)
Solution
Accepted by topic author govindsankar

You're focusing (and showing us) details. The bigger picture might be the problem. (You're showing use big pictures, but that's not what I mean Smiley Wink.)

 

Show us where you call Write Temp2.vi and Read Temp.vi, that's probably where the problem is.

 

When Write Temp2.vi is done, is the Read Temp.vi connected directly to Write Temp2.vi? Use probes to see if the data is there when it exits Write Temp2.vi, and when it enters Read Temp.vi. My guess is they are not connected, and you might be assuming the data written in Write Temp2.vi automatically ends up in Read Temp.vi, even if the class wires are not connected. As if they are working by reference. They're not by reference, those objects are still working by wire, like any normal data type in LabVIEW.

 

But that's all assumption...

0 Kudos
Message 7 of 20
(3,217 Views)

Yes I wired read temp to the end of write temp and it works. Now my doubt is this then what is the use of object oriented programming. If write temp and read temp were normal vis under a project without object oriented programming, wouldn't the same thing happen. 

0 Kudos
Message 8 of 20
(3,207 Views)
Solution
Accepted by topic author govindsankar

@govindsankar wrote:

Yes I wired read temp to the end of write temp and it works. Now my doubt is this then what is the use of object oriented programming. If write temp and read temp were normal vis under a project without object oriented programming, wouldn't the same thing happen. 


Yes, VIs function\work the same. Class methods are VIs.

 

You've only been sniffing one of the pillars of OO, encapsulation . Even now, you can benefit from that. If you made normal VIs, that data would probably end up in a cluster. That cluster would be accessible for reading and writing by everyone and everywhere. If you abuse this capability, you're code will become tightly coupled. As that data is private (a restriction), you are forcing yourself to keep your code less coupled, which is a good thing.

 

The real power of OO comes when you start to use inheritance and polymorphism. Inheritance would be useful for instance when you have more then one temperature inputs. Classical, a parent ITemp, and two children: a physical input, and a simulation. Then you can develop the entire program using the simulation, and if the physical devise works according the contract (class API), your entire application should work.

 

You can also think about OO\polymorphism like this:

The class wire doesn't only transfer data, it also 'transfers' behavior. That means that a class wire can be the input of a VI, and from the outside of that VI, you can specify how the inside of the VI behaves. For instance, a Measurement.vi will call the Measure method of a Device class. The measurement.vi doesn't care about the specific device. The specific device can be specified from outside measurement.vi, by selecting one of Device's children. Or even more then one when a composite child is made.

 

It's hard to appreciate OO at first. It might seem mostly as 'more restrictive and difficult', without seeing any benefit. Those benefits are huge, but you have to grow into it.

 

BTW. There are plug-ins (G#, OpenGDS), that let you create by reference classes. I don't use them, and wouldn't recommend them. Others love them, and don't seem to be able to do without. Suit yourself. At least at fist, I think by reference will complicate things a lot. 

Message 9 of 20
(3,187 Views)

Thank You very much for your help. Now I know that i know nothing about object oriented programming, just how to create a class and a member vi inside. I also know how to set inheritance, but I am not well aware of its benefits. Well the thing is I am currently doing my master thesis and I have done two projects before this as 2 internships. My first was in simple state machine design and second I used producer consumer loop. So here I thought I will use OOP. My boss doesnt matter how I do it, all he wants is the output. But I want to learn OOP using this project and also the other thing is I have done some applications for a job after my master thesis where in the application I stated I am doing LabVIEW object oriented programming. So in the event I get an interview call, I guess I am not sure whether I will be able to answer LabVIEW OOP questions. I need some good online tutorials on LabVIEW OOP. If u have know some links kindly provide me with them. Thanking You. 

Message 10 of 20
(3,173 Views)