06-06-2018 06:46 AM
Hi,
I'm new to labview and I'm wondering if it is possible to create a kind of sub block (not really a sub-vi).
I've created a timeout event which I use to initialize my project. A lot of values or other properties are set to there initial value. This takes up a lot of space in the block diagram.
I want to put all of these in a single block that I can call from the main block (like a function call in C) but if I use a sub-vi an input terminal is created for each property which isn't really what I want.
thanks
06-06-2018 07:25 AM
A sub vi is what you need. You can add all of your controls and indicators to a cluster and then it comes out of the sub vi as one wire. You can look at examples of how to use clusters. You can also look into action engines.
06-06-2018 07:49 AM
The answer is no. The quick&dirty workaround is using the highly deprecated Stacked Sequence structure (I will probably be rebuffed for giving you this suggestion). This involves enclosing your execution code in a Flat Sequence Structure, then right-click on its border and Replace with Stacked Sequence. Your code will be in frame #1. Finally, move your initialisation code to frame #0.
Another possibility is to use a state machine with at least 2 states, let's say Init and Exec. A state machine would be very useful if you ever need to manage a sequence of operations (each one would be run in one state - or maybe more than one depending on its complexity) with the possibility of stopping the sequence before finishing and handling errors in a single state.
06-06-2018 08:34 AM - edited 06-06-2018 08:36 AM
I think what you are describing here is a subVI, with 2 inputs, which can be called in multiple different modes (according to what you want to do) and depending on the mode the "input" changes. The function must store data in memory for later...
This can be accomplished by using a variant control as the input and an action engine (FGV that does stuff) with shift registers to store the data internally and an enum to select the cases. Wiring the error cluster though is a good idea.
James
Edit: It is worth noting that a SubVI size is defined by the Icon size you create, but the wires will go to the connector pane you define so don't leave wires hanging in space!
06-06-2018 08:49 AM
Hi,
The Vi is doing what it's supposed to do so I don't have a problem with the functionality (not yet).
I only want to reduce the screen size of the block diagram to make some space.
I looked at clusters as proposed above but I doubt if that would be a solution. Creating a cluster of 30+ items would also take up a lot of space.
I've attached a screenshot and all I want to do is put the items in the red rectangle in a "sub block" that I could reuse inside the same VI.
06-06-2018 09:23 AM
Please stop using the Value property node. I would rather you use a Local Variable. You still have the same issues as the local variable (race conditions), but made things 1000s of times slower (not exaggerating at all there, last benchmark I did put it in the 2000-3000 times slower) since you are forcing front panel redraws and thread swapping to the UI thread. Even better than the Local Variable is to use the actual terminal (looking at your serial port initialization here) and/or Shift Registers.
What you are describing is exactly what a subVI is. You call other VIs from a VI! Where you will run into issues is the fact that you are setting UI values. So you will need some way to package all of those control references into a cluster and/or arrays and pass those into the subVI to then set all of the values.