From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Insert steps into runtime sequence using DefaultSequenceValues

Solved!
Go to solution

As part of a custom Sequence Call step type I'm designing, I want to add steps to the called sequence, but only at runtime.

 

I found methods of the Execution class to edit the runtime copy of the sequence: New/Set/Get/Clear SequenceDefaultValues, but I'm getting strange errors when I use them to try to insert a step. Changing sequence properties (such as GoToCleanupOnFail) works just fine.

 

When I use these API methods to try to insert the step into the runtime only sequence, I get an error Invalid step index '0' for 'Setup' phase in sequence 'Tests'.

 

Locals.SequenceRef = RunState.SequenceFile.GetSequenceByName("Tests"),
Locals.DefaultSequence = RunState.Execution.NewSequenceDefaultValues(Locals.SequenceRef),
Locals.StepClone = RunState.Sequence.GetStepByName("Label",StepGroup_Setup).AsPropertyObject.Clone("", PropOption_CopyAllFlags | PropOption_DoNotShareProperties),
Locals.DefaultSequence.AsSequence.InsertStep(Locals.StepClone, 0,StepGroup_Setup), RunState.Execution.SetSequenceDefaultValues(Locals.DefaultSequence,SeqDefValueScope_Execution)

 

I have found that this similar code works to insert the step into the edit-time sequence:

 

Locals.SequenceRef = RunState.SequenceFile.GetSequenceByName("Tests"),
Locals.StepClone = RunState.Sequence.GetStepByName("Label",StepGroup_Setup).AsPropertyObject.Clone("", PropOption_CopyAllFlags | PropOption_DoNotShareProperties),
Locals.SequenceRef.AsSequence.InsertStep(Locals.StepClone,0,StepGroup_Setup)

I found in my searching that the SequenceDefaultValues methods were designed for the property loader. That is, the most common use case would be to update sequence locals. Is changing the steps of the sequence not supported?

 

