LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

creating sub-VI with local variable inside?

can this be done?

basically I would like to convert a decimal number into it's 8 bit
binary equivalence and display it with 8 LED's. When the VI is run, the
decimal number changes and I would like to synchronize the chagne with
the LED. So I have a set of LEDs and I created local variables for
them. But when I created a sub-VI for this funtion, I can't seem to
include local variables in the sub-VI, this is just a matter of rule of
Labview?

Thanks,
Steven
0 Kudos
Message 1 of 11
(8,179 Views)
By definition (in any programming language) local variables are local to a
function i.e. a VI. You have to use global variables to communicate between
VIs.

_Steven Chang wrote:
>can this be done?>>basically I would like to convert a decimal number into
it's 8 bit>binary equivalence and display it with 8 LED's. When the VI is
run, the>decimal number changes and I would like to synchronize the chagne
with>the LED. So I have a set of LEDs and I created local variables for>them.
But when I created a sub-VI for this funtion, I can't seem to>include local
variables in the sub-VI, this is just a matter of rule of>Labview?>>Thanks,>Steven>
0 Kudos
Message 2 of 11
(8,178 Views)
[posted and mailed]

scc@ucla.edu (_Steven Chang) wrote in <39E1FFCD.54DD8DF@ucla.edu>:

>can this be done?
>
>basically I would like to convert a decimal number into it's 8 bit
>binary equivalence and display it with 8 LED's. When the VI is run, the
>decimal number changes and I would like to synchronize the chagne with
>the LED. So I have a set of LEDs and I created local variables for
>them. But when I created a sub-VI for this funtion, I can't seem to
>include local variables in the sub-VI, this is just a matter of rule of
>Labview?


No, you can use locals within a subvi. It depends on what you are trying to
achieve. Why use locals? You can just make your binary LED's as indicators
and set them by wiring the output from your conversion from the decimal
number.

L
ocals should really only to be used in very unique situations eg, to
update controls or to pass data from one loop to another.

The major disadvantage of locals is that they force the VI to remain in
memory and therefore are computationally more intensive (in this sense).
Another disadvantage is that they can lead to race conditions where the
update and reading from the control are not synchronized in any
deterministic fashion and this leads to bugs in your running code. You can
almost write local "free" code, because you can be clever about your data
passing and you can throw and catch data between loops using queues.


--

Alexander C. Le Dain, PhD
ICON Technologies Pty Ltd
http://www.icon-tech.com.au
0 Kudos
Message 3 of 11
(8,178 Views)
Hi,

Yes you can send the value of the variable local to the sub-vi. To do this,
you have just to define an input parameter for the sub-vi and connect the
value of the vi to the input parameter.
But you must know that there will have some delays between the time where
the conversion is done and when the value will go to the sub-vi.
I hope this will help you....
Best regards
Olivier

nospam@nospam (Alex) wrote:
>[posted and mailed]>>scc@ucla.edu (_Steven Chang) wrote in <39E1FFCD.54DD8DF@ucla.edu>:>>>can
this be done?>>>>basically I would like to convert a decimal number into
it's 8 bit>>binary equivalence and display it with 8 LED's. When the VI
is run, the>>decimal number changes and I would like to synchronize the chagne
with>>the LED. So I have a set of LE
Ds and I created local variables for>>them.
But when I created a sub-VI for this funtion, I can't seem to>>include local
variables in the sub-VI, this is just a matter of rule of>>Labview?>>>No,
you can use locals within a subvi. It depends on what you are trying to >achieve.
Why use locals? You can just make your binary LED's as indicators >and set
them by wiring the output from your conversion from the decimal >number.>>Locals
should really only to be used in very unique situations eg, to >update controls
or to pass data from one loop to another.>>The major disadvantage of locals
is that they force the VI to remain in >memory and therefore are computationally
more intensive (in this sense). >Another disadvantage is that they can lead
to race conditions where the >update and reading from the control are not
synchronized in any >deterministic fashion and this leads to bugs in your
running code. You can >almost write local "free" code, because you can be
clever about your data >passing
and you can throw and catch data between
loops using queues.>>>-- >>Alexander C. Le Dain, PhD>ICON Technologies Pty
Ltd>http://www.icon-tech.com.au>
0 Kudos
Message 4 of 11
(8,178 Views)
_Steven Chang wrote:
>
> can this be done?
>
> basically I would like to convert a decimal number into it's 8 bit
> binary equivalence and display it with 8 LED's. When the VI is run, the
> decimal number changes and I would like to synchronize the chagne with
> the LED. So I have a set of LEDs and I created local variables for
> them. But when I created a sub-VI for this funtion, I can't seem to
> include local variables in the sub-VI, this is just a matter of rule of
> Labview?
>
> Thanks,
> Steven
Steven,

