From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Creat a Timer (How to execute a Step for a specific time)

Solved!
Go to solution

Hi everyone,

 

I'm new with the TS and wanne execute a step for only 5 seconds. When the time is over the step can not be executed anymore. 

I could't find any timer function like programming languages. Could you please help me. I really appreciate it. 

Thank you. 

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

do you mean some kind of max time limit for execution?

 

A step will execute as long as the code module execution completes because TestStand passes the execution to the respective language to complete the execution and TestStand will not have control to abort the code module execution mid-way as it is not under its control.

 

If needed, you need to implement a technique within the code module to stop execution after the timeout period.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 8
(1,316 Views)

Thank you for your reply.

 

Yes exactly. I just wanne the timer to start when the step is beeing started. after 5 seconds the step must be stoped. 

 

 

 

0 Kudos
Message 3 of 8
(1,312 Views)
Solution
Accepted by topic author navid.mo2

TestStand will let you set Station Options for an execution time limit which when expired will terminate the execution or allow a prompt to be displayed for user to decide the action. 

You can control the Time Limit settings dynamically using expression steps

  • In an expression step before your module step use the following (this will set a max time of 5 seconds):
    • RunState.Engine.StationOptions.SetTimeLimitEnabled(TimeLimitType_NormalExecution, TimeLimitOperation_Executing, True),
      RunState.Engine.StationOptions.SetTimeLimitAction(TimeLimitType_NormalExecution, TimeLimitOperation_Executing, TimeLimitAction_Terminate),
      RunState.Engine.StationOptions.SetTimeLimit(TimeLimitType_NormalExecution,TimeLimitOperation_Executing, 5),
  • In an expression step after your module step use the following to "turn off" the Time Limit
    • // set time back to 10 second default. This allows time enough to toggle other options when enabled later
      RunState.Engine.StationOptions.SetTimeLimit(TimeLimitType_NormalExecution,TimeLimitOperation_Executing, 10),
      RunState.Engine.StationOptions.SetTimeLimitEnabled(TimeLimitType_NormalExecution, TimeLimitOperation_Executing, False)

Use these constants for the value of the StationOptions.SetTimeLimitAction and StationOptions.GetTimeLimitAction methods.

  • TimeLimitAction_Abort–(Value: 0) Initiates an abort of a running execution.
  • TimeLimitAction_KillThreads–(Value: 1) Ends the thread for a running, terminating, or aborting execution.
  • TimeLimitAction_Prompt–(Value: 2) Launches a dialog box with the option to terminate, abort, or kill the execution.
  • TimeLimitAction_Terminate–(Value: 3) Initiates a termination of a running execution.

 

I like to label my expression steps "Watchdog On" and "Watchdog Off".  Could also easily setup a Sequence call to pass a "time" parameter to make it user friendly for changing time requirements.

0 Kudos
Message 4 of 8
(1,243 Views)

@ee-jallen wrote:

TestStand will let you set Station Options for an execution time limit which when expired will terminate the execution or allow a prompt to be displayed for user to decide the action. 

You can control the Time Limit settings dynamically using expression steps

  • In an expression step before your module step use the following (this will set a max time of 5 seconds):
    • RunState.Engine.StationOptions.SetTimeLimitEnabled(TimeLimitType_NormalExecution, TimeLimitOperation_Executing, True),
      RunState.Engine.StationOptions.SetTimeLimitAction(TimeLimitType_NormalExecution, TimeLimitOperation_Executing, TimeLimitAction_Terminate),
      RunState.Engine.StationOptions.SetTimeLimit(TimeLimitType_NormalExecution,TimeLimitOperation_Executing, 5),
  • In an expression step after your module step use the following to "turn off" the Time Limit
    • // set time back to 10 second default. This allows time enough to toggle other options when enabled later
      RunState.Engine.StationOptions.SetTimeLimit(TimeLimitType_NormalExecution,TimeLimitOperation_Executing, 10),
      RunState.Engine.StationOptions.SetTimeLimitEnabled(TimeLimitType_NormalExecution, TimeLimitOperation_Executing, False)

