05-17-2010 12:29 PM
Consider a bunch of experiments (Exp 1, Exp 2, Exp 3, for example) where in each Experiment there are many trials (trial 1, trial 2, etc.).
In each trial I am acquiring data from a sensor. I want to be able to initiate a trial (e.g. "Start Acquisition for trial") and stop it when I'm finished. When finished, the program would naturally go to the next trial (trial 2) and repeat the process of acquisition with the same button.
When I do all the trials I want for that experiment, I quit the experiment and begin the next one (Exp 2).
The process is repeated once again until I finish all the experiments (say, Exp 1 to Exp 3).
What kind of structure should I be looking at here? Can I use a flat sequence structure somehow?
Any guidance and simple examples would be greatly appreciated.
Thanks!
05-17-2010 12:53 PM
Probably the best structure for this kind of program is one based on a state machine. There are examples in the Design Patterns and many postings here on the Forum. The simplest implementation in LabVIEW is a while loop with a shift register (containing the next state) with a case structure inside. Each case contains the code for one state. This architecture is much more flexible and adaptable than anything you would try to do with sequence structures.
I have written programs much like what you describe both ways. I have not used sequence structures for anything like that since LV version 2.
You could use nested loops (outer loop for Experiments and inner loop for Trials), but I would just use one loop and pass the experiment number and trial number via shift registers.
I would likely use two loops in parallel: one would have an event structure to handle the button presses and other user inputs. The other loop would have the state machine. This is called the Producer/Consumer (Events) Design pattern and an example ships with LV.
Lynn