LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Starting simultaneous while loops

Hi, I am fairly new to labview, and understand most of the basics. With daqmx I have had the pleasure of some simpler initial programming, but this has led me to miss out on some of the advanced topics. I have code that is in a single vi, that records data at 1 khz and sends out data at random delays. My main issue is getting these to start simultaneously. Many other forums I have looked at have suggested rendevous, flowing errors from one loop to the other, or possibly creating two sub vis. I tried the rendevous route and it did not work. What is the best option for this? I really just want to start them at the same time and then have them run without interacting. 

0 Kudos
Message 1 of 8
(1,255 Views)

Ah, what a monolithic mess!

 

Your entire code architecture seems inside-out, with no toplevel loop and terminals on the top-level diagram that get read (and their various output results calculated) when the code starts, so when these controls are changed during the run, the connected indicators (e.g. "Estimated Session Duration (s)" will have stale values for the duration of the code.

Every single one of your property nodes should be eliminated (or replaced by local variables if there is no other way). much more efficient.

Writing the same value to an indicator terminal and to a local variable of that same terminal in parallel is just silly (e.g. the "True Positive" terminal).

Most of your other controls also get read right away and before the dialog that everything is OK even pops up. Any changes later will never get read from the terminals, so whatever is wired downstream inside the big case structure never gets what you think it gets. 

 

To your questions: If you want to synchronize the start of two loops you can use timed loops, which has such tools. Still, I have the nagging suspicion that that's not the real problem.

 

Further code analysis would need to wait until I get my 8K monitor. Sorry. 😞

 

Properly architected as a clean state machine, it would probably fit on half a screen and would be manageable.

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

Hey altenbach

 

1. I do not want the ability to change these controls during the run. ( I use this code for technicians to run a set paradigm that, I must restrict from mistakes where they may accidentally change things during the run. 

2. I believe the property node is more efficient (see:

The real difference is that creation of local variable makes a copy of data and you call it's data by value. When you crate many of locals, especially for complex data types like arrays, you get perfomance loss.
Property node calls value by reference and doesn't copies the data itself. LV internal updating values mechanism is another difference.

 

3. The extra local variable was a mistake. As you can see I have a lot going on in this. 

4. I do obtain the values I want because I do not change those values during the run.

 

5. The timed loops I will give a try, however, for one of my loops it has a random wait time, so the execution is not consistent in its timing. I do not think that time loops can handle that. ( I inherited alot of this code so if it can be done better from scratch I am all ears, I could change all property nodes but doesn't seem worth my time)

 

6. Basically this code is to send out random trials of two digital signals at specific timing, and record them, until a certain amount of each digital signal is recorded. 

7. All the stuff prior to the ok signal is just to have people input where they are saving things. (could I make this a sub vi and call it? That would be helpful to know)

8. The monolith of nodes if for those watching to make sure everything is running and that we record all instances.

So it seems like all you had to input was clean up the diagram, which is just moving blocks around, replacing a few different pieces of code that would not change the essesnce of how things run, and an idea that is not right for this project. 

9. If it is easier I can send some code where I simply have two while loops inside a single case structure. One of those while loops executes every 1 second and records 1000 samples of data. The other loop executes randomly either at 10, 11, 12, 13, 14, or 15 seconds, and commands within those timings certain digital outputs. How do I make sure that these start at the same time and stay together. 

0 Kudos
Message 3 of 8
(1,155 Views)

I replied before, but don't think it got sent, but in a much more succinct format:

 

yes, 1.  code needs to be cleaned ( I inherited much of the property nodes and such) 

2. I don't want users to change those things outside of the loop, which is why I moved them there. 

3. The stuff before the okay is for file naming and saving. 

4.  I do want to make this smaller but do not have the time as of yet. 

5. Timing Loops have been considered, do they work if I do not know the total time of execution of the loop prior to it executing.

6. My main question is better set as if I have two while loops inside a single case structure, one samples analog output every 1 sec and 100 samples. The other has random intervals before changing digital outputs (random as in waits either 10, 11, or 12 secs). How do I make sure these while loops start at the same time, and do not vary greatly in their timing ( as I record the digital outputs along with other signals).

 

Hopefully now you can provide more appropriate help. 

 

Message 4 of 8
(1,165 Views)

As for the indicator and local variable, that was a mistake.

0 Kudos
Message 5 of 8
(1,160 Views)

@SamDussen wrote:

1. I do not want the ability to change these controls during the run. ( I use this code for technicians to run a set paradigm that, I must restrict from mistakes where they may accidentally change things during the run. 

2. I believe the property node is more efficient (see:

 

 


  1. In your implementation, the controls need to be set before even running the VI. A proper program should never be in edit mode when used.
  2. That ancient post is wrong and you did not even bother reading the entire thread up to my post. Property node force a thread switch and execute synchronously. That gets very (very!!!) expensive quickly if you constantly do it.
Message 6 of 8
(1,146 Views)

@SamDussen wrote:

6. My main question is better set as if I have two while loops inside a single case structure, one samples analog output every 1 sec and 100 samples. The other has random intervals before changing digital outputs (random as in waits either 10, 11, or 12 secs). How do I make sure these while loops start at the same time, and do not vary greatly in their timing ( as I record the digital outputs along with other signals).

 

 


Seems like your goal is to synchronize the analog output and digital output, I would recommend you omit DAQ Express VI and use the DAQmx API. See Learn 10 Functions in NI-DAQmx and Handle 80 Percent of Your Data Acquisition Applications

You can refer to DAQmx Multifunction Synchronization with Shared Sample Clock for your application.

-------------------------------------------------------
Control Lead | Intelline Inc
Message 7 of 8
(1,084 Views)

Your Block Diagram is about 6 Laptop Screens wide by two Laptop Screens tall.  Impossible to comprehend and understand.  There is little organization, no way to understand the flow of logic, no encapsulations of the trivial details (i.e. no sub-VIs to "Initialize Parameters" or "Save Data to Disk"), and reliance on the Dreaded DAQ Assistant, the DDA (instead of using simple DAQmx calls -- you really only need to learn 5 or so, so do read "Learn 10 Functions in NI-DAQmx ..." and you'll be rid of the DDA forever!.

 

You might not need to start "simultaneous while loops".  I can't tell what you are doing, but if you have several loops that run at the same speed and start at the same time, they can be started in the same While Loop.

 

I suggest that you "start small".  Figure out what the critical Task(s) are, forget about the fancy Front Panel, and write a little routine that sets up you two or three "simultaneous Tasks" and see if you can get them to start and stop at the same time.  You'll set them in advance, then bring them both into the Loop where they both acquire (I'm assuming they run at the same rate, or at least can by synchronized with the timing of their enclosing Loop).

 

Bob Schor

Message 8 of 8
(1,025 Views)