Top Banner
© 2011, H Guy Williams 1 What Is NI TestStand? Overview NI TestStand is ready-to-run test management software designed to help you develop automated test and validation systems faster. You can use NI TestStand to develop, execute, and deploy test system software. In addition, you can develop test sequences that integrate code modules written in any test programming language. Sequences also specify execution flow, reporting, database logging, and connectivity to other enterprise systems. Finally, you can deploy test systems to production with easy-to-use operator interfaces. Table of Contents 1. Developing Test Systems with NI TestStand 2. Deploying Test Systems with NI TestStand 3. Where Would I Use NI TestStand? 4. Conclusion Developing Test Systems with NI TestStand NI TestStand includes the Sequence Editor development environment for automated test system development, as seen in Figure 1. Figure 1. The NI TestStand Sequence Editor helps you develop automated test systems faster. With the Sequence Editor, you can create test sequences, which automate the execution of code modules written in any programming language. Each code module executes a test on the device under test and returns measurement information to NI TestStand. You can log test result information in a report or database automatically. In addition, systems written in NI TestStand can integrate with source code control, requirements management, and data management systems. Watch this four-minute demo to discover how you can develop automated test systems with NI TestStand. Deploying Test Systems with NI TestStand
31

What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

Jun 13, 2018

Download

Documents

dangliem
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 1

What Is NI TestStand? Overview

NI TestStand is ready-to-run test management software designed to help you develop automated test and validation systems faster. You can use NI TestStand to develop, execute, and deploy test system software. In addition, you can develop test sequences that integrate code modules written in any test programming language. Sequences also specify execution flow, reporting, database logging, and connectivity to other enterprise systems. Finally, you can deploy test systems to production with easy-to-use operator interfaces.

Table of Contents

1. Developing Test Systems with NI TestStand

2. Deploying Test Systems with NI TestStand

3. Where Would I Use NI TestStand?

4. Conclusion

Developing Test Systems with NI TestStand

NI TestStand includes the Sequence Editor development environment for automated test system development, as seen in Figure 1.

Figure 1. The NI TestStand Sequence Editor helps you develop automated test systems faster.

With the Sequence Editor, you can create test sequences, which automate the execution of code modules written in any programming language. Each code module executes a test on the device under test and returns measurement information to NI TestStand. You can log test result information in a report or database automatically. In addition, systems written in NI TestStand can integrate with source code control, requirements management, and data management systems.

Watch this four-minute demo to discover how you can develop automated test systems with NI TestStand.

Deploying Test Systems with NI TestStand

Page 2: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 2

After development is complete, you can use NI TestStand to deploy automated test systems to production. NI TestStand helps deployment by providing simple operator interfaces that can execute the test system and reduce operator error. You can create operator interfaces, like the one seen in Figure 2, in a number of different programming languages to meet a variety of application requirements.

[+] Enlarge Image

Figure 2. You can create simple operator interfaces to execute test systems.

NI TestStand also offers a deployment utility, which helps you create a distribution of code modules, test sequences, and related files. You can copy this distribution to a central code repository or directly to a production machine, or you can include it in an installer.

Where Would I Use NI TestStand?

NI TestStand automates a sequence of steps. These steps can be individual tests, measurements, actions, or commands. Any application needing automation of executable pieces of code can benefit from the use of NI TestStand. NI TestStand was designed to address four key areas: (1) simplify complex sequence development; (2) accelerate complex sequence development; (3) increase code and test system reusability and maintenance; and (4) improve test system execution performance. This has led to its adoption in consumer electronics for validation and manufacturing test, military and aerospace applications, and the medical industry, as well as IC characterization and simple code sequencing.

Page 3: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 3

[+] Enlarge Image

Figure 3. This diagram shows where NI TestStand fits into the development and manufacturing cycle.

Read more in the “Where Would I Use NI TestStand?” white paper.

NI TestStand in the Electronics Industry

