NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

c# interop get Step Name

Solved!
Go to solution

I am attempting to use a C# code module in order to read the calling step's name. However, my code only every returns "Step" as the name of the object (regardless of what the step is actually called in the sequence). Note that I have also tried doing the same thing to get the calling sequence name - and it always returns "Sequence". Where am I going wrong? Here is the code: (please see attachment for complete source and example TestStand sequence in the "Debug" folder.

 

using System;
using System.Collections.Generic;
using System.Text;
using NationalInstruments.TestStand.Interop.API;
using System.Windows.Forms;

namespace Test
{
    public class TestClass
    {
        public void TestMethod(SequenceContext thisContext)
        {
            PropertyObject pObj = thisContext.AsPropertyObject();
            PropertyObject stepObj;
            stepObj = pObj.Evaluate( "Step" );
            MessageBox.Show(stepObj.Name);
        }
    }
}

 

As a bit of background, I am trying to retrieve the name of the calling step and the name of all Sequence calls all the way up the stack to the root. This same methodology works using Expression steps, but I want to hide all the mess into a single code module. Any ideas would be appreciated! 

 

Thanks,

Phil

0 Kudos
Message 1 of 3
(4,396 Views)

Hi,

 

use

stepObj = thisContext.Step to get the Step as an object reference

then you can use  

StepObj.Name

 

Hope this helps

Regards

Ray Farmer

Regards
Ray Farmer
0 Kudos
Message 2 of 3
(4,392 Views)
Solution
Accepted by topic author Phil_Rawlings_SAI

Hi Ray,

 

Thanks for the advice. Unfortunately, I think I made my example a little too simplistic! Your solution is perfect for the Step Name case, unfortunately it will not work for what I am trying to do. I am writing a custom result logger that is called from the ProcessModelPostResultListEntry callback, and want to check whether the "RecordResult" option is enabled on all of the SequenceCall steps in the stack and whether each Sequence in the stack has the "RecordResults" option enabled. (Basically, Result Recording must be enabled at all levels for the result to be logged). You may think that the ProcessModelPostResultListEntry callback would only get called if this condition is met - unfortunately it is only affected by the most nested combination of the Step's "RecordResult" and the Sequence's "RecordResults" properties. Therefore, frustratingly, I need to check all the way up the stack back to the ProcessModel. The reson why this is more complex is that the Step and Sequence property objects further up the stack can only be accessed by using the Evaluate() Method, as opposed to the lowest level in the stack which can be accessed via thisContext.Step and thisContext.Sequence.

 

Anyway, I worked it out in the end: Expressions within TestStand enable you to take a number of API shortcuts which are not available when using the API in another language - hence why I was able to use expressions like:

Locals.SequenceRef = Evaluate( "RunState.Caller.RunState.Caller.Sequence" ),

Locals.SequenceName = SequenceRef.Name

Locals.SequenceRecResult = SequenceRef.RecordResults

whereas similar code in C# did not work as expected (note that the RunState.Caller string above is actually built dynamically depending on the call stack depth).

 

Being more explicit in C# does work correctly though:

seqObj = pObj.Evaluate( "RunState.Caller.RunState.Caller.Sequence" );
SequenceName = seqObj.Evaluate( "Name" ).GetValString("", 0 );

SequenceReqResults = seqObj.Evaluate( "RecordResults" ).GetValBoolean( "", 0 );

 

Although, in the process of writing this response, I have just found the following property:

 

SequenceContext.CallerDiscardsResults

"Returns whether any sequence in the call stack instructs TestStand to disable results or if any calling step up the call stack instructs TestStand to not record results"

 

Typical! I think this may be an easier route to use!!! 🙂

 

Thanks anyway,

Phil

 

 

 

Message Edited by monkeyslikebananas on 03-11-2009 01:40 AM
Message Edited by monkeyslikebananas on 03-11-2009 01:41 AM
0 Kudos
Message 3 of 3
(4,360 Views)