LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

"communication" with subvi?

Ok I think I have figured out how to create a subvi and how to implement it into another VI but I cant seem to "communicate" with it? if create a subVI containing a simple while loop with a Led and an On/OFF switch, then a assign the connectors and save it ----> then I import it into another VI where I connect an ON/OFF switch and a led to the subvi. But when I run it nothing happens when I turn the switch on and off????? what I'm I during wrog? 
0 Kudos
Message 1 of 6
(3,243 Views)
This is actually a pretty common error early on. You have to remember that LabVIEW functions on a dataflow paradigm. Your subvi will not execute untill all the inputs to it are available, and then it won't return untill it has completed everything in the subvi. In your example, the boolean switch on the front panel is read, and the value is passed to the subvi. Your subvi will begin to iterate through the while loop, but since the input was a constant (whatever the value of the boolean on the parent vi was when you hit run), it won't change the value of the boolean. I also imagine that you may have some difficulty getting the while loop in the subvi to return if you haven't set up a timeout or some other way of ending the subvi.

What you can do, is move the while loop to the parent vi, and just make your subvi display the value of the boolean that gets passed in every iteration. There are ways to establish communication between running vi's, but I don't think that's really what you are looking for here.

Just remember that any subvi or function operates on the inputs that were available when it was called. It may help to turn on execution highlighting and watch to see how the data flows in your program.

Chris
Message 2 of 6
(3,229 Views)
Thank you for your response Chris. The simple example with the switch and the led was just an example - actually I have a "timer" which uses a while loop and it is this "timer function" I want to put in a sub VI, so isnt there any way to overcome this problem? I understood your answer but then I cant really see how it is possible to incorporate a while loop inside a subvi?
0 Kudos
Message 3 of 6
(3,216 Views)
Hello,
 
From what I've read it seems very possible to do this all as one vi.  Could you attach your vi so we can have a look at it?  Or explain in full detail what you want and we can help you further, or just create the program for you.
 
Regards,
Message 4 of 6
(3,194 Views)
I am going to second Steve's remarks. It would be helpful if you could upload an example vi. As far as a timer goes, there are tons of ways to do that. One way is to make a while loop that spins for whatever amount of time, and then returns. Another way is to just use a wait, or Wait Until Next ms Multiple to control timing. I don't recommend either of these ways, even though they are very simple to implement. In both of those cases, the loop that is executing the wait is frozen until the wait completes (so if you tried to stop the vi by pressing a button, it couldn't end until the wait was over).

I think it's better to get a current timestamp, and then add your desired wait time to it, and then in each iteration of your loop, check to see if the current time is greater than your time-plus-wait to trigger whatever you want to happen. Of course, this is only decently accurate if your loop time is fairly small. In this way, if you press a stop button, your vi can immediately respond. Let's see an example and try to put together a good solution for you.

As far as using while loops in subvi's, remember that there are lots of ways to stop a while loop; a control input isn't the only way. Also, if you want to, you can make a subvi display it's own front panel that you can interact with.

Chris
Message 5 of 6
(3,187 Views)
Yes it is possible to put it all in one VI and it is working fine! but I just wanted to put the "timer part" in a subvi so that the code wold be more easy-to-read
0 Kudos
Message 6 of 6
(3,158 Views)