The electronics industry has to meet high test-throughput challenges. Device production can increase quickly, requiring test systems to scale and test more units in less time. Using NI TestStand, engineers in the electronics industry can develop test systems quickly to reduce time to market. NI TestStand parallel test features also help engineers develop scalable test systems that can increase, as necessary, the number of devices tested in parallel.

Learn more about how Flextronics saved millions of dollars and met its test-throughput challenges using NI TestStand.

NI TestStand in the Aerospace and Defense Industry

Engineers in the aerospace industry face the challenge of testing some of the most complex and innovative devices today. With NI TestStand, engineers can rely on a commercial off-the-shelf tool that is compatible with industry standards such as ATML, IVI, PXI, ATLAS, and others. In addition, the modular architecture of NI TestStand helps reduce obsolescence by supporting the execution of both legacy and next-generation programming languages in the same test system.

See how Lockheed Martin used NI TestStand to standardize the test architecture for the Joint Strike Fighter.

Conclusion

NI TestStand offers a flexible and powerful framework for developing, managing, and executing test systems. The components of NI TestStand work together and seamlessly integrate the features of enterprise systems and software.

As test management software, NI TestStand delivers easy integration of independent test modules into a testing framework. With this easy integration, you can focus on developing tests instead of the test framework needed to build the test system.

NI TestStand is an integral part of any test where accelerated development, code reusability, improved performance, and automation are desired. It offers a ready-to-run yet fully customizable environment for developing and managing test systems.

What's New in NI TestStand 4.2 Questions? Get real-time assistance now!

Page 4: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 4

Upgrade to NI TestStand 4.2 Now

Reduce test system development time with NI TestStand 4.2 by reusing your existing software investment in NI

LabVIEW, NI LabWindows™/CVI, scripting languages, and .NET with a commercial test executive. With faster

deployment of LabVIEW code, better integration with scripting languages such as Perl and Python, and Visual Studio

2008 support, you can now integrate different software more easily into NI TestStand.

Improved Integration with LabVIEW, .NET, and Scripting Languages

Simplified Integration with Scripting Languages

The redesigned Call Executable step type provides a more powerful interface for calling common scripting languages

such as Python, Perl, and Tcl.

Read the in-depth white paper

Accelerated Deployment of LabVIEW Files in NI TestStand

The NI TestStand 4.2 deployment utility uses improved internal caching to accelerate the analysis and build time of

deployments.

Validation of LabVIEW Code Modules

The new software engineering tools for LabVIEW can help you ensure the quality and reliability of your LabVIEW

code.

Support for Visual Studio 2008

NI TestStand 4.2 supports direct integration with Visual Studio 2008 and the ability to target the .NET 3.5 framework.

Memory Leak Detection with LabWindows/CVI The new Resource Tracking Window in LabWindows/CVI 9.0 can help you identify places where memory was

allocated but not released.

View webcast on the new NI TestStand 4.2 features

Improved Report Performance and Customization

Report Path Customization Using Expressions

NI TestStand 4.2 gives you the ability to use expressions to customize the path where reports are stored.

Faster XML Style Sheet Performance and Enhanced Documentation

XML report style sheets have been completely restructured to enhance report generation efficiency and

customization.

Processor Affinity Control for Improving Multicore Performance

With new functionality for controlling processor and core affinity, you have tools to optimize symmetric

multiprocessing system performance.

Support for PropertyObject Attributes

The new PropertyObject attributes, available for any PropertyObject, let you store additional information about

PropertyObjects.

Page 5: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 5

Page 6: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 6

Page 7: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 7

Page 8: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 8

Automated Test Equipment: Instrumentation, Software, Services, and Integrators

National Instruments offers a complete software and hardware platform, allowing you to build a software-defined test

system that meets your exact test requirements. With this platform, you gain the assurance of ongoing technology

support and the flexibility to customize your instrumentation as your needs change. NI offers service programs for

