Example Code

Passing Custom Command Line Arguments to a TestStand Operator Interface (.NET)

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • Teststand

Code and Documents

Attachment

Download All

Description

Overview

The TestStand Application Manager supports processing custom command line arguments through the ProcessUserCommandLineArguments event. This can prove useful when automating test execution from a CI server.

Description

This example is similar to the .NET Basic User Interface, but has been modified to accept the following command line arguments:

Option Purpose
/SimulateFailure <failures> When used with the included example sequence file, this suppresses the simulation dialog and instead simulate failures as specified. This argument accepts the following parameters:
  • Keyboard
  • Video
  • Power
  • CPU
  • ROM
  • RAM
If no parameters are specified, then all components are simulated to pass.

 

This example demonstrates the following concepts:

  • Using _ApplicationMgrEvents_ProcessUserCommandLineArgumentsEventHandler to handle custom command line arguments
    Spoiler
  • Modifying a TestStand user interface to print UI error messages to the console and set the return code appropriately
    Spoiler
  • Use of the ApplicationMgr.AddCommandLineArgumentsHelp function to add custom command line arguments help.
    Spoiler
  • Creating a custom UI Message handler to pass simulation data to sequence execution.
Spoiler

Note: By default, TestStand shows dialogs under certain conditions. This can cause hangs when automating sequence execution without user input, such as when ran from a CI Server. In order to prevent popups that require user input, configure the following options:

  • Disable User Management or automatically log in the System User
  • Set the 'Station Options » Execution »  On Run-Time Error' setting to something other than 'Show Dialog', such as 'Run Cleanup'.
  • Specify 'Station Options » Time Limits' for Exiting and Normal Execution such that the user will not be prompted.
  • Pass the /quit argument via the command line so TestStand automatically shuts down after all executions are complete.

Hardware and Software Requirements

TestStand 2014 SP1 or later

Visual Studio 2015 or later
LabWindows/CVI Runtime Engine 2015 or later

Steps to Implement or Execute Code

 

  1. Unzip the attached example and build the Basic User Interface solution for the bitness of TestStand you have installed.
  2. Open a command line window in the build output directory (Shift + right click » Open command window here). Alternatively, you can configure command line arguments for the Visual Studio debugger in the Project Properties under the Debug tab.
  3. In order to see the Command Line help, run:

    TestExec /?

  4. Experiment with the /SimulateFailure argument. For example:

    TestExec /runEntryPoint "Single Pass" "<ExampleDir>\TestSequence\Computer Motherboard Test Sequence.seq" /SimulateFailure Keyboard Video RAM /quit

https://www.linkedin.com/in/trentweaver

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
AntoineVretman
Member
Member
on

Very useful ! I guess i begin to understand how to really use axApplicationManager to run my sequences programmatically ! 

As described in Overview, i need to run my sequences from a CI Server, so this example is absolutely matching my needs. 

Nevertheless, i am not able to report errors: when parameter is not correct and i set: 

                e.errorProcessing = ProcessCommandLineErrors.ProcessCommandLineError_CustomError;
                e.errorMessage = "Invalid Command Line Argument: " + e.arguments[e.currentArgument];

i have no error raised... 

I set options as you recommand about StationOptions, log in and /quit parameter...

Any idea ? thanks.

WireWeaver
Active Participant
Active Participant
on

Hey Antoine,

 

I don't have a chance to dig too much into this right now, but I'll take a look later. Setting that error should trigger the axApplicationMgr_ReportError event that is also customized in this example. I just noticed a comment i left, but don't remember why i never revisited it.

Console.WriteLine("Error " + e.errorCode + ": " + e.errorMessage); //this isn't working because of appdomain stuff

Pretty vague i know... but for starters I would put a breakpoint there and see if your error message is making it to this callback.

 

-Trent

https://www.linkedin.com/in/trentweaver
AntoineVretman
Member
Member
on

Hi,

 

Thanks for reply. Actually that's the blocking point: inserting a breakpoint here, or adding methos to display log messages, or message boxes has no effect here. It means the exception is not raised, and execution never goes through axApplicationManager_reportError method. 

 

 private void axApplicationMgr_ReportError(object sender, NationalInstruments.TestStand.Interop.UI.Ax._ApplicationMgrEvents_ReportErrorEvent e)
        {
            TSUIlogger.Error("Error " + e.errorCode + ": " + e.errorMessage);
            MessageBox.Show(this, ErrorMessage.AppendCodeAndDescription(this.axApplicationMgr, e.errorMessage, e.errorCode), "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            Console.WriteLine("Error " + e.errorCode + ": " + e.errorMessage);
            axApplicationMgr.ExitCode = e.errorCode;
   
}

I don't understand why, because documentation expressively specify that set value for 

 e.errorProcessing = ProcessCommandLineErrors.ProcessCommandLineError_CustomError;

should automatically raise event for reportError method, and my axApplicationManager has event property for ReportError attached to corresponding method...image.png

 

Thanks for your time !

Antoine

WireWeaver
Active Participant
Active Participant
on

Hey Antoine,

 

I just played around with this some and it looks like the error is actually getting reported prior to this event being called. it does print the error to the console, but it never calls that callback (because the error is already handled by the appMgr):

DebugSettings.PNG

ErrorMessage.PNG

https://www.linkedin.com/in/trentweaver
danimon
Member
Member
on

Hi

Thanks for this helpfully example.

Unfortunately I have still some struggle with the "no login message box" part. I did as described and while I am opening the Teststand Sequence Editor, the login message box doesn't appear, but if I start the example code application, the message box shows up.

Could you help me to find out, what I have forgotten or did wrong?

Thanks for your help,

Dani

joshikak
Member
Member
on

I'm trying to run a sequence using command line argument but my sequence is ending up with the below error.

 

Thank you in advance,

Capture.PNG

WireWeaver
Active Participant
Active Participant
on

Since this isn't specific to custom commands, you should post your question to the normal TestStand forums:

https://forums.ni.com/t5/NI-TestStand/bd-p/330

 

Also, you should include the specific command that you're which throws this error.

-Trent

https://www.linkedin.com/in/trentweaver