LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to create a subvi

you can always get rid of a stacked sequence.  😉

don't be shy... we'll help you complete your mission.. 🙂

Message 11 of 41
(2,958 Views)
Hi krispiekream,

this load of property nodes pops up because of your unneeded (and often criticized) use of local variables!
Don't use locals when not needed. Use wires and/or shift registers!

Your simple vi contains 4 local variables where only one is needed (at the moment, but can be removed by using a shift register in the main vi):
(missing some subvi/global variable...)
Converting this code into a subvi (by Edit->CreateSubVi) only creates one reference/property node. This will be completely avoided when using a shift register to create the "Pressure" array...

Instead of directly setting the global "lock..." you should use a subvi to do so. Include an error input and output to allow for dataflow programming and to get rid of sequences at all...


Message Edited by GerdW on 07-10-2008 09:32 AM

Message Edited by GerdW on 07-10-2008 09:34 AM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 12 of 41
(2,945 Views)
hi GerdW,
thanks for your help. your picture is very easy to understand. I remember why I send that helpwithsubvi.vi looking like that now.
its because throughout my code, there are a couple of times this tasks was performed.
the terminal is not available at times throuhgout the code.
local variables were used throughout the code when trying to do the same tasks.
but going with your instruction. i made this.
i am afraid that the True LOCK_PRESS_READ will perform before the while loop in the first frame.
but can you look at it and tell me if i followed your instructions.
thanks

Best regards,
Krispiekream
0 Kudos
Message 13 of 41
(2,920 Views)
hi joelabview.
here is where else it is used and how it was used throughout the codes.
i think its easier to make AN EXTRA LOCAL VARIABLES rather than creating a while loop, then add a shift register .
what do you think?



Message Edited by krispiekream on 07-10-2008 12:47 PM
Best regards,
Krispiekream
0 Kudos
Message 14 of 41
(2,907 Views)
It looks as though you may already have a while loop. The line above the Read Pressure sequence looks like part of a while loop. If it is a loop, just add the shift register(s) to that loop.

I cannot think of a case where a local variable would be better than a shift register for passing around data. Moving data via wires on the diagram is the fastest possible way and it cannot generate a race condition. The local variable is much slower, may make extra copies of data, and updates the front panel, often needlessly.

Lynn
Message 15 of 41
(2,898 Views)
i still think creating a subvi would make my main diagram less complicated.
i made this.
but i dont quite understand the inputs and outputs Mikes81 was talkinga bout.
how would i make an input for Pressure and and output for Pressure



Message Edited by krispiekream on 07-10-2008 01:29 PM
Best regards,
Krispiekream
0 Kudos
Message 16 of 41
(2,891 Views)
drop a numeric control on your front panel, change it to double (under representation), then right click on the icon in the top right corner of the front panel, and select "show connector."  click on one of the connector boxes (after you do, your cursor will turn into a spool of wire) and click on your control.
 
now, when you put the subvi on the block diagram, you can wire to that box as an input.
 


Message Edited by JeffOverton on 07-10-2008 03:00 PM
Download All
Message 17 of 41
(2,871 Views)
Your diagram can be further simplified by making use of semaphores. I am guessing that the lock_press_read global is being used to prevent another part of the program from gaining access to the Pressure commport. The Semaphore VIs from the Synchronization palette are specifically designed for that function. Here is a screenshot of the diagram with the semaphore functions replacing the global. Note that using the error clusters for dataflow eliminates the need for the sequence structure.

Another point: Connecting a DBL to the selector input of a case structure is generally not a good idea. If the value coming from the subVI is even slightly different from zero, the other case will never execute. If the value is obtained by some type of numerical calculation, the finite binary representation may differ in one or a few bits from zero. There have been many threads about this topic on the Forum.

Lynn
Message 18 of 41
(2,863 Views)
thank you everyone. considering the advices i was given, i made this.
its code is simplier than what i initially started. i like this subvi method more than the one where you drag over the items and let labview create subvi automatically. i think its harder to edit in 6 months from now.
let me know if anyone have any more advice to take out the last stack sequences from the images below.



Message Edited by krispiekream on 07-10-2008 03:33 PM
Best regards,
Krispiekream
Download All
0 Kudos
Message 19 of 41
(2,844 Views)
Very nice.  Much improved!  In this situation, I think you can eliminate your outer while loop since it only runs once with the true constant wired to the stop terminal.  You won't need the shift registers because the get initialized on every call by way of the terminals wired in.
 
A single run while loop with uninitialized shift registers is a characteristic of a functional global variable, LV2 style global, or action engine.  With these, the shift registers are uninitialized.  There will be a case structure called initialize, (or set value, or something like that) which takes inputs and feeds them to the shift register where the values are stored for later calls of the subVI.
 
You can also move the multiplication all the way inside to the false case since that is the only location where they are used.  You can also use the compound arithmetic function set to multiply to do the math in 1 step rather than 2.  Not that you need to, just so you know that the other function exists.  Compound arithmetic is especially useful for multiple OR or AND functions.


Message Edited by Ravens Fan on 07-10-2008 04:59 PM
Message 20 of 41
(2,829 Views)