NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Get Sequence Context from Model?

Hello.  I'm adding some additional results stroage to the Sequential Model.  I would like to be able to record a value of a local variable, parameter or file global, from the perspective of the step that's being executed.  I have the variable name, and I need to query its value.
 
To my mind, this means I need to use the GetValxxx method from the Sequence Context, after turning it into a property object.  From my model, I therefore need to get hold of the Sequence Context, just as seen by the step.
 
If I use RunState.Main then it works with steps that are within the top level sequence that's running.  But this doesn't work with steps that are part of a sequence that is called.
 
Hopefully someone will tell me the really obvious thing I've missed, but this has stumped me.
 
To summarise, I have a string containing the name of a variable, e.g. "Locals.MyString".  I need a way of getting the value of this variable, as seen by the step itself.
0 Kudos
Message 1 of 7
(3,617 Views)

Hi Sean,

If you prefix RunState.Caller then you will able to access the properties of the caller. For every level down prefix additional RunState.Caller.

eg

Say you wanted to access the StationID which is contained in a local in the 'Single Pass' sequence from the Client MainSequence, You would use "RunState.Caller.RunState.Locals.StationInfo.StationID"

 

Hope this helps to answer your question

Regards

Ray Farmer

Regards
Ray Farmer
Message 2 of 7
(3,601 Views)
Apologies if I didn't explain clearly.
 
My step is within the SequentialModel sequence file, in ProcessModelPostStep.  I need to be able to record a variable from the viewpoint of the step that's executing.
 
E.g. I'm running a sequence called "MainSequence".  This has a sequence call to "SubSequence", which contains a step called "MyStep".  There is a variable called "Locals.MyString" within "SubSequence".  My code, which is located within ProcessModelPostStep, has already been passed the string "Locals.MyString".  I now need to record the value of this variable with the results.
 
Normally, to look up a variable I would convert SequenceContext to a Property Object, then call the "GetTypeDisplayString" method, then use a Select...Case per data type (with a default case for the types I'm not interested in).  Then, if it's a string, I call the "GetValString" method.  Both of these use the string "Locals.MyString" as the "lookupString" parameter.
 
This works perfectly from ProcessModelPostStep if I use "RunState.Main" as the SequenceContext.  But it doesn't work if the step is not in the top-level sequence (as in my example given above).
 
All I'm after is a way of getting hold of the SequenceContext from the point of view of the step that's currently executing, regardless of where in the hierarchy it is.
 
I'm still hoping this is a complicated question with a really simple answer!
0 Kudos
Message 3 of 7
(3,587 Views)

Thanks, Ray.  I finally worked out the wisdom of your words!

RunState.Caller does get me the SequenceContext for the current step.  I think I'm sorted now.  Ta very much.

0 Kudos
Message 4 of 7
(3,581 Views)

Hi Sean,

To get the value of Locals.MyString from within the ProcessModelPostStep

use as the Lookup string "RunState.Caller.RunState.Locals.MyString"

                                          RunState.Caller gets you back to the Caller Sequence

 

Hope this helps, if not I'll do an example, but it will be later during the day.

Regards

Ray Farmer     

Regards
Ray Farmer
0 Kudos
Message 5 of 7
(3,576 Views)

I think I'm on the same lines.

I'm using "RunState.Caller" as my SequenceContext, then using "Locals.MyString" as the lookup string.  I think this is the same thing, from a slightly different angle.

0 Kudos
Message 6 of 7
(3,572 Views)

Great stuff.  RunState.Caller hops from the model to the sequence being executed.  Thanks again Ray.

I just found one weirdo:

e.g. The sequence contains Locals.MyArray (array of strings) and Locals.Index.

I need to obtain the value of Locals.MyArray[Locals.Index], from ProcessModelPostStep.  If I use the GetValxxx method, I get an error, as it doesn't correctly evaluate the "Locals.Index" value.  It will work with a number as the index, but not with a variable.  Instead, I had to do this:

Use "RunState.Caller" as the reference to call the SequenceContext>AsPropertyObject method.

Use the above property object as the reference to call the PropertyObject>EvaluateEx method, with "Locals.MyArray[Locals.Index]" as the exprString.

Use the new property object as the reference to call the PropertyObject>GetValString method, with "" as the exprString.

Weird, but it works!

0 Kudos
Message 7 of 7
(3,553 Views)