LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger a While Loop from a previous loop and returning to the first one (parallel loop operation)

Solved!
Go to solution

Hello,

 

I have a while loop where I monitorize with a couple of graphs a voltage variation given by an instrument. When I finish the loop (with a boolean) it goes to another loop where I take a number of measurements in an array and average them (this loop condition is when the number of loop iterations is equal to the number of mesures desired).

 

The thing is that every time I take a measurement I have to reinitiate the VI, also the monitoring graphs stop for taking the measurements (as it exits from its loop). I have tried to put the second while loop inside the first one but then it does not take any measurement. If I put all the code in a global while loop I can't stop the VI when I want. I have also tried event structures with no success.

 

Is there any easy way to go from the first loop to the second one (as I am doing) and then return to the first loop without closing the VISA sesion? (communicating between both loops only when pressing a boolean).

0 Kudos
Message 1 of 8
(2,384 Views)

All you need is exactly one loop and a state machine architecture.

 

(Your entire description is very ambiguous, so it is difficult to give advice. It help if you would actually show us a simplified version of your code)

0 Kudos
Message 2 of 8
(2,370 Views)

I can't figure out how to have both loops running at the same time in a state machine, sorry.

 

I am attaching this part of the code. Thank you

0 Kudos
Message 3 of 8
(2,346 Views)

(You did not attach any code, just an relatively useless image. That's not the same! We cannot run or debug a picture and it is difficult to make sense of it if there are overlapping wires going in all directions and wires partially hidden behind objects. There are weird constructs such as building a 1D array into a 2D array just to take the sum of all elements. Seems unnecessary. What's up with all the coercion dots? e.g. Why is the "#. scans" orange? That "equal" comparison is extremely dangerous and the second loop might never stop!)

 

Your two while loops have a data dependency (and a completely unnecessary sequence structure!) and thus can never run "at the same time"! If things need to run in parallel, use more than one toplevel loop and a suitable communication mechanism (queues, notifiers, channel wires, etc.)

0 Kudos
Message 4 of 8
(2,335 Views)

Just guessing here by the commands, you are using a SRS lock-in or something similar.

 

Because you are receiving data in from a device over VISA, you can never do both loops in parallel; VISA does not work that way.

 

It looks like you a building a chart 1 point at a time; in your second loop you are spinning it as fast as possible, if it is a SRS lock-in then ~25 Hz is the fastest you can go point-by-point. Those lock-ins, or you device, have an internal buffer where you can store points then download them, check your manual.

 

mcduff

0 Kudos
Message 5 of 8
(2,304 Views)

It sounds to me like what you want is a Producer/Consumer setup with the second (consumer) loop perhaps using Quotient and Remainder, Replace Array Subset and a fixed length array to iteratively replace a value in the array, then when you have all your values (so they're all "unprocessed") process them. Then repeat, replacing the now old/processed elements with new ones, and on and on...

Example_VI.png

This might get you started. The top loop should be replaced by something that generates the samples...


GCentral
0 Kudos
Message 6 of 8
(2,294 Views)

@DFMarq wrote:

I can't figure out how to have both loops running at the same time in a state machine, sorry.

 

I am attaching this part of the code. Thank you


Your current code don't run at the same time, so what's the issue?

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 8
(2,244 Views)
Solution
Accepted by topic author DFMarq

@DFMarq wrote:

I can't figure out how to have both loops running at the same time in a state machine, sorry.

 

I am attaching this part of the code. Thank you


My understanding of your description is that you want to have one loop running (let's call this State 1) until something finishes that loop, and then run another loop (State 2) returning to State 1 on completion. You only need 1 loop that includes both states (and probably some other states as well). You only change states when the exit condition is met.

0 Kudos
Message 8 of 8
(2,236 Views)