NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Sync between main and parallel thread

I'm using TS 2014 SP1 and here's what I'm running into and need help on.

 

I have a main sequence that spins off a new thread. The new thread generates a freq from NI card and it runs in the background for 2 seconds. This sequence needs to be running in order for the main sequence to read the freq that's being generated in the new thread. Once the freq is read, I "unload" the step that produces the new thread by using unloadmodule() step. I put in a wait for 2 seconds and then we move to the next channel and repeat the above steps. The wait step was to make sure the new thread stopped executing before moving to the new channel. Each channel has a different frequency we test.

 

Problem: While i'm able to read the right value most times, I occassionally get a value of 0. I believe it's becuase of a synchronization issue. Either the thread isn't stopping or there is a miss in the handoff value and it ends up being 0.

Any example to show how this can be done will be appreciated!

0 Kudos
Message 1 of 5
(3,380 Views)

Why does it need to be spun off in a new thread?  Just call it and have it return the value if it is only 2 seconds.

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 2 of 5
(3,359 Views)

@~jiggawax~ wrote:

Why does it need to be spun off in a new thread?  Just call it and have it return the value if it is only 2 seconds.


B/c MihirKiran needs to generate, and measure at the same time - so parallelism is needed.

@MihirKiran wrote:

The new thread generates a freq from NI card and it runs in the background for 2 seconds. This sequence needs to be running in order for the main sequence to read the freq that's being generated in the new thread.

 


 I propose two ways, and one comment.

Comment: you don't need to do step unload. This is just overhead. You should implement code module in a way, that it will simply stop execution, when generation is finished.

  1. Is it possible to combine two code modules into one - for generation, and measurement at the same time? Then you don't need to care about handling of TestStand parallel threads; you'll have just two parallel loops inside of one VI.
  2. If you want anyway to do it via TestStand, then you can use the following approach. You have some flag, which indicates whether parallel thread is running, or stopped. Values of flag are setup in Setup and Cleanup sections of subsequence. And in your "upper" sequence, where you measure, after measurement, you just wait till your flag-variable will indicate, that parallel thread stopped running. Hopefully, screenshots will explain it more.

Generate Frequency.PNG

 

 

Main Sequency.PNG

 

logos_middle.jpg

Message 3 of 5
(3,329 Views)

I'll need to generate and measure at the same time.

0 Kudos
Message 4 of 5
(3,312 Views)

thank you kosist90! The screenshots are very helpful. I'll try it out in my code and see if that resolves my issue! 🙂

0 Kudos
Message 5 of 5
(3,311 Views)