NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Launch actions of an asynchronous thread in a main sequence

Solved!
Go to solution

Hi,

 

In my application i have 2 threads :

- A main thread : the test sequence

- A second thread : It sets some parameters asynchronously corresponding to different actions types that the test sequence has to make

 

These actions have to be possible at any step of the test sequence. the different possible actions to do are :

- Stop the test sequence (go to the cleanup part of the sequence)

- Set Pause the test sequence

- Call another subsequence

- Repeat the current step

 

In order to do that, I use the post action options to make it possible at each step. There is an example of my first try to integrate it attached to this post. In this example, I create a very simple asynchronous thread where I update a value of a variable considering that one action corresponds to a particular value of this variable (see the StationGlobals variables in this file).

 

The problem with this way to do is that I will need for other reasons (for example a test failure) to use the post action options but that is not possible with this.

 

Do you know better ways to allow an asynchronous thread to provok actions in a main sequence ? If no how can I improve my sequence ?

 

Thanks for your help

 

Configuration

TestStand Engine Version:4.2.1(4.2.1.83)

Sequence editor 4.2.1.83

Licence: development system

OS: Windows XP

 

 

 

 

 

 

0 Kudos
Message 1 of 12
(7,069 Views)

Hi,

 

Thank you for posting on National Instruments' Forum.

 

I found a tutorial on the thread. I hope this tutorial help you.

 

The web link is: https://www.ni.com/en/support/documentation/supplemental/06/when-to-run-a-sequence-in-a-new-executio... .

 

If necessary, contact me again.

 

 

Brice S.
National Instruments France

0 Kudos
Message 2 of 12
(7,057 Views)

Hi Brice,

 

Very interesting tutorial Smiley Happy

The main problem that I have to solve is that the main goal of this asynchronous thread in my application is to drive the test sequence thread. I mean that this asynchronous thread has to be able for example to stop the test sequence or provoks calling another sequence in the test sequence . The other difficulty is that it must be possible at any step of the test sequence.

 

That is exactly what I do not really understand, how it is possible to do it,. Maybe with ActiveX API ?

 

Thanks for your help

 

 

0 Kudos
Message 3 of 12
(7,053 Views)

Hi,

 

Ok, I understand your problem.

 

Watch this weblink :

It explains how to manage events and sequences.
I hope it will help you advance for this moment.
Merry Christmas.

Brice S.
National Instruments France

0 Kudos
Message 4 of 12
(7,050 Views)
Solution
Accepted by topic author potpi

You can use a SequenceFilePostStep callback sequence rather than a post action. It is a special sequence that will be called after each step executes and you can put whatever you want into that sequence. To create such a sequence use the Edit->Sequence File Callbacks... menu item and add the SequenceFilePost step callback sequence to your file.

 

Please note that this will have an affect on execution speed since a sequence will now get run after each step, however if your steps are doing a significant amount of work and you don't have that many of them, the difference might not be significant.

 

NOTE: I haven't looked at your sequence at all, but make sure you are using a lock or other synchronization primitive to protect access to any global data shared between threads.

 

Hope this helps,

-Doug

Message 5 of 12
(7,016 Views)

Hi,

 

At first happy new year ! Smiley Very Happy  

and thanks for all your answers Smiley Wink

 

@Brice S.

I am not sure that I clearly understand the main use of UI messages: do they only allow to indicate the state of the execution in messages ?

 

@Doug:

I try to use as you recommended to me the SequenceFilePostStep to solve my problem. Steps of this SequenceFilePostStep are executed in the main thread but in the second too and that does not work because of that.

Why ? Because I update an interruption value corresponding to one particular action in the second thread. And to avoid doing twice the same action, I set OFF this value during the SequenceFilePostStep steps. But considering that the second thread executes SequenceFilePostStep too, the actions are executed in the second thread but never in the main thread because the value is set OFF after each end of SequenceFilePostStep executions. I hope I was clear.I attach the corresponding sequence file if it is not: asynchronousActions3.seq

 

@All

Does it exist a way to make it 100 % asynchronous ? I am trying to use statements to drive my main sequence using thread API. For example thread.stepOver(), ...

I store correctly the Id of the thread corresponding to the main sequence with "RunState.Thread.Id". but when I try to execute in the second thread "RunState.Execution.GetThread(index).SetStepOver()", the execution crashes. Here this is the message of the generated report : "Error in call to TestStand API member 'Execution.GetThread'.
Specified thread index '27' is not valid. [Error Code: -17300, Value invalid or out of range.]"

 

I attach my sequence file (asynchronousActions4.seq) if it is not clear.

 

 

Thanks for your help

 

 

 

Download All
0 Kudos
Message 6 of 12
(6,962 Views)

Considering another behaviour for my application, I do not need a second thread anymore so the method with SequenceFilePostStep works !

 

Thanks for your help Smiley Very Happy

0 Kudos
Message 7 of 12
(6,958 Views)

This is a bit late but I found a useful example while trying to create a similar behaviour with an asynchronous VI that monitors variables in the main sequence while it executes and allows the user to stop the sequence at any point and send it to the clean-up of the caller sequence:  http://zone.ni.com/devzone/cda/epd/p/id/6254 

 

This works great however I have two problems that may be unique to my sequence I am now trying to address:

 

1.  How to stop an external sequence that is called by the main sequence.  The example above shows how to stop the caller sequence but if the caller launches another sequence, then the process will not stop until the code returns to the main sequence.  I think I need to set a flag parameter that is passed by reference to the external sub sequence and then do a post step call in the external sub sequences to see if this flag has been set.  Let me know if anyone has other ideas.

 

2.  The asynchronous sequence does not monitor errors in the caller sequence or the other external sub sequences.  I just notice that the data stops updating on my asynchronous VI and when I click stop/abort, then I receive a pop up of an error in the caller sequence.  Any ideas how to monitor errors from the caller sequence or external sequences the caller sequence calls with the asynchronous VI?  Should I pass the error as a parameter by reference to the asynchronous VI?

 

-Brian

0 Kudos
Message 8 of 12
(6,694 Views)

Brian,

 

1) For "external sequence" do you mean a sequence called in the same thread, a new thread, or a new execution? Why not just call Terminate() on the execution? Terminate() on an execution will cause all threads in the execution to go to cleanup.

 

2) Why do you need your VI to monitor errors? What exactly are you trying to accomplish?

 

-Doug

 

 

 

0 Kudos
Message 9 of 12
(6,684 Views)

Let me clarify a bit.  The monitoring VI is launched via a sub sequence that is part of the sequence file, not external, but is launched in a separate thread.  Bascially I duplicated what is in the example that I posted a link to.

 

The monitoring VI shows info on how many tests are complete, how much time has passed since start and values of critical test outputs so you have feedback while the test is running.  This VI since it is in a separate thread, will not stop or show info if an error comes up in the main sequence that launched the monitoring VI.  So if you have an instrument drop off, a wrong file name, etc. you do not see the TestStand error until you exit/stop the monitoring VI.   I need a way to have the monitoring VI see errors from the main sequence and any sub sequences that the main executes.  Some of my subsequences are external to the main program.  They are in the same execution and same thread I think.

 

Thanks,

Brian

0 Kudos
Message 10 of 12
(6,664 Views)