LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Moving live data from inside for loop

Solved!
Go to solution

Is there any way to move live data from inside a for loop to outside of the case structure in real time? I would like to graph data from a case structure in real time outside of the case structure. It would ideally include the information from the true case and then the wait period as a "0" for the false case. Attached is a simplified version of the VI i am working on. I have tried local variables but they will only read the first element the for loop puts out every T/F cycle. Any idea's are welcomed including complete change of structure to the VI. 

 

Thanks! 

0 Kudos
Message 1 of 15
(3,592 Views)

Your code makes no sense whatsoever. In your FOR loop you create an array with a single element, then try to index it out again. Why the detour? None of that code is needed. Also, the code outside the case structure executes only once in parallel to the FOR loop, so sharing data across will not really update anything. Also, your scalar indicator is not needed. Simply right-click the chart...visible iterms...digital display.

 

To share data between independent code segments, you would use queues or local variables, for example, but it seems that your current problems are much deeper. I would suggest you start with some tutorials about dataflow.

 

Please tell us exaclty what the code is supposed to do. There are probably much better solutions to all this.

0 Kudos
Message 2 of 15
(3,586 Views)

The quick answer that comes to mind is to use a queue.  You would want to put the reading of the queue and the writing to the chart in another While loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 15
(3,581 Views)

@kspink wrote:

Is there any way to move live data from inside a for loop to outside of the case structure in real time? I would like to graph data from a case structure in real time outside of the case structure. It would ideally include the information from the true case and then the wait period as a "0" for the false case. Attached is a simplified version of the VI i am working on. I have tried local variables but they will only read the first element the for loop puts out every T/F cycle. Any idea's are welcomed including complete change of structure to the VI. 


Charts often only make sense if they are updated at a constant interval, else you cannot label the x-axis as time.

The correct way here would be to spin the while loop at 10ms and use the case structure to either output zero or real data, depending on the state. The terminal of the chart belongs after the loop. Flip the boolean acording to the required state transition, and not with every while iteration.

0 Kudos
Message 4 of 15
(3,567 Views)

Dividing by one and getting the remainder is not necessary either.  That's always 0.  Smiley Very Happy

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 5 of 15
(3,558 Views)

Here is one possible solution. Modify as needed.

0 Kudos
Message 6 of 15
(3,553 Views)

Sorry the simplified version might have caused more problems. What I would like to do is create a program that will pump a linear actuator to act as a mock heart beat. 

 

What I am currently doing is taking a .txt and using the "read from measurement file" and turning it into dynamic data. This is done outside the main while loop.

 

Inside the while loop is is a case structure wired to a not function connected to a shift register.

 

In the true case I  use a for loop and convert the dynamic using a local variable and create an array by indexing the data with the iteration and quotient and remainder function. Within the for loop there is a wave chart, this graphs the data within the for loop. 

 

In the false case there is only a wait until function. This is pauses the the graph.

 

Overall all I want to do is create an array (a .txt file mimicking the rate of ejection volume of the heart) that can output to a linear actuator. I want to be able to change the frequency of the curve (mock heart rate) And the duration of the phase (which includes a rest period) 

 

 

Download All
0 Kudos
Message 7 of 15
(3,534 Views)

Why read the same file 103 times?  Just read it all at once.  Then get the array of data out of it.  You can then pass that array into your loops with wires and tunnels.  You can index off any value you need from there.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 15
(3,513 Views)

You still should program this as a simple state machine without inner loops (look at my earlier example for some ideas).

 

There are still plenty of very questionable constructs.

There are race conditions, because there is no guarantee that the "systolic" terminal is written before the corresponding local variable is read in the FOR loop. Why not just wire acrosss, eliminating the terminal and local variable? Why are you reading the same file 103 times? (We cannot tell how the reading is configured, so please attach the actual VI instead). Why are you dividing by 102 instead of 103? The last read is never seen! Since you never exceed the number anyway, you could just autoindex the dynamic array at the loop border and eliminate all of the useless index math.. 

Please attach the actual VI. Thanks!

0 Kudos
Message 9 of 15
(3,509 Views)

@crossrulz wrote:

Why read the same file 103 times?  Just read it all at once.


The read can be configured to read fixed size segments so this might not be the same. No way to tell without seeing the actual code.

0 Kudos
Message 10 of 15
(3,497 Views)