individual engineers, global organizations, integrators, and OEMs. These services are designed to meet your needs

throughout the application life cycle – from planning and development through deployment and ongoing maintenance.

NI supplies this framework through its modular, automated test platform shown below. Select individual components

to learn more about these instruments. Or, view example reference test systems that employ software-defined

architecture.

Page 9: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 9

http://zone.ni.com/devzone/cda/tut/p/id/8847

Calling Scripting Languages from NI TestStand 3 ratings | 5.00 out of 5

Read in [] | Print

Overview

The ability to re-use existing code while migrating to a new test software framework can save developers both time and money. Both NI TestStand test management software and NI LabVIEW give users the ability to directly call and integrate with code written in a variety of languages such as Perl, Python and Tcl.

NI TestStand, starting with version 4.2, has the ability to call your scripts written in languages such as Perl, Python and Tcl using the Call Executable step type. In particular, NI TestStand can pass data in and out of scripts as well as access the script’s error information.

Passing Data to Scripts:

Developers can pass data from TestStand to their scripts either through command line arguments or directly through the Standard Input stream. Using the Standard Input stream allows developers to reuse scripts that traditionally took user input from the keyboard during run-time, and run it in an automated fashion from TestStand.

Accessing Output in TestStand:

Once the execution of the script is complete, anything that the script wrote to the Standard Output can be accessed from the TestStand sequence. This will enable developers to base the status of a step on the result of a script.

Accessing Script Errors in TestStand:

If an error occurred during execution of the script, the error information is also available to TestStand through the Standard Error stream. This enables developers to handle the error appropriately.

What this means is that developers can effectively utilize the full power of their scripts by taking advantage of the hooks that TestStand provides to the executable’s Standard Input (stdin), Standard Output (stdout) and Standard Error (stderr).

This article is Part 2 of a three-part series on calling scripting languages from TestStand with a focus on the needs of engineers and scientists.

Table of Contents

1. Calling a Simple Script from TestStand

2. Accessing Script Outputs from TestStand: Standard Output

3. Passing Data to Scripts from TestStand: Command Line

4. Passing Data to Scripts from TestStand: Standard Input

5. Evaluating Script Results: Pass/Fail Test using Status Expression

6. Evaluating Script Results: Numeric Limit Test using <None> Adaptor

7. Handling Script Errors in TestStand

8. Next Steps

Calling a Simple Script from TestStand

Page 10: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 10

Getting Started

If you are new to scripting or don’t have an interpreter installed, we recommend reading Part 1 of this series: Developer Zone Tutorial: Introduction to Scripting

Also, if you are looking to call scripts from LabVIEW, instead of NI TestStand, you can use the System Exec VI. For a tutorial, refer to: Developer Zone Tutorial: Call Perl and Python Scripts from LabVIEW

In order to call a script from TestStand you will have to have the following:

A script to call (we will use examples in Perl, Python and Tcl)

An interpreter for the scripting language you choose

The NI TestStand Sequence Editor (or an Operator Interface that allows you to modify sequences)

If you are currently part of the National Instruments Standard Service Program, you can also access the interactive training module on calling scripts from TestStand here: On Demand Training: TestStand Modules

The Script: HelloWorld

The script used in this example is a simple HelloWorld script that will simply write “Hello World!” to the Standard Output stream. Note: You can download any of the script files by clicking on their filename above the code snippets.

Perl: HelloWorld.pl

#!/usr/bin/perl -w use strict; print "Hello World!\n";

Python: HelloWorld.py

#!/usr/bin/env python print "Hello World!"

Tcl: HelloWorld.tcl

#!/bin/sh # -*- tcl -*- # The next line is executed by /bin/sh, but not tcl \ exec tclsh "$0" ${1+"$@"} puts "Hello World!";

Calling the HelloWorld Script from TestStand

