04-18-2023 12:23 PM
Hi,
I am trying to execute all the iterations of an inside FOR loop for each iteration of the outside FOR loop (this part is working). And for each iterations of the outside FOR loop I wanted to readout the data to be plotted real time. I tried using **bleep** registers and using channel writers and Tag, but docent seem to work. Also in my case the FOR loops are inside a case structure and i found that no other functions work within the case structure while the FOR loops are executing even though the functions have nothing connected to the FOR loops. I am hoping to get some suggestions to help me get this work. All suggestions, remarks are appreciated.
Thanks
04-18-2023 12:32 PM - edited 04-18-2023 12:43 PM
Note that the word shift register contains an "f", else the forum will bleep out the word. 😄
You never use the output of the shift register on the left, so anything you put in there will be irreversibly lost.
Your use of the conditional terminal is just plain silly. The loop will automatically end when the iteration count is reached, but in your case, the inner loop will only do one iteration on the last round. Is that what you really want?
I think you need to do some tutorials about dataflow and LabVIEW in general. What are the "other functions" that should run in parallel? Maybe they belong in their own toplevel loop.
Your boolean should be latch action and your FALSE case needs a small wait. No need to burn the CPU just to wait for the user. If you are stopping the code after the TRUE case, you don't even need the while loop and switch. Have a look at state machines.
Can you explain how you are using this code? What do do, what do you see, and what do you expect to see instead?
Have a look at this draft (note that all terminal should have reasonable names!!!):
04-18-2023 12:47 PM
And if you want to update the indicator one point at a time, you can do as follows:
04-18-2023 03:16 PM
Hi @ altenbach
The VI i attached is just a model and what i am trying to do and is just a small part of the whole code. How i am planning to use this is for data acquisition in sample mode. For example i want to get 4 sample data, and every sample is an mean of 10 values, and i am also using each data set values of the samples for other analysis too.
What i meant by other functions is that i initially thought a channel writer might work for what i was trying to achieve, but i found that the Tag functions are updating but put outputting a value coz of the For loops iterations.
I also tried your example, but that's not what i was trying to achieve. For me the challenge is to get each of those sample data values outside of the for loop to be used in other parts of the overall code while the For loops iterations happen.
04-18-2023 04:06 PM - edited 04-18-2023 04:12 PM
For loops have a "natural affinity" with Array structures. By default, a wire from an element generated inside a For loop (say, a Random Number), when brought to the right edge of the For Loop, creates an indexing tunnel that accumulates all the N values of the For Loop into an N-element Array. In contrast, a While loop, by default, uses a "Last Value" tunnel that, as the name implies, only has the "Last Value" generated by the last Loop that the While performed.
[Quiz to see if you are paying attention:
What if you don't use a Tunnel at all in a For Loop? There are ways (some "reasonable", others "questionable") to get data out of Loops as they are produced. Two such ways are via Queues and via Stream Channel Wire. You probably don't need to worry about them at this time, but these will "export" the values inside the loop as fast as they are produced (what you do with them at the other end is another question.
So when you have Loops within Loops, it depends on how the data get out of a For Loop. If through an Array Tunnel, the inner Loop (which finishes first) outputs a 1D Array, so the outer Loop will make an Array of 1D Arrays, or a 2D Array. You can make 3D and 4D Arrays by adding more Loops.
If you use a Last Value tunnel, you will get a single "Last Value" (assuming all the output tunnels are Last Value tunnels), and if you use an "Export" method, you will have a single stream of all the data in the order they were produced.
Bob Schor
P.S. -- I actually forgot to attach the Snippet -- thank goodness for "Edit Reply". I apologize for not using an earlier version of LabVIEW, but this is so easy to code that if you are running an earlier version, you should be able to put this together in 5 minutes or so.
04-19-2023 07:33 AM
@themadgreek wrote:
Hi,
I am trying to execute all the iterations of an inside FOR loop for each iteration of the outside FOR loop (this part is working). And for each iterations of the outside FOR loop I wanted to readout the data to be plotted real time. I tried using **bleep** registers and using channel writers and Tag, but docent seem to work. Also in my case the FOR loops are inside a case structure and i found that no other functions work within the case structure while the FOR loops are executing even though the functions have nothing connected to the FOR loops. I am hoping to get some suggestions to help me get this work. All suggestions, remarks are appreciated.
Thanks
When some part of the code in running in For loop and there wont be any parallel execution happening out the For Loop until Loop Completes.
If you want to continuous Read using For Loop and at the same time you want that data to be displayed outside the Loop, you can use Functional Global Variable to update the FP.
04-19-2023 09:55 AM
@themadgreek wrote:
Hi @ altenbach
The VI i attached is just a model and what i am trying to do and is just a small part of the whole code. How i am planning to use this is for data acquisition in sample mode. For example i want to get 4 sample data, and every sample is an mean of 10 values, and i am also using each data set values of the samples for other analysis too.
What i meant by other functions is that i initially thought a channel writer might work for what i was trying to achieve, but i found that the Tag functions are updating but put outputting a value coz of the For loops iterations.
I also tried your example, but that's not what i was trying to achieve. For me the challenge is to get each of those sample data values outside of the for loop to be used in other parts of the overall code while the For loops iterations happen.
As I said, it's all in the dataflow. LabVIEW has plenty of tools to communicate between independent parts of the code (e.g. queues and many others). So instead of an oversimplified small code fragment, shows us what you actually need to do with the data as it is being acquired. If the acquisition is slow, some of the processing can even be done in the same loop. For example averaging four points can be done right there.