LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing data to subvi on every loop iteration

Solved!
Go to solution

Hello everyone,

 

I'm a student currently taking a course on LabVIEW. Right now I'm having trouble with completing an assignment which was given to me.

 

The gist of it is: The teacher has provided us with a subvi that outputs 7 random values based on the current time. Those values have to be read continously (in a while loop) and visualized using indicators. This works perfectly fine.

Now my problem: Those random values must also be saved into a .csv file. In class we have written a (sub)vi for this (using the File Dialog express vi), but we never have passed values from a main vi into the sub vi where those values are used in a loop for writing to the file.

What is the best way to complete this task?

 

Thanks for your help, I really appreciate it!

 

PS: I could also attach my vis if that would help

0 Kudos
Message 1 of 6
(3,309 Views)

Typically, you'll get better help is you show us your VI.

 

The file writing subVI also belongs inside the loop. It would be more efficient to use lowlevel file IO, open the file before the loop, append data inside the loop, and close the file when the loop completes. Try it!

Message 2 of 6
(3,267 Views)

Thanks for your help!

I have attached my VIs to this reply.

The problem I'm having is if I put the writing subVI into the loop then my indicators do not update anymore as the outside loop is waiting for the subVI to complete.

Would it best to completely break down the writing subVI and put all the necessary parts dirctly into the main VI?

Another thing is that I'd like to have different intervals for updating my indicators and for writing to the file. For example I'd like to update my indicators every second, but only write to the file every 5 seconds or so.

Download All
0 Kudos
Message 3 of 6
(3,235 Views)
Solution
Accepted by topic author LabVIEW_Tester

You might want to "save for previous" (e.g. 2015), because virtually nobody has LabVIEW 2017 at this point in time. It was released only days ago.

 

As a second step, learn about arrays. It would make your code and the subVI connectors 7x simpler! For example, the indicators on the "visualization" tab, could all be arrays. I probably would use an array of clusters, where each cluster contains a string for the label, a vertical slide, a limit control and a boolean. If you need a connector pane that is bigger than the default, something is seriously wrong.

 

You can turn your subVI into a proper state machine (or action engine) with various modes (write header, append data, close, etc.) and get rid of the while loop inside the subVI so it immediately returns after each operation. To write only every 5th iteration of the loop, just use a case structure that only turns true whenever the iteration value is divisible by 5, for example.

 

Message 4 of 6
(3,222 Views)

Thanks!

 

I took a look at arrays and that would make my program a lot cleaner, thanks. I'll change it as soon as I get the writing to work.

You lost me a bit at using a state machine in my subVI. I looked at a couple of tutorials online (like this one) but I can't really see how implementing a state machine would get rid of the while loop inside the subVI. Do you by chance have an example?

 

Attached are my VIs saved for version 2015 (no changes to the VIs above, only saved for the previous version)

Download All
0 Kudos
Message 5 of 6
(3,219 Views)

Thank you very much, I figured it out!

It now works as intended.

Your idea on checking if the iteration value is divisible by 5 and using a case structure to write to the file put me on the right track.

Now my program works and looks much better thanks to your suggestion of using an array of clusters.

 

Thank you once again!

0 Kudos
Message 6 of 6
(3,194 Views)