The process of calling a script from TestStand is very similar to calling it from the Windows command line. In fact, all you have to do is use the Call Executable step and specify the path and file for the script you want to execute. (The

reason this works is because we associated the script file extension with the appropriate interpreter. If you haven’t associated the script file with a particular interpreter, you will have to specify the interpreter as the executable and pass in the script file as a command line argument).

Page 11: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 11

1. Open the NI TestStand Sequence Editor and a new sequence file.

2. Add a Call Executable step and rename it “Call HelloWorld Script”.

3. On the Step Settings pane, switch to the Call Settings tab.

4. Specify the name of the script you want to call in the File PathName

Perl: HelloWorld.pl Python: HelloWorld.py Tcl: HelloWorld.tcl

[+] Enlarge Image

5. Save the sequence file as CallingHelloWorld.seq in the same folder as the script.

6. Run your sequence file. Your report should say that the test passed and that the Call Executable script had an ExitCode of 0, which indicates success.

Note: If you haven’t associated the script file’s extension with the appropriate interpreter, you will have to call the

interpreter directly from the Call Executable step and pass in the script as a command line argument. See the following screenshot for an example:

Page 12: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 12

[+] Enlarge Image

Accessing Script Outputs from TestStand: Standard Output

Most programming languages define a standard output stream that programs can write their output to. While this standard output stream (stdout) defaults to the terminal (monitor), NI TestStand gives you the ability to access the standard output stream from the Call Executable Step type.

In the following example, you will learn how to use the previous Hello World example and modify it so that you can write the output of the script to your TestStand report.

Accessing the Standard Output Stream from TestStand

We will use the same HelloWorld script and continue from the same sequence CallingHelloWorld sequence that you created in the previous section, Calling a Simple Script from TestStand.

1. Open the sequence file CallingHelloWorld.seq.

2. Highlight the “Call HelloWorld Script” step.

3. On the Step Setting pane, switch to the Standard Output/Error tab.

4. On the Output Destination combo box, pick Store in Variable/Property. Leave the default value, i.e., Step.StdOutput.Text.

Page 13: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 13

[+] Enlarge Image

5. On the Step Settings pane, switch to the Properties tab and select the Additional Resultscategory.

6. Click the Add Result from List button and select Standard Output. This will include the stdout stream in

the report.

[+] Enlarge Image

7. Save the sequence file as CallingHelloWorldWithStdOut.seq in the same folder as the script.

8. Run your sequence file. Your report should look like the following screenshot:

Page 14: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 14

[+] Enlarge Image

Passing Data to Scripts from TestStand: Command Line

Most programming languages allow you to pass data to them when you launch them through command line arguments – extra parameters that you type in after the name of the script on the command line. TestStand’s Call Executable step allows you to pass parameters to your scripts in this method.

The Script: AddNumbersCommandLine

This is a fairly basic script that will accept a series of numbers as command line arguments and writes their sum to the standard output stream.

Perl: AddNumbersCommandLine.pl

#!/usr/bin/perl –w use strict; #Command Line Arguements are stored in list @ARGV my $numArgs = $#ARGV + 1; my $sum = 0; #Iterate through each element and add to the sum foreach my $currentNumber (@ARGV) { $sum += $currentNumber; } print "Sum: ", $sum, "\n";

Python: AddNumbersCommandLine.py

#!/usr/bin/env python import sys #Command Line Arguements are stored in list argv numArgs = len(sys.argv) - 1 sum = 0 #Iterate through each element and add to the sum for n in range (1, len(sys.argv)):

Page 15: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 15

sum = sum + int(sys.argv[n]) print "Sum:", sum, "\n"

Tcl: AddNumbersCommandLine.tcl

#!/bin/sh # -*- tcl -*- # The next line is executed by /bin/sh, but not tcl \ exec tclsh "$0" ${1+"$@"} #Command Line Arguements are stored in list argv set numArgs $argc set sum 0 #Iterate through each element and add to the sum foreach currentNumber $argv { set sum [expr $sum + $currentNumber] } puts "Sum: $sum\n"