Except globals, recommended before you can use:

1.Open reference to your sub-vi in caller vi and assign this reference
to a local variable. When needed, use set/get control value method from
caller vi with this reference.

2. If you are in LV6, use
DataSocket for direct connection through
DataSocket server to sub-vi controls or indicators.

3.Use TCP/IP and vi-server functionality to communicate with sub-vi,
which is made as a vi-server.

4.Make functional global (vi with while loop with uninitialized shift
registers) and call this vi when values are changing.

Connection through data socket is easiest and straightforward, but LV6
is required and recommended.

Cheers,
--
Sergey Krasnishov
____________________________________
Automated Control Systems
National Instruments Alliance Member
Moscow, Russia
sergey_acs@levsha.ru
http://acs.levsha.ru
0 Kudos
Message 5 of 11
(8,178 Views)

Hi

I got problem for creating sub vi because the message said its more than 28 connector inside and cant create it.

I also cant use cluster .Is anyone can give me suggestion about my problem?

Thanks

0 Kudos
Message 6 of 11
(7,829 Views)
You should post your question in a new thread since it is unrelated to the 7 year old thread you posted into.
 
How are you creating your sub-VI?  I'm guessing it must be by selecting a section of code that must have more than 28 wires running into or out of it and hitting the menu Edit/Create SubVI?  I have yet to find this a useful way to create a subVI.
 
Since a subVI is limited to 28 connectors, there is no way you can use that method.  What you will need to do is create a new, blank sub VI and copy and paste the code into it.  You will need to find a way to organize all of those wires, perhaps by bundling common wires into clusters so that you can reduce the number of connectors needed.  (Actually, you could probably do this on the original VI so that you select cluster wires crossing the boundaries rather than the individual data wires.)  Then create your controls and indicators and connect them to the panel.
 
Overall, it is better to plan for subVI's before you create the code.  28 wires is a lot and indicates that probably way too much is going on in that single subVI. 
 
Why do you say you can't use clusters?
 
 
0 Kudos
Message 7 of 11
(7,824 Views)
Actually I want to create sub vi for the instrument program. As the program is too complicated, it is very difficult to change their input into clusters. Is there any better way to create sub vi instead of using clusters?
0 Kudos
Message 8 of 11
(7,817 Views)


@120341 wrote:
Actually I want to create sub vi for the instrument program. As the program is too complicated, it is very difficult to change their input into clusters. Is there any better way to create sub vi instead of using clusters?


I have no idea what you mean by "instrument program". Could you be a bit more specific?

A subVI with 28 connectors is a prime example for "complicated". It will be a nightmare to hook it up anywhere and the chance of crossing a wire by accident is nonzero! 

Does it already have 28 connectors and you want to add more? Do you just grab a screenful of code and are trying to do a "create subVI" and it won't work?

No matter what, you need to rethink your code design. Use arrays and cluster to keep related data grouped together. Can you show is a code image or even attach a VI?

Message Edited by altenbach on 09-20-2007 10:38 PM

0 Kudos
Message 9 of 11
(7,807 Views)
Instrument program means the program which can be used to control for measuring instruments.
 I want to combine each individual program to form one big program which can be used for at least 3 or 4 instruments. So the only way to form the program is I must create sub vi for each individual program. But my problem is each individual program has too many input and output and it's more than 28 connectors .
0 Kudos
Message 10 of 11
(7,797 Views)