LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

SubVIs problem

Hi everyone.
 
I don't understand the VI problem...
 
I made a simple VI with a SubVI, the SubVI has a while loop. Why the while loop of my SubVI doesn't stop when I press the "Stop Button" and why I can't see the "indicator value"?
 
Please, help me... I don't understand why it doesn't works! This is a simple VI but I need the answer to fix another VI I'm making...
 
I attached 1 pic to see the program. 
 
Sorry about my english...
0 Kudos
Message 1 of 10
(4,150 Views)
Kinda hard to figure out just looking at the pic. Plus I use Labview 6.1.

Anyway here's what I think...

In your sub-VI num 1 isn't connected to num 2 at all?

Not 100% sure why it's not stopping, looks right to me.
0 Kudos
Message 2 of 10
(4,120 Views)
The loop needs to be in the main VI not the sub VI.  Once the sub VI is entered you get "locked" into it because the loop cant terminate and go back to the main VI without clicking the stop button.  In addition to this the stop button is a part of the main VI and not the sub VI so it cant be controlled from there.  Thus an infinite loop.
0 Kudos
Message 3 of 10
(4,118 Views)
The reason you can't see the indicator is because it won't be updated until the subvi is done running, and that can't happen because the stop button is only read when the subvi first begins to run.

There are a few ways around your problem.  The best of which is probably to use references, since you said that you need to use this for a more complicated vi.  Another method is to remove the loop from the subvi, and put the subvi in a loop in the calling vi.  That would be best for a simple solution.

In order to use references, you need to read up on them in the help.  Search for references and refnums to read about how to use them.   Also read up on property nodes, and put all those together, and you should be able to make something up.  If you can't get anywhere with those, let us know!
0 Kudos
Message 4 of 10
(4,116 Views)
From your main vi, you call the subvi.  At that time, the values from the main are input into the subvi.  While the subvi is running, your main is waiting for the subvi to finish.  Clicking the stop button in main while the subvi is running will not stop the subvi.  It has already received the value of the stop button.  It is like calling a subroutine in text languages, you pass the parameters and they immediately go to the subroutine.  You can't change what has already been passed.  Also, you will not see any updates (changing numerical outptut) in your main vi.  Once the subvi finishes, the value of the output gets sent back to the main and then it is displayed.  Fortunately, Labview has reference data type that can allow you to peek and poke into a subvi from main.  Create a reference of the stop button (right click - create - reference).  Also create a reference to the numeric indicator.  In your subvi, change the stop and numeric indicator to reference types.  Make sure they are connected in the connector pane.  In the main, wire the references into the subvi.  Now your main indicators will be updated as the subvi is executed, and the stop button immediately will be passed to the subvi.
Here is a better explanation.  You need to understand the difference between passing a value into a subvi, and passing the address of the value into the subvi.  When wiring in a control or such to the subvi, the value is sent (not the address).  The subvi creates its own memory space and copies the value it was sent into an address space in its own memory.  So changing the value in main does not change the value that the subvi is using.  Same for the numeric indicator.  The main indicator holds its value in a different address than the subvi.  By using references, you are not passing the value.  Instead you are passing the address of the variable, similar to pointers in C.  So now, when the subvi starts, it does not create addresses in its own memory space for these variables.  It manipulates the address space that was sent to it by the main.  Now, when you press the stop button in main, each time the subvi must read the stop button, it goes to the address sent by main, and sees the new value immediately.  Same with the indicator.  When the subvi changes the indicator, it is actually changing it at the address of the indicator sent by main.  So main will see the change immediately.
I hope this is clear.
- tbob

Inventor of the WORM Global
Message 5 of 10
(4,114 Views)
The problem is that a subVI will not output nay data until it completes running. So the indicators on your top level VI will not receive any data until the subVI stops running.

In the same way, any controls that are wired to the subVI are only read once before the subVI starts running.

To make this work the way you want, you should move the While loop from the subVI to the top level VI. This way the subVI only runs once on each iteration of the top level loop and will update the indicators as needed.

These are some of the basic priciples of LabVIEW that you really should know before you start coding. There's a good online tutorial at http://cnx.rice.edu/content/col10241/latest/. There's also some good information/reading material and tutorials in NIs LabVIEW Zone.

I would suggest doing some reading to make sure you understand the basics.

Ed


Ed Dickens - Certified LabVIEW Architect
Lockheed Martin Space
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
0 Kudos
Message 6 of 10
(4,112 Views)
You've made a very basic mistake. When you call a subVI, you pass it some parameters. The subVI then takes those and runs. It will not accept any new parameters until it finishes, returns to the main VI, and is called again. It also won't return any parameters until it finishes. Function calls in text based languages work the same way. If you want, you can have the subVI show it's front panel when called so that you can see the results and stop it. You could also have a while loop in the main program in which you call the subVI (without the while loop). There are also advanced methods that can be used to pass the results from an indicator in a subVI back to a main VI while the subVI is running and pass a control value to the subVI. This is done with something called control references and there are shipping examples of how these work. You should probably get an understanding of LabVIEW basics first. Go to the LabVIEW Learning Center and investigate some of the links on classes, books, and on-line tutorials.
0 Kudos
Message 7 of 10
(4,108 Views)
I am concordant with Dennis.
 
Would you check for attachment for the future? It uses the control referencies and works.
Once again you should change your algorithm. Do not use my example to develop your applications yet.

Message Edited by EVS on 08-25-2005 11:47 PM


Jack
Win XP
LabVIEW 6.1, 7.0, 7.1, LabWindows/ CVI 7.1
Let us speek Russian 🙂
Download All
Message 8 of 10
(4,098 Views)

Hi !!!

Thank you so much for help to everyone!!

I didn't know about the levels between Main VI and SubVIs. You help me so much, tbob! I will practice with "references" to make the real VI.

0 Kudos
Message 9 of 10
(4,055 Views)

Thank you EVS...

your example was I looking for... your picture show me how start (practice) the real VI I have in my mind.

0 Kudos
Message 10 of 10
(4,054 Views)