Passing Command Line Arguments from TestStand

All you need to do in order to pass Command Line Arguments from TestStand to a script is to include the parameters you want to pass in the Argument Expression field of the Call Executable step.

1. Create a new sequence file.

2. Add a Call Executable step and name it “Call AddNumbersCommandLine Script”.

3. On the Step Settings pane, switch to the Call Settings tab.

4. Point the File Pathname field to the appropriate AddNumbersCommandLine script.

5. For the Argument Expression field, enter in a series of numbers enclosed in double-quotes. For example:

“2 5 8”

[+] Enlarge Image

6. Switch to the Standard Output tab and store the output in the Variable/PropertyStep.StdOutput.Text.

7. On the Step Settings pane, switch to the Properties tab and select the Additional Resultscategory.

Page 16: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 16

8. Click the Add Result from List button and select Arguments. This will include the command line

arguments in the report.

9. Click the Add Result from List button and select Standard Output. This will include the stdout stream in

the report.

10. Save the sequence file as PassingDataToScriptsCommandLine.seq in the same folder as the script.

11. Run your sequence file. Your report should look like the following screenshot:

[+] Enlarge Image

Passing Data to Scripts from TestStand: Standard Input

Most programming languages also define a standard user input stream that programs can read from during execution. While this standard input stream (stdin) defaults to the keyboard, NI TestStand gives you the ability to access the standard input stream from your sequence. This gives developers more flexibility as your scripts can read these values during run-time rather than right when they begin execution.

The Script: AddNumbersStdIn

Perl: AddNumbersStdIn.pl

#!/usr/bin/perl -w use strict; print "Enter numbers (separate with commas): "; #Get input as a string my $numbersAsString = <STDIN>; #Parse the numbers into a list my @numbers = split(/, | |,/,$numbersAsString); my $sum = 0; #Iterate through the list and add to the sum foreach my $currentNumber (@numbers) { $sum += $currentNumber; } print "Sum: ", $sum, "\n";

Page 17: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 17

Python: AddNumbersStdIn.py

#!/usr/bin/env python #Get input as a list numbers = raw_input('Enter numbers (separate with commas): ') sum = 0 #Iterate through the list and add to the sum for currentNumber in numbers: sum = sum + currentNumber print "Sum:", sum, "\n"

Tcl: AddNumbersStdIn.tcl

#!/bin/sh # -*- tcl -*- # The next line is executed by /bin/sh, but not tcl \ exec tclsh "$0" ${1+"$@"} puts "Enter numbers (separate with commas): " #Get input as a string gets stdin numbersAsString #Parse the numbers into a list set numbers [split $numbersAsString ,] set sum 0 #Iterate through the list and add to the sum foreach currentNumber $numbers { set sum [expr $sum + $currentNumber] } puts "Sum: $sum\n"

Passing Data through the Standard Input from TestStand

All you need to do in order access the standard input stream from TestStand is to enable an Input Method on the Standard Input tab of the Call Executable step.

1. Create a new sequence file.

2. Add a Call Executable step and name it “Call AddNumbersStdIn Script”.

3. On the Step Settings pane, switch to the Call Settings tab.

4. Point the File Pathname field to the appropriate AddNumbersStdIn script.

5. On the Step Settings pane, switch to the Standard Input tab.

6. Switch the Input Method combo box to String, and enter in a series of numbers separated by commas. For

example: 2, 5, 8

Page 18: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 18

7. Switch to the Standard Output tab and store the output in the Variable/PropertyStep.StdOutput.Text.

8. On the Step Settings pane, switch to the Properties tab and select the Additional Resultscategory.

9. Click the Add Result from List button and select Standard Input. This will include the stdin stream in the

report.

10. Click the Add Result from List button and select Standard Output. This will include the stdout stream in

the report.

11. Save the sequence file as PassingDataToScriptsStdIn.seq in the same folder as the script.

