NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Running Threads In Parallel

Hello everyone.  I need advice from all you TestStand gurus out there.

 

I Need to run two things in parallel:

 

1. Polling Sequence: I need to poll devices in a product continuously.  This poll just pings each device to make sure it is able to communicate with it.  If a device does not get pinged within 5 seconds the device FW will shutdown the device.  It is crucial that I continuously poll these devices to keep the product up and running.

 

2. Main Test Sequence: I also need to run a sequence to run test steps on this product.

 

My issue:

 

At certain steps in the "Main Test Sequence" I will need to tell the "Polling Sequence" (Polling Loop) to shut down so that I can free up the communication to send test commands on a device within the product.

 

I've done a bit of research on this issue.  One way I believe to do this is from my "Main Test Sequence" I could create a "Sequence Call - New Thread" step.  I could call this thread at the beginning of my "Main Test Sequence" to start it and if I come across a step in my "Main Test Sequence" that needs to access one of the devices in the product I could set a global variable step that the "Polling Sequence" would see so that it would stop or start based on this variable.

 

I am newer to TestStand and am looking for the most efficient way to do this.  What do you guys and gals think is the most efficient way to do this?

 

Thanks!

0 Kudos
Message 1 of 13
(6,852 Views)

 

 

 questions

Are you going to communicate with each board/UUT with a communication Device/USB/Serial  Independently or are you going to be switching to Share One device/usb to communicate with all the boards?

 

 

After that we can continue to make a strategy on how to do it.

 

but...

if you are not sharing resources and you have for example ONE serial port or USB/to serial convert for each UUT..

 

you could run everthing in parallel.. in testand you could build a while function to cycle your program to ping each 5 seconds...and if you want to do some other stuff  every 15 minutes you could have an IF inside the loop call a Test Sequence. and after that it will come back to the ping.

 

is it something like that what you are looking for?

CLAD, CTD
0 Kudos
Message 2 of 13
(6,830 Views)

One approach that works well for this is a notifier or queue. You would set up the sequences exactly as you described, with a monitoring/polling sequence running in a new thread concurrently with your main sequence. However, you can use a TestStand notifier (in the Synchronization folder of the insertion palette) to allow you to communicate between the two running threads. Your monitoring/polling thread should have a step in its loop which checks the notifier status and responds to new notifications as needed. When the main sequence needs the monitoring/polling sequence to pause or perform an action, it simply sends a notification to the that thread.

 

This also helps with shutdown at the end of the test program, as it provides a clean way to instruct the monitoring/polling thread to safely shut down.

 

I'd recommend this type of approach for your system--I've seen it used successfully by other customers in similar situations. Let us know if you have any additional questions about it, we're always happy to help out.

0 Kudos
Message 3 of 13
(6,802 Views)

Thanks guys.

 

Daniel-E,

 

Do you have any good TestStand examples that show how Notifications are used to communicate between threads (in this case my Polling Thread and my Main Sequence)?

 

Thanks!

0 Kudos
Message 4 of 13
(6,796 Views)

I think the simplest approach would be to just use a lock around the calls to the devices. It sounds like you really don't want to stop the polling loop, you just want it to pause while you are accessing the hardware in a different thread. If so, you can accomplish that with a lock as follows:

 

Polling thread:

 

Begin Loop

AcquireLock

Ping Hardware

ReleaseLock

End Loop

 

Main thread:

 

AcquireLock

Use Hardware

ReleaseLock.

 

Ownership of the lock then effectively gives ownership of access to the device. There are a couple of ways to use locks in teststand. You can use the Lock step type to lock around multiple steps, or use the builtin step type lock setting to lock around the execution of a single step.

 

A global variable is not a good solution because when you set the global variable you still have know way of knowing if the polling thread has checked it yet. It might still be pinging the device. While a lock guarantees exclusive access if used as described above.

 

Also, don't forget to disable result collection for your polling sequence (in the sequence properties dialog) to avoid leaking memory while that thread is looping.

 

Hope this helps,

-Doug

Message 5 of 13
(6,790 Views)

Doug, in the method you mentioned above do I need to create 2 separate locks?  One for Main Sequence and One for Polling Sequence?  Thanks!

0 Kudos
Message 6 of 13
(6,778 Views)

Doug, could you send me an example?  Thanks!

0 Kudos
Message 7 of 13
(6,777 Views)

@testdesign wrote:

Doug, in the method you mentioned above do I need to create 2 separate locks?  One for Main Sequence and One for Polling Sequence?  Thanks!


They need to be the same lock (i.e. the same lock name). The idea is that only one thread can own the lock at a time. In order to create an example, I need to know what version of TestStand you are using.

 

-Doug

0 Kudos
Message 8 of 13
(6,744 Views)

Thanks Doug.  I am using TestStand 2013.

0 Kudos
Message 9 of 13
(6,732 Views)

Here's an example. Had to zip it to get the forum to allow me to attach the file.

 

-Doug

0 Kudos
Message 10 of 13
(6,673 Views)