NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Launching a sequence in a new thread using the Batch Model

Using TestStand 4.2, and I am trying to do my first sequence using the batch model.  I have a working sequence using the sequential model, but I realized the custom reporting I need to do will be somewhat difficult and convoluted using the test sequence.

 

The issue I am having is that within one UUT, I need to run some tests in parallel.  In this case, I have a sequence which pushes buttons and verifies their functionailty, and another sequence that verifies the illumination LEDs are functioning properly.  These tests are completely independent, and in the sequential model, I have the sequences set to launch in a new thread so that they run in parallel.

 

When I switched over to the batch thread, this no longer appears to work.  I have some hardware setup within the sequence which only needs to run for the first thread that reaches it.  If I launch the sequence in a new thread, it appears to launch 12 instances of it, but the items within the sequence marked for first thread only are executed by every UUT.  And it appears that the UUTs do not run the sequences syncronized.  If I change the sequence call to not launch in a new thread, the test runs fine.  The issue is that I can no longer run the LED test and button test in parallel.

 

Is there a way to get this to work?  I have also noticed that the sequence runs significantly slower in batch mode.  Is this normal?  It may end up being better for me to run in sequential mode and deal with the convoluted reporting if the tests are going to run significantly slower.

 

Thanks,

Matthew

0 Kudos
Message 1 of 10
(7,392 Views)

Hi Matthew,

 

When using the batch model, you will need to make sure that you implement synchronization, using either the lock step types or the synchronization settings within the step (this method is a bit easier).  From what you are saying, I would recommend sticking with the sequential model and using an asynchronous sequence like you mentioned in the first paragraph - the batch and parallel models are meant more for conducting multiple instances of the same code simultaniously rather than different code.

Al B.
Staff Software Engineer - TestStand
CTA/CLD
0 Kudos
Message 2 of 10
(7,368 Views)

Al,

 

I attached an example sequence showing my problem.  I am not sure I was clear on what I was doing.  I am not trying to run different code on different UUTs.  The same code should run on all UUTs, but testing within one UUT can be done in parallel.

 

The attached example calls two sequences.  Both sequences just display a pop-up dialog.  In both, the pop-up should only be displayed for the first socket.  You will see when calling Seq1, that only one pop-up is displayed.  Seq2 is launched in a new thread.  You will see that despite the fact the pop-up is supposed to only execute for the first socket, it executes for all sockets.  And the complete mesage pop-up in the main sequence executes as soon as Seq2 completes, so the sockets aren't all waiting for Seq2 to complete before moving to the next step.

 

Is there a way to launch a sequence in a new thread without breaking batch mode?

 

Thanks,

Matthew

Message 3 of 10
(7,364 Views)

Hi Matthew,

 

The behavior you are demonstrating is actually expected behavior, but there is a method which will allow batch synchronization of subsequences called in a new thread.  The reason this behavior is occuring is because TestStand does not create the new subsequence threads within the batch being used with the main threads - the threads are created with no batch association, and are treated as a one-thread batch by any batch synchronization functions.  To put the new subsequence threads into a batch, we will need to manually create it using the batch specification step.  This process is demonstrated in the attached sequence file. 

 

In this file, a new subsequence (called synchronously from the main sequence) gathers the asynchronous thread references and incorporates them into a new batch. As the asynchronous threads are created, the thread references are stored to a local variable (the thread reference is accessible in the advanced options of the asynchronous sequence call).  This local is then passed as a parameter to the batch compilation sequence, and once all of the new threads are in the new batch, the asynchronous threads begin executing (a notifier is used to make sure nothing runs until the batch is completely created and populated). Now that the new threads are all included in a single batch, the batch functions work as expected.  Let me know if you'd like any more clarification or if you have any other questions!

Al B.
Staff Software Engineer - TestStand
CTA/CLD
Message 4 of 10
(7,330 Views)

Ai,

  I am trying to do same as you posted in  example in my code for launching new parallel thread but I am not getting 'Nothing' in the variable "parameter.thredref", as it is not valid thread reference add new thread not working for. I have mainseq inthat calling calibration as subsequence and inside that seq I have for loop to get sample there I need to launch new thread as parallel to the batch module threads, could you please guide me how I can get the new thread as parallel to batch threads

0 Kudos
Message 5 of 10
(6,024 Views)

Hi Paddi,

 

The problem may be that you did not specify to store the thread object reference.  This option is accessible by selecting the Advanced settings button in the module tab of the sequence call step (asbutton.png), then specifying the locals.threadref  property in the advanced settings dialog:

 

2012-09-27_130104.png

 

Let me know if you are still encountering problems!

Al B.
Staff Software Engineer - TestStand
CTA/CLD
Message 6 of 10
(5,997 Views)

AI, Thank you very much. I will try this and let you know, this will help me lot....

0 Kudos
Message 7 of 10
(5,991 Views)

AI,Thanks again It worked for me.

       Got one more glitch here, actually I am calling this new thred inside for-loop where Batch threads will collect samples from UUt and New launched thread will collect samples from reference instrument.and both UUT and reference instrument having different scan rate Ex. UUt finish sample in 1 second, where Reference needs 5 second to collect samples, so my question is how I can get both things i.e.batch and new thread in synch so that all threads will wait at beginning of FOR loop to get ready for second sample, so that sampling count mismatch will not happen between batch thread and new launched thread as those reference and UUT samples get compared finally in program, also new thread should stop after each sample or wait still uut sample get over... plz suggest me possible solution

0 Kudos
Message 8 of 10
(5,979 Views)

If all threads involved are part of the same batch, use batch synchronizations step types. If not, use rendezvous step types.

 

Hope this helps,

-Doug

0 Kudos
Message 9 of 10
(5,975 Views)

An alternative to using the notifier, is suspending the thread, and resuming in when the batch is created.

 

Suspend Thread.png

 

Resume Thread.png

 

PS: I realize this is an almost ancient thread, but it came up when googling, because I had the same problem as Matthew_Kelton, so I thought I will share this input anyway.

The modified sequence uploaded is in version 2014.

0 Kudos
Message 10 of 10
(4,790 Views)