11-28-2018 11:03 PM
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
11-29-2018 01:23 AM
LabVIEW use Data flow principle.
Use the error wire to synchronize the two required task.
Please clean your code.
Benoit
11-29-2018 01:58 AM
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
11-29-2018 02:06 AM
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
11-29-2018 08:52 AM
@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.
11-29-2018 09:11 AM
You need to do two things:
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
11-29-2018 09:18 AM
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:
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
11-29-2018 09:32 AM
@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.
11-29-2018 09:54 AM
@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.
11-29-2018 10:07 AM
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.