NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help Navigating Through Subsequences in TestStand Using Python

Solved!
Go to solution

Hello everyone,

I'm working on a project involving TestStand and Python. I aim to optimize the runtime of a TestStand sequence by pre-fetching global variables and step-specific information for each step in the main sequence and its subsequences. This is to efficiently populate a custom test report.

What I'm Trying to Do:

  • I plan to run a Python script as a module in TestStand before initiating the main sequence.
  • This Python script is designed to traverse the main sequence and its subsequences to fetch information like TestStepName, FileGlobals.Test_Sequence, FileGlobals.xx, etc.
  • My current sequence already fetches this information but does so inefficiently by querying the TestStand API during each step of the sequence through LabVIEW VIs. The goal is to make these VIs purely functional for tasks like measurements, reading LIN frames, sending LIN frames, etc., and to fetch test results when necessary.

Issue:

  • My existing Python script runs into an infinite loop because I can't seem to access the context of the subsequences.
  • While the script can successfully navigate the main sequence to fetch required information, it fails to enter any subsequences to evaluate their steps.
  • I need guidance on how to access the context for each subsequence so that my script can recursively fetch the information for all steps.

I've consulted the TestStand API documentation but have not found a clear solution to this issue.

Has anyone else faced a similar challenge or has any suggestions on how to resolve this? Your insights would be much appreciated.

Thank you in advance.

0 Kudos
Message 1 of 5
(1,108 Views)
Solution
Accepted by Eder22

My understanding is that the script is to be run, before the MainSequence (and its subsequences are run) 

If so, trying to access properties via RunSate might not work properly, since teh Sequences are actually not running.

 

Possible solution: open the sequence file, parse for sequence calls, store the call targets and then parse each of the sequences called.

 

From where are you calling the script? From the model?

 

Message 2 of 5
(1,073 Views)

Hello Oli,

Thank you for your response!

Yes, I'm calling the script from the predefined execution model. My intent is to run the script before the MainSequence and its subsequences actually execute, aiming to preprocess and gather information prior to the real execution.

You're right in suggesting that trying to access properties via RunState might not be apt in this context. Your idea about opening the sequence file and parsing for sequence calls sounds promising. Would you have an example or recommendation on how to go about it, especially on how to identify and access the subsequences?

Any guidance or suggestions you can provide would be greatly appreciated.

Best regards,

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

I don't have the exact example of what youre looking for at hand

 

As a starting point, you can use %teststandpublic%\Examples\TestStand API\Building a Sequence Using API\TestStand Expressions

This example shows how to build a sequence file using the API which showcases the object structure quite nicely.

 

If you happen to have access to the TestStand II (Architecting Testsystems using TestStand) Course on your learner dashboard on ni.com, there is Excercise (6-2) which scans a sequence for steps of a specific type

 

 

0 Kudos
Message 4 of 5
(1,012 Views)
Solution
Accepted by Eder22

Hello Oli,

 

After several iterations, I finally came up with a solution to the functionality I was looking for in my script, you were right about your recommendations and basically I updated my script form that staring point, of course I added a lot more code with specifics associated to my application but in summary the solution was:

1. Open the sequence file (sequenceFile = engine.GetSequenceFile(sequence_filename))

2. Get main sequence form the previous call (mainSequence = sequenceFile.GetSequence(0)

3. parse sequence calls using GetSequenceByName method.

Explanation

  • The script initializes the TestStand engine and loads the specified sequence file.
  • It iterates over each step in the main sequence and any sub-sequences.
  • Regular expressions are used to extract specific pieces of information from each step.
  • It creates a list of dictionaries, each containing relevant information about the steps.

 

of course the script is a bit more complex with recursive functions called to be able to go to the entire sequences and get the info that I was looking for.

 

Conclusion

This script effectively allowed me to programmatically analyze TestStand sequences to extract the information I needed. I hope this will be helpful for others facing similar challenges.

 

Special thanks to Oli for the initial guidance.

 

Note: Attached is a simplified script version highlights the main sequence handling and recursion.

0 Kudos
Message 5 of 5
(981 Views)