From the error, I would guess that there is a mismatch somewhere between the array of steps in the sequence Sequence.Setup[] array (that is getting updated) and some other value that stores the number of steps in the setup step group (that isn't getting updated). Also, the error refers to the setup 'phase' not 'step group', which implies to me that it is an internal engine error, since NI is usually careful with their nomenclature for externally facing error messages.

 

I also found this old KnowledgeBase from TestStand 2.0 that says that TestStand maintains an internal step counter for the current step group. Is there something similar going on here?

 

Attached is a sequence file from TestStand 4.2.1 that shows the error in as simple a case as I can make it (unfortunately 4.2.1 is the version my customer is using, and they haven't been persuaded to upgrade yet).

Josh W.
Certified TestStand Architect
Formerly blue
Message 1 of 8
(5,484 Views)
Solution
Accepted by topic author Josh_W

Hi Josh,

 

I appreciate the detailed post!  After some investigation, the issue here is that when a subsequence step calls a sequence, it uses the edit-time copy of the file to check the number of steps, but then attempts to execute the run-time copy, which is different.  Because there is a mismatch, the error occurs.  I was able to find a workaround which may work for you, but I first want to emphasize that TestStand does not support the structural modification of any sequence file that is currently loaded for execution. The term "structural modification" includes things like:

 

  • Adding or removing steps
  • Adding or removing sequences
  • Adding or removing properties
  • Changing step module or adapter settings

This is why the sequence editor prevents you from editing a sequence file while it is executing. Operations such as changing property values are not considered "structural modification", which is why the property loader can successfully change limits of dynamic sequences.  

 

The workaround is to actually create a new sequence file to contain a clone of the sequence you are modifying, and then load that sequence file dynamically from the sequence call step.  Using this method, the new sequence file is not loaded for execution until after the structural modifications are complete.  Also, since the run-time copy is not created until the sequence call step, the use of the SequenceDefaultValues methods is no longer necessary.  I have attached a modified version of your example demonstrating this approach.

 

If this approach won't work in your case, let me know and we can look into other possible methods to go about this.

Al B.
Staff Software Engineer - TestStand
CTA/CLD
Message 2 of 8
(5,449 Views)

Al,

 

Thank you for answering my question so thoroughly. I had forgotten (if I had ever known) that TestStand doesn't support editing sequence files at runtime when that file is loaded for execution. It's a critical piece of information to keep in mind.

 

Thank you for coming up with a workaround too, but unfortunately, in my specific case it is not directly applicable.

 

Let me provide a bit more detail. Please excuse the length of these comments, I'm trying to give a full accounting of my design process.

 

I want to allow the developer to designate other sequences as prerequisites of the sequence called by the step. The step would call those sequences before the step module. I wanted this to be as seamless as possible for the developer so I started writing a pre-step substep. But I ran into a roadblock when I couldn't think of an elegant way to execute a sequence from within the pre-step substep.

 

So I thought I would try modifying the called sequence to add the sequence call steps I wanted called, which lead to this question. Unfortunately, the workaround you provided will not work because the module is loaded before the pre-step substep is executed; steps  7 and steps 14 respectively in the Step Execution order. So I can't use your workaround because the module has already been loaded for execution. (And can I just say how awesome it is to have the TestStand reference manual in the help! It's really great that it's searchable with the rest of the help and it's usable from ni.com/manuals for when I'm on a machine without TestStand installed.)

 

I considered briefly using an interactive execution to run the appropriate sequences (as what  I'm really trying to do is get the UUT into a specific state, so running the sequence interactively would be acceptable), but I need the results of the additional sequence to be part of the report. I'm guessing there's still a way I could do this by getting the ResultList from the interactive execution before it is released, but I'm reluctant to go down that path. Creating

  1. an interactive execution
  2. during another execution
  3. programmatically from within a pre-step substep
  4. and retrieving information from that interactive execution when it finishes

is a lot of complexity; I put the idea to the side hoping to find something simpler.

 

[Edit: I should really look at the help before posting here]

It's not an interactive execution that I thought I wanted, it would be an entirely new execution. But I might be able to just spawn a new thread and use WaitForEnd on it.

[End Edit]

 

Based on your comments, I could edit the sequences called by my custom step type at edit time. I could use the custom step type's edit substep (which I already have for configuring the step) and have it programatically edit the called sequence when the dialog is dismissed. The added steps will be visible to the developer (not ideal, but it will be fine once I name them and give them appropriate comments) if they view the called sequence. And I will need some logic to make sure I don't add the steps twice.

 

There are a few downsides to this design:

  1. If the developer changes the target sequence after configuring the step via the edit dialog (or simply uses the edit dialog before configuring the module)then the steps will not be added to the target sequence unless the dialog is called again.
  2. The custom edit dialog will not be able to add the additional steps when the step is configured to use an expression for the sequence/sequence file to call.
  3. The logic to prevent adding the steps twice will probably be complex, or rely on a flag that I set. If it is complex, then that adds to the possibility of a mistake; and if it uses a flag, the steps are editable by the developer, which means the flag could be toggled accidentally.

Those downsides are the reason that I originally had the idea to make the changes at runtime, when I don't have to rely on the developer using the step correctly, and the expression would evaluate correctly, and I'm sure that the steps have not been added before.

 

A lot of this dancing around is because I want the developers to be able to specify the sequence to call the same way as if the step were a standard Sequence Call step. But I may have to give that up. Although if I do, I'm not sure how I would make my custom step call a sequence as its module. Hmm... something to think about.

 

I'm going to start investigating how feasible using a new thread is.

 

If you or anyone else has any suggestions or can think of another way to get the desired behavior, I'm all ears.

 

Thanks!

 

-Josh

Josh W.
Certified TestStand Architect
Formerly blue
Message 3 of 8
(5,413 Views)

Hi, had a doubt regarding the dynamically created sequences, can we not access the sequence created in the SequenceFilePostStep? the callback is not executing after each step within the sequence I've created.

Lakshmi Narasimha
0 Kudos
Message 4 of 8
(4,593 Views)

Lnsimha93,

 

Can you give us some more information about what you are trying to do? Are you dynamically creating a sequence file like Josh_W was trying to do? What sequence are you trying to access in the SequenceFilePostStep?

 

Is the main issue that your callback is not executing after each step? Does the callback work properly in your sequence if you do not create it dynamically?

 

One thing to note is that the callback will not execute on any step that errors. Are you getting any errors on your steps?

 

If you could give us more information about your setup, it would help us narrow down what could be going on. If this is a different issue than what Josh_W described above, it may be best to make a new forum post so that you can get more views on it.

 

Regards,

Hannah 

Applications Engineering 

National Instruments 

www.ni.com/support 

0 Kudos
Message 5 of 8
(4,566 Views)

Hi Hannah,

I am designing a sequence for an ATE where requirement wherein I would have to jump between different tests/steps during runtime based on a jump request from the tester, I had previously divided and grouped all my tests into various sequence calls. To satisfy the above requirement I thought if I had all the tests\steps under one sequence it would be easy for me to implement some logic. So I copied the files dynamically into another sequence like Josh_W was trying to do, I got the sequence how I wanted, but for some reason my post step callback did not work within that sequence only. It worked fine everywhere else. And no, I had no error in my sequence, the file executed perfectly.

 

Instead of creating a runtime copy, I tried creating a new sequence file and copied my post step callback there, and it worked flawlessly there. So my question is whether a dynamically created (run time copy only instead of creating another file) sequence can access callbacks? Am I missing something? cause it would be better if no additional file gets created.

 

Yes I think it would be better if I had a new forum post, will do it.

 

Lnsimha93

 

Lakshmi Narasimha
0 Kudos
Message 6 of 8
(4,560 Views)

Lnsimha93,

 

Could you post the link to the new forum post that you create to this forum post as well? I'd like to look into this more on my end.

 

Thanks,

Hannah

0 Kudos
Message 7 of 8
(4,550 Views)
0 Kudos
Message 8 of 8
(4,541 Views)