NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Get all parameters of dynamic sequences using TestStand API

I have an upper level sequence that runs in a loop.  The sequence launches a subsequence by expression to a file path, and the subsequence always uses "MainSequence"

These subsequences have parameters that are set according how it is Launched, (either run independently as "the sequence", or run as part of an automated sequence of subsequences).

 

The some of the subsequences could have a parameter called "Auto_Test", which skips the initialization routine if it is set to true, some subsequences do not have this parameter.

 

The issue I am having is this:

I need to set that Auto_Test Value, but only if it exists.  

 

RunState.NextStep.TS.SData.ActualArgs.Exists("AUTO_TEST",0) does not work because the prototype is load dynamically.

 

If I add the variables myself using:

RunState.NextStep.TS.SData.SpecifyByExpr=True,

RunState.NextStep.TS.SData.SeqNameExpr="Locals.Sequences[Locals.index]",
RunState.NextStep.Module.LoadPrototype(1),

RunState.NextStep.TS.SData.ActualArgs.NewSubProperty("Auto_test",PropValType_NamedType,False,"SequenceArgument",1),
RunState.NextStep.TS.SData.ActualArgs.Auto_test.UseDef=False,
RunState.NextStep.TS.SData.ActualArgs.Auto_test.ParamType=4,
RunState.NextStep.TS.SData.ActualArgs.Auto_test.ParamRepresentation=1,
RunState.NextStep.TS.SData.ActualArgs.Auto_test.Flags=0x4,
RunState.NextStep.TS.SData.ActualArgs.Auto_test.Expr="Locals.AUTO_TEST",

 

Then it works, but only if Auto_Test is a parameter in the subsequence.  If it does not exist, then the value I try to write overwrites the 1st index in the parameter of the subsequence, and causes unexpected behavior.

 

I need the method to get all the parameters, then loop through them and only write the value if it is exists.

 

I can't seem to find the method the returns the parameter's names, unless they are already loaded in the prototype.

 

I have attached the sequence I have so far, using subsequences located in the current file to make it easier to share.  I also have comments on what it is doing vs. how I expect it to behave.

 

I've been struggling with this for a couple days, looking at using the TestStand API, or the ActiveX APIs. I'm not that familiar with the API calls of TestStand and a have dug through the forums.

I feel like I am really close but am missing something obvious.

 

Thanks in Advanced for any help.

 

0 Kudos
Message 1 of 7
(123 Views)

Have you tried 

PropOption_DoNothingIfExists
    –(Value: 0x4) Use this option with the SetVal methods of the PropertyObject class to avoid setting the value of a property that already exists. Usually, you use this option in combination with the PropOption_InsertIfMissing option.

 

on creating the parameter?

0 Kudos
Message 2 of 7
(103 Views)

Thank you for the feedback.  But I think those options do the opposite of what I need.

 

If the parameter "Auto_test" exists in the subsequence, then I need to set it.  If it doesn't exist, then I need to skip it.  If I insert the Auto_Test argument every time then sequences where "Auto_Test" does not already exist has one of it's existing parameter's overwritten with Auto_Test's value.

 

This is because parameters are passed to subsequences in an array of values of a defined size.  

If the subsequence has the parameters [AutoTest,X,Z], then when I create the argument and pass the value everything works.

 

But if a subsequence has the parameters [a,b,c] passed in, then creating the argument causes this behavior to happen with the parameters

[ -> Auto_test,b,c].  In this case a's default value becomes Auto_Tests value.  

 

What I need to be able to do is open the reference to the sequence file and retrieve its existing values of parameters, look for a specific  parameters name and act accordingly.

 

I just haven't been able to find the right combo to load the sequence object by file path, then find how to extract is parameter's names.

 

Thanks again for the suggestion.  I'm still digging through the api calls... there are tons of them.

0 Kudos
Message 3 of 7
(97 Views)

If the file you want to call is loaded and you have a reference to it, you should be able to traverse its ActiveX structure using the TestStand API or use its PropertyObject structure and lookup strings to access the edit-time copy of a sequence's parameters. The following expression is just illustrative of that structure, RunState.SequenceFile.Data.Seq["MainSequence"].Parameters.*, and then you can traverse the subproperties in the Parameters container using the API methods GetNumSubProperties and GetNthSubPropertyName.

Hope that helps...

Scott Richardson
https://testeract.com
0 Kudos
Message 4 of 7
(89 Views)

Good Morning,

 

That does help quite a bit, thank you.  I think I'm closer.  That gets me the references and parameters if the subsequence is part of the calling sequence.

 

I'm trying to call a subsequence at a different path. The example I used combined all the files together to make it easier to share, so I might have been unclear.

 

Thank you again for your time.

0 Kudos
Message 5 of 7
(66 Views)

I was able to cobble something functional with this information.  So thank you again for the help.

 

I ended up using the Active X TestStand API to get the Sequence parameters, then looped through them looking for my desired parameter.

I couldn't get the "Set Property" to set the value to work correctly.   I put a flag in the loop to identify if the parameter was found.  I added and set the parameter to the prototype before the subsequence executed.  After the subsequence ran I checked the flag again, then deleted it from the prototype.

 

I am getting 2 errors.

1) is simple, since the Auto_Test Argument doesn't exist it shows a "not found" error.  I think if I do a #NoValidation() it will fix it.

2) The code runs once correctly, then I get a "error Calling sequence MainSequence" message.  (attached).  I have to close and relaunch test stand to make this run.  Any suggestions.

 

The code is attached.  SetParameters.seq

The file paths are .C:\Folder\

 

I'll keep trying to figure out that error.

 

Thanks again,

 

0 Kudos
Message 6 of 7
(56 Views)

I didn't go through the whole of your example, IMHO it is quite complicated... nevertheless: thanks for setting up this example!

 

Just a few hints from my side.... 

 

Once  you have  gained access to the Sequence File you need, you get a PropertyObject holding the parameters using

Locals.SequenceFileRef.AsSequenceFile.GetSequenceByName("MainSequence").AsSequence.Parameters

 

To check if a Parameter exists:

 

 

Locals.SequenceParameters.AsPropertyObject.Exists("Auto_Test",0)

 

 

 

To create it

 

Locals.SequenceParameters.AsPropertyObject.NewSubProperty("SomeOther", PropValType_Boolean, False, "", PropOption_DoNothingIfExists || PropOption_InsertIfMissing)

 

You might wanna save the change if you have to

 

If you code is running only once, I guess the second time fails due to incorrect PropOption

 

Hope this helps / adds som ehelpful aspects

 

 

 

 

 

0 Kudos
Message 7 of 7
(29 Views)