NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I programmatically attach to a automation server using TestStand?

I am working on a piece of code that will programattically build a teststand sequence using the TS engine API. The sequence will consist primarily of calls to properties and methods on automation servers already loaded into memory (ie I have already created the server and maintain a smart pointer to it). The first step of the sequence will be to attach to the in memory automation server and write the server reference to a local activeX reference variable. I can do this quite easily using the sequence editor, but fail to see how to do it programmatically?

As a bonus question, I also need to know how to programmatically add a activeX reference local variable (one per server that I will be accessing dur
ing the sequence).

Thanks,

Aaron
0 Kudos
Message 1 of 4
(3,688 Views)
Aaron,

I believe what you are asking is how to "Specify Module" for a step that uses the ActiveX Automation adapter. Specifically, you probably want to know how set the value of the Create Object ring control to Attach to Active. Correct me if I am wrong.

There is nothing specific in API for configuring these settings. However, these settings are stored in hidden properties of the step. You can view them by enabling Show Hidden Properties in the Station Options, and then expanding the tree view for your step. The properties of interest are under the branch, Step.TS.SData.Call. You can modify the value of these properties either using expressions or using the Property Object methods of the TS API (e.g. SetValNumber). To change the step property setting for A
ttach to Active, you would change the value of Step.TS.SData.Call.CreateObject to 1.

There are limitations to the hidden step properties that you are changing. Please read the Developer Zone article "Hidden Properties of TestStand" before using the properties.
http://zone.ni.com/devzone/conceptd.nsf/2d17d611efb58b22862567a9006ffe76/246f6c77f5ad473e86256a2c0055c0d0?OpenDocument


As to creating a local variable of ActiveX type, you can use the SetValIDispatch or SetValInterface on the Locals property. Set the option of these methods to 1 (insert if missing) and set the new value to Null or Nothing depending on your programming environment. This will insert the ActiveX variable.

One word of worning. Technically creating and editing sequence files programmatically makes the machine on which your application runs subject to a TestStand development license. This is to prevent people from developing their own sequence editor and using it/distributing it/selling with a less expe
nsive TS run-time license. The run-time license is designed for running test sequence rather than creating them.

Hope this helps.
0 Kudos
Message 2 of 4
(3,688 Views)
Thanks, that really helps. However, I am a little alarmed by the statement "The properties under Step.TS.SData cannot currently be accessed using the API properties of the Step class". Is that for 1.0 only? If that's true it means I can't programmatically add an ActiveX Automation step to a sequence and all is for nought! The horror!

Out of curiousity I wrote some code to read Step.TS.SData.Call.CreateObject from a step on a pre-existing sequence file and write back the value plus one. I then did another read and it came back with the modified value. Does that mean it worked? I can send the code if you want.

I tried stepping through some sequences with a watch on Step.TS.SData.Call.CreateObject. It looks like TS has the following enum defined somewher
e.

0 Create a new object
1 Attach to in memory instance of object
3 Use the TS.SDATA.CALL.OBJECTVARIABLE activeX reference

It appears that specifying an activeX reference variable in TS.SDATA.CALL.OBJECTVARIABLE while using a CREATEOBJECT setting of 0 or 1 will result in OBJECTVARIABLE to be set with the result of the object creation, nes pas?

Aaron
0 Kudos
Message 3 of 4
(3,688 Views)
You missed one enumeration (2).

0 Create a new object
1 Attach to in memory instance of object
2 Create From File
3 Use the TS.SDATA.CALL.OBJECTVARIABLE activeX reference

Yes you can create a step that uses any adapter with the TS API. There does not exist specific API methods for specifying the module settings for a step. Instead you must update the values of the hidden properties using SetVal... methods. This WILL allow you to specify the module for a step.

If you think about it, specifying the module really falls under the domain of the adapter being used for a step rather than the step itself. Consider that an Action step has a different way for specifying its module depending on the adapter that it uses. Thus SData for a step
changes depending on the adapter used. In the future TS may include API methods for specifying the module for a step. Until then, you will have to do this by modifying the hidden properties of the step.

There are drawbacks to using the hidden properties that are explained in the link I sent previously. They include
- the hidden properties (or their enumerated values) could change in futures versions of TestStand, breaking your code.
- When using the API to make changes (when/if it is developed) TestStand may perform other actions than simply changing the value of a property (e.g. could faciltate selecting the values)
- TestStand does not make run-time copies for the subproperties of Step.TS.SData. Any changes that you make to the values of these subproperties affect all current run-time copies of the step and the original version of the step that the sequence file window displays. If you are only setting the SData values of a sequence that you are creating, rather than modifyi
ng SData of an executing sequence, then this should not be a problem.

I've attached a sequence file that gives you a start on how to make the changes you want.
0 Kudos
Message 4 of 4
(3,688 Views)