12. Run your sequence file. Your report should look like the following screenshot:

[+] Enlarge Image

Evaluating Script Results: Pass/Fail Test using Status Expression

Page 19: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 19

The earlier topics discussed how to get the output of a script into TestStand using the Standard Output stream. Once you have this data in your sequence, NI TestStand gives you the ability to base the result of your sequence based on this output. One way to do this is to modify the Status Expression of the Call Executable step.

The Script: IsVoltageInRange

This simple script takes in a range as an input (minimum and maximum) through the standard input stream. It then compares a simulated voltage which is hardcoded to 5V to the range and prints “Result: True” or “Result: False” to the standard output.

Perl: IsVoltageInRange.pl

#!/usr/bin/perl -w use strict; #Simulated Voltage my $voltage = 5; #Get Range print "Enter range (separate with commas): "; my $numbersAsString = <STDIN>; my @numbers = split(/, | |,/,$numbersAsString); my $min = $numbers[0]; my $max = $numbers[1]; if ($voltage >= $min && $voltage <= $max) { print "Result: True\n" } else { print "Result: False\n" }

Python: IsVoltageInRange.py

#!/usr/bin/env python #Simulated Voltage voltage = 5 #Get Range numbers = input('Enter range (separate with commas): ') min = numbers[0] max = numbers[1] if voltage > min and voltage <= max: print "Result: True\n" else: print "Result: False\n"

Tcl: IsVoltageInRange.tcl

#!/bin/sh # -*- tcl -*- # The next line is executed by /bin/sh, but not tcl \ exec tclsh "$0" ${1+"$@"}

Page 20: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 20

#Simulated Voltage set voltage 5 #Get Range puts "Enter range (separate with commas): " gets stdin numbersAsString set numbers [split $numbersAsString ,] set min [lindex $numbers 0] set max [lindex $numbers 1] if {$voltage >= $min && $voltage <= $max} { puts "Result: True\n" } else { puts "Result: False\n" }

Evaluating Output in TestStand using Status Expression

Since you know that the script is going to return either “Result: True” or “Result: False”, you can use a status expression to parse for this string in the standard output stream and set the step status based on the output.

1. Create a new sequence file.

2. Add a Call Executable step and name it “Pass/Fail Test: IsVoltageInRange (Pass)”.

3. On the Step Settings pane, switch to the Call Settings tab.

4. Point the File Pathname field to the appropriate IsVoltageInRange script.

5. On the Step Settings pane, switch to the Standard Input tab.

6. Switch the Input Method combo box to String, and enter in a range that will pass separated by commas.

For example: 2, 8

[+] Enlarge Image

7. Switch to the Standard Output tab and store the output in the Variable/PropertyStep.StdOutput.Text.

Page 21: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 21

8. Create a Boolean local variable named Locals.isVoltageInRage.

9. On the Step Settings pane, switch to the Properties tab and select the Expressionscategory.

10. Enter the following Post-Expression to parse the standard output:

Locals.isVoltageInRange = (Find(Step.StdOutput.Text, "Result: True") > 0) ? True : False

11. Enter the following Status-Expression to set the result of the step:

Step.Result.Status = Locals.isVoltageInRange ? "Passed" : "Failed"

[+] Enlarge Image

12. On the Additional Results category, enable Standard Input and Standard Output using theAdd Result From List button. This will include the stdin and stdout stream in the report.

13. Click the Add Custom Result button and enter in “isVoltageInRange” as the Name and “Locals.isVoltageInRange” as the Value to Log. Make sure the Type reads Boolean.

14. Now create a copy of the step and insert it right after the original step. Name the copy “Pass/Fail Test: IsVoltageInRange (Fail)”. Modify the Standard Input in this step to cause a fail condition. For example: 3, 4

Page 22: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 22

[+] Enlarge Image

15. Save the sequence file as PassFailTestStatusExpression.seq in the same folder as the script.

16. Run your sequence file. Your report should look like the following screenshot:

