NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically Create Test Step

I want a TestStand sequence to dynamically create multiple copies of a test step (with different parameters).  We are currently looping on the test step, but this doesn't provide a clear indication to the operator what test steps have been and will be executed.  I tried to do a SetNumElements(RunState.Sequence.Main, numElements) and an InsertElements(RunState.Sequence.Main, index, numElements), but they both made the new steps of type "Container" instead of type "Step" and when I tried to copy the test step it gave me an Error: "-17321; Variable or property types do not match or are not compatible."

 

Has anyone successfully done this?  Thank you in advance.

 

 

0 Kudos
Message 1 of 7
(4,255 Views)

Roger -

Typically you will have to call Step.AsPropertyObject().Clone() to get a new copy of the step, call Step.CreateNewUniqueStepId to regenerate its unique step ID, and then call Sequence.InsertStep(Step, ...) insert it into a sequence.

Scott Richardson
Message 2 of 7
(4,242 Views)

Hello,

Here's one technique for doing this, there are probably others:

1.  Call Engine.NewStep

2.  Get the Module property of the Step

3.  Cast the Module property to the apropriate module type object (note that the module types are found in a different Automation Server than the rest of the TS API objects).

4.  Use the module object to specify the module (for example, if it's a SequenceCall object you might set SequenceFilePath, SequenceName and you might get the Parameters object and add some properties to it to specify parameters).

5.  Get a reference to the sequence you want to insert the step into (probably by using SequenceFile.GetSequenceByName)

6.  Call Sequence.InsertStep with the step you created.

 

Hope that helps,

Ryan K.

Message 3 of 7
(4,241 Views)

Thank everyone for your help.  I have successfully copied test steps.  I have had one difficulty though.  If the step I copy is a function call with a relative path to the DLL and the DLL is located in the same directory as the test sequence, the copies are not able to find the DLL (the original step is able to do so).  I have "Current Sequence File Directory" selected in the search directory list.  I checked and it seems as though the paths to all of the pre-defined directories (including "Current Sequence File Directory") are empty ("") at run-time.  I don't want to add the path in the directory search list, nor do I want to hard code the path in the sequence file. 

Does anyone have a solution to this problem?  Optimally I would like to dynamically specify the absolute path to the DLL, but I couldn't find a property or process to do this.  Thank you in advance for your help.

 

 

0 Kudos
Message 4 of 7
(4,219 Views)

Interesting.  Unfortunately I don't have time right now to try to reproduce the behavior.  As a workaround, maybe you could try just constructing the path dynamically by stripping the file name off the SequenceFile.Path property and then adding the dll name to it.  Once you have the correct relative path you can assign it to the module using the apropriate property (for example CommonCModule.ModulePath for a sequence call step).  Check my previous post if you're not sure how to get the reference to the module.  I'd be interested in figuring out what is causing the step to loose the path in the first place.  Here's a few questions that might shed some light on the subject:

1.  Just to confirm, you are copying a step within a sequence file, and the sequence file is saved in the same directory as the DLL?

2. What adapter are you using?

3.  If you read the value of the path in the module object, what does it return?

That's about all I can think of at the moment, maybe Scott will have more insight.

 

Regards,

Ryan K.

0 Kudos
Message 5 of 7
(4,203 Views)
Ryan:
 
Thanks for your help.  I got it working using the workaround you suggested.  To answer your quetions though:
 
1.  Yes, I am copying a step withing a sequence file (actually within the same sequance) and it is saved in the same directory as the DLL.
 
2.  I am using the "DLL Flexible Prototype Adapter."
 
3.  If I read the value of the path in the module object (both original and copy), it returns the DLL file name (no path since it is relative).
0 Kudos
Message 6 of 7
(4,176 Views)

Roger,

That kind of makes sense, TestStand may not resolve relative paths as it executes each step, it may resolve them all at some previous point.  You might try creating the step in a sequence callback somewhere closer to the start of the execution.  However, if you've got it working I wouldn't worry about it.

 

Regards,

Ryan K.

0 Kudos
Message 7 of 7
(4,166 Views)