LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sub vi does not return all elements

Solved!
Go to solution

Fundamentally, my sub vi is only returning one value for every loop iteration.  I read 10 samples at a time, so I lose 9.

I thought of building an array, running the sub vi in a for loop with auto indexing.  the problem with that is it only returns last value, unless I build an array out of the loop.  downstream I have dbl sinks, so I can not wire the array.  Is there a way to convert the 1D array to the stream of 10 elements so that the simple math corrections can be run downstream?  Is there an alternate solution to make the sub vi return all ten samples?

0 Kudos
Message 1 of 23
(3,736 Views)

let me update that... index array seems to be what I need.  when I wire the array to the sinks, I get error.  source 1d array, sinks - dbl.  when I wire index array to sink, i get source is dbl, sink is 1d array.

0 Kudos
Message 2 of 23
(3,732 Views)

It would be better if you post the sub VI you are talking about

-----

The best solution is the one you find it by yourself
0 Kudos
Message 3 of 23
(3,725 Views)

Of course, fundamentally this comes down to what the data means. You said that the subVI reads 10 samples, but downstream you have a DBL. OK, forget the code. You have 10 values. You need to get it to 1 value. How does this 1 value represent the 10 values? Is the maximum? Minimum? Mean? Mode?

0 Kudos
Message 4 of 23
(3,710 Views)

right-click the array wire and go into the array palette and find the index array and drop it on the diagram and wire the array to it. Then pull down on the index aray to get an output terminal for each element in the array. WIre those outputs to your indicatros.

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 5 of 23
(3,704 Views)

I made example code.  I am producing 10s every loop.  it goes into sub vi then to file write.  I am losing 9/10 of data.  I have 2 examples here.  ex1 represents original problem.  ex2 is a work in progress.  I still have same problem.  i am not building the array properly.  I need it to build a 1d array of 10 elements then reset every loop iteration.  if I use a feedback node, the array builds fast.  I could just move the contents of the sub vi to the main block diagram and be done, but it is a math that takes up lots space, visually.

Download All
0 Kudos
Message 6 of 23
(3,701 Views)

ben, sounds like that would work.  I agree the indicators are probably the problem.  I got an error when I wired in an indicator, which is why I used the array indicator.  If I do that, then the indicator would only update once every loop iteration, correct?

0 Kudos
Message 7 of 23
(3,696 Views)

You need to convert the dynamic data type (blue wire) to an array of doubles.  (Not turn it into an array of signals.)

 

0 Kudos
Message 8 of 23
(3,683 Views)

@comedygene wrote:

ben, sounds like that would work.  I agree the indicators are probably the problem.  I got an error when I wired in an indicator, which is why I used the array indicator.  If I do that, then the indicator would only update once every loop iteration, correct?


 

Are you trying to live up to your user name comedygene, becuase that's funny. Smiley LOL

 

You want me to confirm your notion without having looked at the code?

 

Post an image of your code after you make the changes and we can give you a better answer.

 

But even better!

 

Have you tried going to execution highlighting mode )turn on the light bulb in the diagram) and watch your code in slow motion. That is one of the nice thing about LV, it hides nothing from us. All we have to do is look in the right place. Yes experience helps with figure whcih place to look but that will come with time.

 

Have fun!

 

Ben

 

PS Disreagard me. Look at what Raven Fan posted. Smiley Happy

 

 

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 23
(3,683 Views)

I did what raven fan posted.  actually, I tried a couple things.  I will post examples when I can.  using the converter before the for loop seems to work.  I now have an array of 10 before and after the loop.  one issue is timestamps.  the data is converted to dynamic data again after the loop.  when I look at the data, I have ten datapoints with the same timestamp.  so I tried index array after the loop. still had the issue of only recording 1/10 of the data.  I did try the highlight exec mode.  it was interesting, but I did not find anything like a smoking gun.  another idea I had was to remove the for loop, set up a producer/ consumer loop and dequeue one element at a time.  the problem there is that I do not know how to enqueue and dequeue multiple channels.  In the meantime, I thought the array with a for loop would be an easy fix, but it is turning out to be a little tricky.  will post example code soon. tnx for hlp

0 Kudos
Message 10 of 23
(3,652 Views)