Page 23: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 23

[+] Enlarge Image

Evaluating Script Results: Numeric Limit Test using <None> Adaptor

The earlier topics discussed how to get the output of a script into TestStand using the Standard Output stream. Once you have this data in your sequence, NI TestStand gives you the ability to base the result of your sequence based on this output. One way to do this is to use Test Step with a <None> Adaptor after the script to evaluate the script’s output.

The Script: GetVoltage

This script simply creates simulated voltage reading which is hardcoded to 5V to the range and prints “Voltage: <voltage>” to the standard output.

Perl: GetVoltage.pl

#!/usr/bin/perl -w use strict; #Simulated Voltage my $voltage = 5; print "Voltage: " , $voltage, "\n"

Python: GetVoltage.py

#!/usr/bin/env python

Page 24: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 24

#Simulated Voltage voltage = 5 print "Voltage:", voltage, "\n"

Tcl: GetVoltage.tcl

#!/bin/sh # -*- tcl -*- # The next line is executed by /bin/sh, but not tcl \ exec tclsh "$0" ${1+"$@"} #Simulated voltage set voltage 5 puts "Voltage: $voltage\n"

Evaluating Output in TestStand using <None> Adaptor

Since you know that your script is going to return either the voltage in the format “Voltage: <voltage>, you can use a status expression to parse for this string in the standard output stream and set a local variable to this value. Then, you can use a Numeric Limit Test with a <None> Adaptor to test the output.

1. Create a new sequence file.

2. Add a Call Executable step and name it “GetVoltage”.

3. On the Step Settings pane, switch to the Call Settings tab.

4. Point the File Pathname field to the appropriate GetVoltage script.

5. On the Step Settings pane, switch to the Standard Input tab.

6. Switch to the Standard Output tab and store the output in the Variable/PropertyStep.StdOutput.Text.

7. Create a numeric local variable named Locals.voltage.

8. On the Step Settings pane, switch to the Properties tab and select the Expressionscategory.

9. Enter the following Post-Expression to parse the standard output:

Locals.voltage = Val( Mid( Step.StdOutput.Text, Find(Step.StdOutput.Text, "Voltage: ") + Len("Voltage: "), Find(Step.StdOutput.Text, "\n", Find(Step.StdOutput.Text, "Voltage: ")) - (Find(Step.StdOutput.Text, "Voltage: ")) + Len("Voltage") ) )

Page 25: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 25

[+] Enlarge Image

10. On the Additional Results category, enable Standard Output using the Add Result From List button.

This will include the stdout stream in the report.

11. Click the Add Custom Result button and enter in “Voltage” as the Name and Locals.voltage as the Value to Log. Make sure the Type reads Number.

[+] Enlarge Image

12. Now pick <None> from the Adaptor dropdown list and a Numeric Limit Test step. Name the step “Numeric

Limit Test: IsVoltageInRange (Pass)”.

13. Set the Data Source for this step to Locals.voltage.

14. Set the Limits of the step to a range that covers 5 so that the test will pass. For example:

Low: 3 High: 8

15. Now create a copy of the two steps and insert them right after the original steps. Name the copy of the Numeric Limit Test “Numeric Limit Test: IsVoltageInRange (Fail)”. Modify the Limits on this step to cause a fail condition. For example:

Low: 3 High: 4

Page 26: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 26

[+] Enlarge Image

16. Save the sequence file as NumericLimitTestNoneAdaptor.seq in the same folder as the script.

17. Run your sequence file. Your report should look like the following screenshot:

Page 27: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 27

[+] Enlarge Image

Handling Script Errors in TestStand

Finally, NI TestStand also gives you access to the Standard Error (stderr) stream. Anytime an error occurs in your Perl, Python or Tcl scripts, they will write out to this stream. Using this, you can handle any errors eloquently in your TestStand sequence.

The Script: AddNumbersWithErrorHandling

