LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Running two tasks simultaneously

Hi All,

I have a problem to run two tasks simultaneously, see attached picture. I'd like the "execute first" and "execute second" to run at the same time so that the elapsed time will be the same. In this current code, the "execute first" will run first and then "execute second" will run later. Any suggestion to improve this problem.

 

Thank you,

Drake

0 Kudos
Message 1 of 31
(5,561 Views)

LabVIEW use Data flow principle.

Use the error wire to synchronize the two required task.

Please clean your code. Smiley Mad

 

Benoit

0 Kudos
Message 2 of 31
(5,538 Views)

Hi Drake,

I see your arrows point to the wires, but the wires do not execute, the wires connect the nodes with each other and hold the data.When you watch the Block Diagram in Highlight Mode you see the data flowing from nodes which finished execution to nodes which are waiting for data to start execution.

When running the VI, the data in control 'Sampling Rate' is ready and can flow directly to the next nodes, the data on 'Execute Second' is not ready yet, because the timing node has to run first.

Beside the error wire you can you a Flat Sequence Structure to force a special execution order.

UliB

0 Kudos
Message 3 of 31
(5,531 Views)

ARRGHHH... Never suggest a flat sequence... it creates messy code

ERROR bus it the proper way and should be the only way. By doing so, you can manage exception, error and warning in your code. Therefore, you will code like a pro.

Benoit

0 Kudos
Message 4 of 31
(5,528 Views)

@bseguin wrote:

ARRGHHH... Never suggest a flat sequence... it creates messy code


I disagree.  Sometimes a flat sequence is required, especially if the VI in question doesn't have an error wire (such as the timestamp function in this question). 

 

Having said that, the question is still not clear to me.  I only see one task in this SCREENSHOT (post code) and it is the DAQmx task.  A constant and a timestamp are not tasks...they are constants stored in a variable (the wire).  It doesn't make sense that these constants need to be executed at the same time.   

aputman
0 Kudos
Message 5 of 31
(5,497 Views)

You need to do two things:

  • Post your VI!  We can't do much with a picture (have you ever tried to execute a picture?  Would you like to help debug a multi-page C++ program if you only had a picture of the code?).
  • Describe, in words, what it is you want to do.  What are the two tasks that you want to run "simultaneously"?  Do you want them to start at (roughly) the same time?  To "time-share" the CPU and execute as though they were running independently?  Do they need to communicate with each other?  Does it matter the order in which they finish?

You need to learn about the Principle of Data Flow, which determines how LabVIEW executes code and how the order of functions and code are defined.  A key concept is whether or not there are any "dependencies" of one piece of code on another -- are they connected by "wires", for example, or are they inside the same Structure?

 

Bob Schor

0 Kudos
Message 6 of 31
(5,487 Views)

Hi there,

 

I think the real issue you had is that the while loop stops, because the "Get Date/Time" function executes when the vi starts and not just before the loop starts. But this has nothing to do with running tasks simultaneously.

 

My simple suggestion is this:LVexample.PNG

With this simple frame you can force the execution of the Get Date/Time function to be done between the Start DAQ task and enter loop.

 

Regards

Kay 

 

 

Message 7 of 31
(5,484 Views)

@aputman wrote:

@bseguin wrote:

ARRGHHH... Never suggest a flat sequence... it creates messy code


I disagree.  Sometimes a flat sequence is required, especially if the VI in question doesn't have an error wire (such as the timestamp function in this question). 

 


I have to agree with Benoit here, the flat and stacked sequence both should be deprecated.

 

But to your example a SINGLE FRAME sequence with an error cluster running through it for sequencing is the only time a Flat Sequence should be used.

========================
=== Engineer Ambiguously ===
========================
Message 8 of 31
(5,479 Views)

@RTSLVU wrote: 

But to your example a SINGLE FRAME sequence with an error cluster running through it for sequencing is the only time a Flat Sequence should be used.


So you agree that a flat sequence has a purpose.  It's also useful for bench-marking, even though bench-marking can be accomplished without it.  I whole-heartedly agree that the stacked sequence should go and if it went, I would never look back.  Smiley Wink

 

aputman
0 Kudos
Message 9 of 31
(5,466 Views)

Sure, but an extremely limited purpose.

 

NI could replace that with some kind of "container" for flow control of VI's and primitives that don't have an error cluster and deprecate sequences all together.

 

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 10 of 31
(5,461 Views)