LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI not outputting values at regular intervals when used as sub-vi (posting for another)

A YouTube question that I wanted a better place to respond to...so it's going here and I'll reply to myself and let anyone else respond as desired.
https://www.youtube.com/watch?v=zr2qqv1F4kk&lc=UgzX7I9d8bInJGp_qex4AaABAg
=========================

@bobopet2 comment from 04-17-2025

I made a sub-vi that iterates through the first column of an array of values at fixed time intervals and I want to output the generated values as they come. For some reason it works fine when I open the sub-vi , but it doesn't output any data when I put the sub-vi in another program. Why could that be?

0 Kudos
Message 1 of 2
(120 Views)

Based on your description and if we’re understanding correctly, you’ve likely fallen into a not all to uncommon misunderstanding of how dataflow works.
Your sub-vi indeed is a method. Your sub-vi will not run, until data ‘flows’ from all upstream sources to it’s inputs, and similarly so, your sub-vi will only complete once it’s done running and will output whichever data is on it’s terminals at completion.
Going off of experience, I’d guess that you’ve got a loop in your sub-vi which runs multiple times at your desired rates, and then once complete your sub-vi is done and other parts of the calling program only get the last value executed in the VI.
It's an easy thing to get turned around on as you get started understanding dataflow.
 
I presume your sub-vi is something like this, where indeed the element output updates at prescribed intervals when run.
but when this is as a sub-vi, it will only output the last value.

NJKirchner_0-1745015647536.png

 

I presume this is to send to some instrument like a DC power supply or the like to periodically update some kind of output value, and you'd like a simple VI to put into a loop to pull out the right value at the right time to update that other thing.

If so, this function as a sub-VI will not work as is. Although you can easily kickstart a sub-VI as an asynchronous running process, i presume you're simply using it as a method in-line with the rest of the code.

 

As with MANY things in programming or CAD there are a multitude of ways to get the output you want, but the right choice is best determined by the bigger picture, how the code will be used and who's going to be the developer / maintainer
I will merely put a super simplistic answer here, but let your response here help drive the continued discussion with the community in tow.

 

Presuming your downstream 'thing' can have the same value sent to it over and over again without issue (situationally dependent), then we can just put a small chunk of code in the sub-vi to see how much time has elapsed and give the new right value based on elapsed time. 

There are more 'elegant' ways to do this using events or queues or even asynchronously launched pieces of code...but I'll leave it at this till you reply.

This code is not guaranteed to not have a bug, but it gives you a better idea of how to do a REALLY simple timed indexing. 
FWIW, the boundary condition of what happens beyond the time limit is UNDEFINED and can lead to a bug. So if you adopt this approach, make sure to deal with what happens when the value to index out goes beyond the number of elements in the array.

NJKirchner_1-1745017261345.png

 

 

 

Download All
Message 2 of 2
(107 Views)