NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing sequence local variables from a within a different sequence

If you have one sequence with local variables. Can you (best approach?) access these local variables from within a second sequence called (as a sequence call step) from within the first sequence?
(Other than using station or file global variables)

Are there any issues with doing this (multi thread dangers etc)?

Thanks
Dan
0 Kudos
Message 1 of 4
(4,424 Views)
Add parameters to your second sequence. Pass the local variables from the first sequence to these parameters when you call the second sequence.

As long as you don't specify that the sequence call runs in a new thread, there are no multithreading issues. If the sequence call does start a new thread, be wary of passing parameters by reference (which is the default) because both the caller and callee could make changes to the variable you pass without realizing that each sequence is not necessarily the only sequence accessing the variable at a given time.
0 Kudos
Message 2 of 4
(4,424 Views)
Dan,

There are 3 ways you can access the local variables of the calling sequence from the callee:

1) Passing the local variables as parameters (as described by James Grey's answer). This is a simple and easy method. However, the disadvantage would be that you'll have to add to the callee as many parameters as local variables you want to access.

2) From the callee, you can access any property of the calling sequence (including local variables, file globals, parameters, step properties...) through the "RunState.Caller" property. For i.e., if the calling sequence has a local variable called "MyVariable", the propery path you would use from the callee would be "RunState.Caller.Locals.MyVariable". From the RunState.Caller property you have access to the sequence context of the calling sequence! Therefore, you could access any property of the calling sequence by using the correct property path.
This second method will work when the callee is running in the same thread as the calling sequence or even in a new thread. However, it won't work if it is called in a New Execution, in which case, the RunState.Caller property doesn't exist.

3) Add an ActiveX Reference Parameter to the callee and pass the sequence context of the calling sequence (ThisContext) as the argument. In the callee, you may access any property of the calling sequence by using the API methods SetValNumber, SetValString, SetValBoolean, etc. You could use the ActiveX adapter configured as follows:
- ActiveX Reference: Parameters.SeqContext (This would be the name of the parameter you added)
- Automation Server: TestStand API
- Object Class: PropertyObject
- Action: Call Method
- Method: SetValNumber (or SetValString, SetValBoolean, etc.). You'll need to give the correct path to the property you are trying to access as the lookup string. For i.e., if the calling sequence local variable is called "MyVariable", the property path would be "Locals.MyVariable" (including the double quotes).
This last method will work even if the subsequence is called in a New Execution.

The best method will really depend on what you are doing as previously described.

Regards,

Carlos Leon
Message 3 of 4
(4,424 Views)

Could you please advise what should i set for the "Method" in method 3 if i am looking for a local variable which is an array?

Thank you.

0 Kudos
Message 4 of 4
(1,033 Views)