Virus scan in progress. Please wait to download attachments.
This example demonstrates how you can quickly create tools to programmatically edit one or more sequence files using the ForEach.seq sequence file that ships with TestStand.
When working with many large sequence files, it is often useful to be able to quickly update all of your files programmatically. There are many approaches you can use to accomplish this:
For simple changes, you can use the Find/Replace tool. For example, updating a certain expression to a more recent implementation.
If you need to detect where changes are needed without actually making updates, you can use the sequence analyzer with custom rules to detect cases where an update is needed.
For more involved changes, you will need to utilize the TestStand API to create an update tool. Creating such a tool can be complex, since it requires you to implement the following functionality:
Obtain a list of sequence files to operate on, and manage the references to the files.
Iterate over each step in all of the selected sequence files.
Detect the condition that you want to update.
If the specified conditions are met, update the step.
To make the process of creating update tools easier, TestStand includes a sequence file which implements much of the required functionality for you. This sequence allows you to define a callback sequence which runs for each step, sequence, or sequence file in a list of sequence files. The sequence files to operate on can be specified as a list or as a directory containing the files. This sequence file is ForEach.seq, and is located in the <TestStand>/Components/Tools Directory. To create a sequence update tool with this method, follow these steps:
Create a new sequence file.
Create a sequence call step, and specify the ForEach sequence file in the File Pathname field.
Select a sequence based on the type of iteration you need. The iteration sequences have the prefix ForEach, for example:
ForEachStepInDirectory - execute a callback for each step in each sequence file in the specified directory.
ForEachSequenceInFileList - execute a callback for each sequence in each sequence file in the specified list of sequence file paths.
Create a new variable to store the configuration settings for the ForEach sequence. Right click on Locals, and selectInsert Local » Type » CallbackData, then name the variable.
Add a new statement step before the sequence call to configure the variable. Enter the following expression to configure the local variable://configures the ForEach sequence to look for the plug-in sequence in your sequence file Locals.sequenceCallback.seqFile = RunState.SequenceFile, //configures the Name of the callback Sequence that will be called Locals.sequenceCallback.sequenceName = "ForEachCallback"
Select the sequence call step, and set the local you created as the CallbackData parameter. configure the other parameters based on the desired behavior:
SearchPath- for directory-based tools, this is the directory to operate on. You can use the engine.DisplayFileDialog method to prompt the user for a directory.
Recurse- for directory-based tools, determines whether to operate on files in subdirectories of the selected directory.
saveFile- whether to save the sequence files that the tool has operated on.
processedFiles(out) - a list of all files that were operated on.
In your sequence file, create a new sequence. Rename the sequence to match the sequenceName property above (in this case, ForEachCallback).
Add a new object reference parameter to the sequence, and name it Data. This parameter will contain a reference to the current file, sequence, or step that the tool is operating on, depending on the iteration sequence you chose.
You have now created the framework for your tool. In the callback sequence, implement the code to check for the desired condition and make the required changes using the TestStand API. Use Parameters.data to access and modify the current step, sequence, or sequence file being operated on.
Refer to the attached example to see a tool implemented in this way. The attached example examines all step modules for absolute paths, and replaces them with relative paths if the module name can be found using the TestStand search directories.
Hardware and Software Requirements
Fix Absolute Module Paths_NIVerified.zip
TestStand 2010 or Compatible
Analyze Paths Legacy_NIVerified.zip
TestStand 2.0 or Compatible
LabWindows/CVI 5.5 or Compatible
Steps to Implement or Execute Code
Open the example sequence file.
Run the MainSequence using Single Pass, then select the directory to operate on when prompted. You can test the example by creating a sequence file with code modules specified by absolute paths.
Once the example completes, view the report to see the module paths that were fixed by the tool.
Mark M. Applications Engineering National Instruments
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.