LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I'm still unsure how custom controls and object oriented programming interact, can anyone please enlighten me?

Solved!
Go to solution

I spent quite some time trying to figure out the relation between custom controls and object oriented programming. However, it still isn't quite clear to me. 

 

What I want to do:

I want to have a custom control, and hide it's inner workings from the rest of the blockdiagram, so I don't have to wire for every similar object. Not only because I'm lazy :smileywink:, but also to keep the diagram clean and prevent errors.

 

for instance a graph, a numeric factor and a button. 

when the button is pressed the x scale should be changed depending on the factor.

 

So, this looks like a job for object oriented programming to me. Once I've created something that can do this, I can use it throughout my program. The code that redraws the figure when the button is pressed should be part of the object, so I don't have to connect extra wires and add a value change event when I add a new graph. 

 

Is this possible at all? I tried, but haven't quite figured this out yet. I have to admit I'm pretty new to OO programming and making custom controls. I've been using typedef'ed clusters for most my code so far, which works fine. But it's still a stupid cluster, the only way to have it do anything at all is from the block diagram in the VI you use it in.

 

The only thing I could come up with so far is add an "event handler" SubVI that does this, and have it accept a reference or local variable to an object. Then, this SubVI and the variable or reference can be put in parallel with the other stuff in the main program loop. But surely there's a better way somewhere? 

 

I don't think I can solve this problem of defining custom front panel objects and methods for it to interact with the objects it represents without help. I keep getting the feeling I must have missed it somewhere. Any pointers will be appreciated.

 

Thanks!

Jacco.

0 Kudos
Message 1 of 6
(3,801 Views)

Hi Jacco,

 

LVOOP provides functions for encapsulating data and providing public and private methods for accessing the encapsulated data.  I don't think LVOOP is what you are looking for.

 

Search the LV examples for "XControl". There is a built-in example which is a thermometer that will display in either C or F degrees. The conversion code is built into the XControl.

 

So take a look at that example.

 

Just trying to help,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 6
(3,799 Views)
Solution
Accepted by Jacco K

Jacco K wrote:

What I want to do:

I want to have a custom control, and hide it's inner workings from the rest of the blockdiagram, so I don't have to wire for every similar object. Not only because I'm lazy :smileywink:, but also to keep the diagram clean and prevent errors.

...  

The only thing I could come up with so far is add an "event handler" SubVI that does this, and have it accept a reference or local variable to an object. Then, this SubVI and the variable or reference can be put in parallel with the other stuff in the main program loop. But surely there's a better way somewhere? 

 

Thanks!

Jacco.


Hi Jacco,

 

These two things are exactly what Xcontrols are, a basic VI with a front panel that has an event structure (the facade VI).

If you have any questions I am happy to guide you.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 3 of 6
(3,784 Views)

TonP wrote:
...

If you have any questions I am happy to guide you.

 

Ton


We really need a "Mega-Kudos" button for posts like that!

 

Ben

Message Edited by Ben on 01-12-2009 10:19 AM
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 4 of 6
(3,775 Views)

Thanks you guys, the Xcontrol seems to be exactly what I need.

 

I tried marking both your posts as solutions, but I suppose it's like Highlander: "There can be only one"

0 Kudos
Message 5 of 6
(3,731 Views)

I know this has already been solved, but I think this is a good addition to the topic, for anyone else that may fall in here:

 

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

 

Though in my case it became more work because then I needed to do all those special "bundle" and "unbundle" VIs for the private data.

0 Kudos
Message 6 of 6
(3,334 Views)