LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Timing loop for running a test process

This screenshot is a representation of the test loop (simplified from the real thing).  It shows a nested while loop that checks for a stop/pause condition and stays there (inside a for loop) until the pause is false or stop is true.  It enters the while loop at every iteration of the for loop. and while the test is running, it will always exit immediately.  The key feature I want to call your attention to is that it writes to the "Control State" local variable, because a secondary loop I have on the side reads from it.

Psquared_1-1746197282300.png

This is the secondary loop that runs outside of the main loop.  When the control state is "Running", it updates the time remaining on the UI every 100 ms.  If it is in a state other than "Running" (i.e. "Pause"), it checks for a change of state every 1000 ms until it changes back to "Running".

Psquared_0-1746196084504.png

 

I had a C# timer in mind when I did this loop.  I run the timing loop externally to the main control loop because the program spends most of its time in the for loop.  The disturbances it has to run can be as lengthy as 30 seconds, so I wanted to have a timer that would tick in real time while the cycle is executing.  

 

My question, finally ...... is there a "better" way to handle a test timer?  I would use the same logic in other testing programs so my hope is to make it cleaner, more elegant, and portable.  In C# all I have to do is tweak a property to "false" to stop the timer from running, but I'm not seeing how to do that here ...... unless I'm just not looking in the right place.

 

0 Kudos
Message 1 of 3
(137 Views)

We don't "do" code pictures (too many hidden and ambiguous things), but since your control is outside the loop, it will only get read once and never again. After the loop starts, the case can never change again.

I don't think you need that many local variables.

 

Once you attach your VI (do a "save for previous, 2020 or below first), we can give more specific advice.

 

Instead of high pyramids of stacked structures, all you probably need is a simple state machine.

0 Kudos
Message 2 of 3
(116 Views)

@Psquared wrote:

 

My question, finally ...... is there a "better" way to handle a test timer?  I would use the same logic in other testing programs so my hope is to make it cleaner, more elegant, and portable.  

 


Yes a State Machine would be a far better architecture for this and most tests. When you get to more complex test programs that are "scripted universal tests" instead of a program that just does one test, a Queued Message Handler or Channel Message handler are more appropriate.  

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 3
(102 Views)