11-26-2020 06:10 AM
Hi.
I have 4 cases inside a loop.
In one of the cases, I want to run 3 events 10 seconds each, according to the elapsed time from the moment I entered the case:
event 1- 10 seconds, event 2- 10 seconds, event 3- 10 second (in total 30 seconds), and all this inside the loop. How can this be done?
Thanks
Solved! Go to Solution.
11-26-2020 06:45 AM
It sounds like you're describing different States of a test ... so check out the State Machine architecture.
11-26-2020 01:59 PM
@rivlin wrote:I have 4 cases inside a loop.
In one of the cases, I want to run 3 events 10 seconds each, according to the elapsed time from the moment I entered the case:event 1- 10 seconds, event 2- 10 seconds, event 3- 10 second (in total 30 seconds), and all this inside the loop. How can this be done?
Your description is way too vague! Is your "loop" a WHILE loop or a FOR loop? Do you have four case structures or one case structure with four cases? I doubt "you" are entering any cases, you are probably sitting on a chair. The term "event" has a special meaning in LabVIEW, so please clarify what you mean by it. How long does it take to execute the code in each state? Does it stay in each case for 10 seconds or keep entering the same case for 10 seconds?
Typically we can give much more precise help if you would attach a real VI containing at least a code skeleton with all the major components.
11-30-2020 07:50 AM
Hi KNIGHT OF NI
Apologies for the lack of clarity
I was under time pressure so it came out that way...
I tried to summarize the problem:
I create a while loop (attached), and a stacked sequence. There is a led outside I want to update.
It can be seen that the attempt to do so is misleading, because in fact the program is "stuck" because of the time delay.
In addition, all the other indicators (not seen in this short program) stop updating.
Is there a possibility to keep everything around work and not to be affected by the time delay?
Thanks
Yonatan
11-30-2020 08:17 AM - edited 11-30-2020 08:17 AM
Hi rivlin,
@rivlin wrote:
I create a while loop (attached), and a stacked sequence. There is a led outside I want to update.
It can be seen that the attempt to do so is misleading,
Nobody told you to use a stacked sequence. (In fact usually we advise against them, and they are even hidden from functions palette nowadays.)
You were told to implement a state machine. Why don't you do so?
11-30-2020 11:07 AM
Here is a super simple timer in a state machine to give you an idea how it's done. You could add an event structure to change states on the fly or expand it to multiple states that do different things based on the time elapsed or user input. Note that the 1 mSec Wait VI in the main loop gives good user interaction and allows other code to run but also gives some time for the CPU to run other processes.
Also look at the state machine available as a startup template and check online for lots of examples. It's an important pattern for LabVIEW and probably the most used so understand it well if you plan to advance your abilities.