This is a modified version of our AddNumbersStdIn script that will check to make sure that all the inputs were numeric values; otherwise it will throw an error, write to the stderr stream and exit with ExitCode -1.

Perl: AddNumbersWithErrorHandling.pl

#!/usr/bin/perl -w use strict; print "Enter numbers (separate with commas): "; my $numbersAsString = <STDIN>; my @numbers = split(/, | |,/,$numbersAsString); my $sum = 0; foreach my $currentNumber (@numbers) { die("Input is not a number!, stopped") unless ($currentNumber =~ /^\d+$/); $sum += $currentNumber ; }

Page 28: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 28

print "Sum: ", $sum, "\n";

Python: AddNumbersWithErrorHandling.py

#!/usr/bin/env python import sys try: numbers = input('Enter numbers (separate with commas): ') except: print >> sys.stderr, 'Input is not a number!' sys.exit(-1) sum = 0 for currentNumber in numbers: sum = sum + currentNumber print "Sum:", sum, "\n"

Tcl: AddNumbersWithErrorHandling.tcl

#!/bin/sh # -*- tcl -*- # The next line is executed by /bin/sh, but not tcl \ exec tclsh "$0" ${1+"$@"} puts "Enter numbers (separate with commas): " gets stdin numbersAsString set numbers [split $numbersAsString ,] set sum 0 foreach currentNumber $numbers { if ![string is integer -strict $currentNumber] { #error "Input is not a number!" puts stderr "Input is not a number!" return -1 } set sum [expr $sum + $currentNumber] } puts "Sum: $sum\n"

Handling Script Errors in TestStand

TestStand makes it easy not only to access the Standard Error stream in our sequence, but also makes it easy to make decisions based on the contents of this stream and eloquently handle any errors.

1. Create a new sequence file.

2. Add a Call Executable step and name it “Call AddNumbers Script (Correct Input)”.

3. On the Step Settings pane, switch to the Call Settings tab.

4. Point the File Pathname field to the appropriate AddNumbersWithErrorHandling script.

5. On the Step Settings pane, switch to the Standard Input tab.

Page 29: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 29

6. Switch the Input Method combo box to String, and enter in a series of numbers separated by commas. For

example: 2, 5, 8

7. Switch to the Standard Output tab and store the output in the Variable/PropertyStep.StdOutput.Text.

8. Enable the Standard Error by switching the Error Destination dropdown to Store in Value/Property. Leave the default destination, Step.StdError.Text.

9. Check the Set Error.Msg to Standard Error Test checkbox.

10. Switch the If Standard Error is Non-Empty dropdown to Set Step Status to Error.

11. On the Step Settings pane, switch to the Properties tab and select the Additional Resultscategory.

12. Click the Add Result from List button and add Standard Input, Standard Output and Standard Error.

[+] Enlarge Image

13. Now create a copy of the step and insert it right after the original step. Name the copy “Call AddNumbers Script (Incorrect Input)”. Modify the Standard Input in this step to cause an error condition. For example: 2, Five, 8

Page 30: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 30

[+] Enlarge Image

14. Save the sequence file as HandlingScriptErrors.seq in the same folder as the script.

15. Run your sequence file. Your report should look like the following screenshot:

Page 31: What Is NI TestStand? - hguywilliamshguywilliams.net/images/documents/Notes/LVTS/What Is NI TestStand.… · What Is NI TestStand? Overview NI TestStand is ready-to-run test management

© 2011, H Guy Williams 31

[+] Enlarge Image

Next Steps

Now that you know how to integrate simple scripts into TestStand sequences, the next article will show you how to create more complex scripts that can call DLLs, perform data acquisition in NI-DAQmx and communicate with instruments using NI-VISA. Developer Zone Tutorial: Advanced Scripting in Perl, Python and Tcl

If you are currently enrolled in the Standard Service Program, you can also access the interactive training module on calling scripts from TestStand here: On Demand Training: TestStand Modules