Use these constants for the value of the StationOptions.SetTimeLimitAction and StationOptions.GetTimeLimitAction methods.

  • TimeLimitAction_Abort–(Value: 0) Initiates an abort of a running execution.
  • TimeLimitAction_KillThreads–(Value: 1) Ends the thread for a running, terminating, or aborting execution.
  • TimeLimitAction_Prompt–(Value: 2) Launches a dialog box with the option to terminate, abort, or kill the execution.
  • TimeLimitAction_Terminate–(Value: 3) Initiates a termination of a running execution.

 

I like to label my expression steps "Watchdog On" and "Watchdog Off".  Could also easily setup a Sequence call to pass a "time" parameter to make it user friendly for changing time requirements.


My understanding is those settings are for the whole execution whereas the OP wanted this to be configured per-step.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 5 of 8
(1,240 Views)

@santo_13 wrote:

@ee-jallen wrote:

TestStand will let you set Station Options for an execution time limit which when expired will terminate the execution or allow a prompt to be displayed for user to decide the action. 

You can control the Time Limit settings dynamically using expression steps

  • In an expression step before your module step use the following (this will set a max time of 5 seconds):
    • RunState.Engine.StationOptions.SetTimeLimitEnabled(TimeLimitType_NormalExecution, TimeLimitOperation_Executing, True),
      RunState.Engine.StationOptions.SetTimeLimitAction(TimeLimitType_NormalExecution, TimeLimitOperation_Executing, TimeLimitAction_Terminate),
      RunState.Engine.StationOptions.SetTimeLimit(TimeLimitType_NormalExecution,TimeLimitOperation_Executing, 5),
  • In an expression step after your module step use the following to "turn off" the Time Limit
    • // set time back to 10 second default. This allows time enough to toggle other options when enabled later
      RunState.Engine.StationOptions.SetTimeLimit(TimeLimitType_NormalExecution,TimeLimitOperation_Executing, 10),
      RunState.Engine.StationOptions.SetTimeLimitEnabled(TimeLimitType_NormalExecution, TimeLimitOperation_Executing, False)

Use these constants for the value of the StationOptions.SetTimeLimitAction and StationOptions.GetTimeLimitAction methods.

  • TimeLimitAction_Abort–(Value: 0) Initiates an abort of a running execution.
  • TimeLimitAction_KillThreads–(Value: 1) Ends the thread for a running, terminating, or aborting execution.
  • TimeLimitAction_Prompt–(Value: 2) Launches a dialog box with the option to terminate, abort, or kill the execution.
  • TimeLimitAction_Terminate–(Value: 3) Initiates a termination of a running execution.

 

I like to label my expression steps "Watchdog On" and "Watchdog Off".  Could also easily setup a Sequence call to pass a "time" parameter to make it user friendly for changing time requirements.


My understanding is those settings are for the whole execution whereas the OP wanted this to be configured per-step.


Try it, create a sequence with 4 steps

  1. Create the "Watchdog On" step
  2. Create a MessagePopup step with a 6 second timeout
  3. Create the "Watchdog Off" step
  4. Copy and paste the message Popup step

Run the sequence.  The Popup will show and before the count down is done the Time Limit will terminate the execution.  Now run the sequence again.  This time, click the OK on the first prompt, so you don't time out.  Test will proceed, will turn off the Time Limit, then the 2nd Popup will display....allow it to count down and it will close successfully and the test sequence will not be terminated.

 

TestStand honors the new settings dynamically.

 

The OP could even experiment with putting the Watchdog On and Off statements in the Pre and Post properties of the step.

0 Kudos
Message 6 of 8
(1,226 Views)

Thank you so much @ee-jallen 

It worked correctly. 

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

I would also note that if you are calling code that you have control over then you should implement TestStand Termination Monitor in your code.  You can find an example and topic in the TestStand help.  The time limit settings will indeed signal a termination however if your code performs long actions and you need immediate response then use the Termination Monitor API in your code.  The example I explained in my answer uses a native TestStand MessagePopup step which I imagine honors immediate termination signals via Termination Monitor or some other internal mechanism

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