LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to output data from a while loop during execution?

Hello,

 

I am writing a program that continuously reads digital inputs and continuously writes digital outputs. I am using NI ELVIS and know that these functions can run simultaneously, so thats not the problem. What I really want to occur, is that the reading and writing occurs at the same time. When the 2nd element of the digital inputs receives a true statement that while loop stops and the value goes to the writing while loop and stops the writing. This then triggers another iteration of the for loop which changes the case statement and the array of boolean values that is written.

 

My issue is that the read while loop always runs first and thus the writing isn't continuously occurring. Is there a way to get both of these while loops to occur simultaneously.

 

Attached is my code. Sorry for the convolution. Any help would be much appreciated.

 

-Shane

0 Kudos
Message 1 of 5
(6,764 Views)

You have some very basic misunderstandings of dataflow. The code cannot work in its current form and is way too complicated.

 

First you have a data dependency between the upper while loop and the lower case structure, meaning the case cannot execute untill the upper while loop finishes. All your inner while loops inside the case structure stop after one iteration, because the boolean condition cannot change once the loop has started. Since the boolean is always true, the lower while loops terminate immediately and thus have no purpose. The code would act exactly the same if you delete the lower while loops.

 

There is way too much duplicate code, for example the cases differ only in a diagram constant, meaning all that belongs inside the case in that diagram constant. All the shared code belongs outside. However, you don't even need these array constants, because you can directly generate the pattern form [i] unsing number to boolean array.

 

A good troubleshooting tool is execution highlighting. Have you tried it? It will give you a better feeeling on how dataflow actually works.

 

The initializing and closing needs to be done only once, outside the FOR loop, and probably not with each iteration.

 

I would recommend to do the reading and writing in the same inner while loop. Attached is a quick draft. I don't have the subVIs and hardware, so I cannot test. Most likely you need to change a few things here and there.

 

The program still does not look complete. What should happen after 8 iterations of the FOR loop?

Message 2 of 5
(6,759 Views)

Some corrections:

 

 

  • The output does not need to be in the inner loop. It only needs to update if the outout changes and that is once per iteration.
  • Errors and references should be in shift registers. If an error occurs, the code should stop. (References belong in shift registers of for loops because of you do not, they become invalid in cases where the loop itereates zero times. This cannot happen here, but is still good practice in general). 

 

Message 3 of 5
(6,740 Views)

Thanks for your help. The majority of the corrections you made were very helpful and the program is running well.

 

Thanks again,

Shane

0 Kudos
Message 4 of 5
(6,724 Views)

if the answer was helping you finding a solution to the problem you should mark the solution and, well, give a kudo to the one that helped you, sir !

 

 

0 Kudos
Message 5 of 5
(6,722 Views)