LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using subVI as control?

Solved!
Go to solution

Hello all,

 

I am trying to create a custom two-boolean control where one is "SAVE?" and the other is "DISPLAY?" The two buttons need to be bound by the simple logic that if DISPLAY is off, turning SAVE on turns on DISPLAY as well, and if SAVE is on, turning off DISPLAY turns off save as well.

I have sucessfully implemented the logic in a subVI already. Is there anyway I can use this subVI as part of my main VI's control without having to make an xcontrol? I spent a few hours looking at xcontrol and still have a poor grasp of how to make one. Can I get some general pointers as to how I can "port" this code that I already have to work in xcontrol?

 

I need 16 of these controls on the main panel and hence to have to repeat the code 16 times in the main BD would not be ideal.

 

Thanks for your help.

0 Kudos
Message 1 of 15
(3,537 Views)

Just use a radiobutton control. No code needed.

 

Sorry, I misuderstood. But please use shift registers instead of all these unneeded local variables! Also keep the labels. Your event structure is unreadable if the controls don't have labels. You can hide the label on the front panel.

 

0 Kudos
Message 2 of 15
(3,534 Views)

Thanks for the reply.

Unfortunately, the radio button doesn't do exactly what I need the control to do. For instance, it's impossible for both options to be ON at the same time for radio button. If you would be kind enough to open up the VI, it has the behaviour that I want implemented.

0 Kudos
Message 3 of 15
(3,528 Views)

Understood. I still don't know how I can use this subVI code in the main VI though. The buttons don't appear on the main control panel.

 

Thanks!

0 Kudos
Message 4 of 15
(3,527 Views)

Well, you cannot write to a control on the main panel from within a subVI directly, so you could add a subVI input for references to the controls and modify them via value property nodes.

Message 5 of 15
(3,511 Views)
Solution
Accepted by topic author RaymondLo

Hi,

 

I cleaned up your VI for you (attached) and put control references in so you can use it as a subVI, as altenbach suggested. I also replaced the controls you were using to store the previous values with shift registers. This is a better way to do it, so you should use this as an example for how to do things in the future. In this case, since this is a subVI, I left the shift registers uninitialized so it will work as a functional global variable (you can look this up to learn more about it - basically it will store those previous values from one run of the VI to the next). I set the VI to have pre-allocated clone reentrant execution, this means basically a separate instance of it will be run for each time the subVI appears on the block diagram so that it will store separate values for each pair of save/display controls you have (if this doesn't make sense, try looking up more about reentrant execution). 

 

Also, you should think about what you want the initial values of the previous display and previous save to be. Right now they are just false by default, but I don't know if that's what it should be for your logic to work right.  Actually, you might want to re-think your boolean logic overall. Perhaps I am overlooking some complexity that you are accounting for, but it seems like you shouldn't need to do that much logic. In fact, I'm not sure why you even need to store the previous values. You might want to consider just comparing the current values to each other, as it would greatly simplify, and then the VI would not need to be a functional global and you wouldn't have to worry about the reentrancy or anything. Just a thought.

 

--Hope

Message 6 of 15
(3,479 Views)

Wow, thanks. I will look into global variables. So I suppose the idea is to use the subVI as the "logic" to control the buttons on the top level? I hope I am understanding this correctly.

 

I do think this level of logic is needed because when I reasoned through it, it seemed like the transition (F->T or T -> F) matters as well, and not just the states.

Anyway, I appreciated both of your help. Do I have the permission to use some of this code for a BME Lab at research university?

0 Kudos
Message 7 of 15
(3,451 Views)

@RaymondLo wrote:

Wow, thanks. I will look into global variables.


He was talking about "functional globals", quite different to plain global variables. Make sure you know the difference. Also have a look at action engines.

 

You can handle all possible state transitions by creating an array with four elements (the current boolean values and their previous value from a feedback node), converting it to a number (boolean array to number) and wiring the number to a case structure. Leave the default case empty and create two cases that represent the transition where the value of the other control needs to be changed.

Message 8 of 15
(3,421 Views)
Solution
Accepted by topic author RaymondLo

This is my first attempt at XControl but it seems to be working sames as your code. 

 

Sorry for the 7-zip format.  I couldn't get a standard zip file to upload.  Something about the MIME type not matching the extension. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 9 of 15
(3,405 Views)

Oh, yeah I re-read your initial post and now I see why you need the previous values as well - of course you do, because you have to tell if it was changed. Still, you can simplify the logic, altenbach's suggestion for that seems really good.

 

And yeah, it's a functional global not a global variable. Actually, since it doesn't have specific read/write operations, "action engine" is probably the more appropriate term.

 

You can use the code, of course. I wouldn't post it publicly if not 🙂

Message 10 of 15
(3,391 Views)