LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

create a sub block

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

0 Kudos
Message 1 of 6
(2,711 Views)

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.

Tim
GHSP
0 Kudos
Message 2 of 6
(2,697 Views)

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.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 3 of 6
(2,682 Views)

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!

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 4 of 6
(2,673 Views)

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.

 

0 Kudos
Message 5 of 6
(2,664 Views)

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.


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
0 Kudos
Message 6 of 6
(2,657 Views)