NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Examples on .NET and TestStand using TS API

Hi
Are there some examples using theTestStand API in .NET. I am looking to use the API functions, and not the UI controls.
Thanks
 
0 Kudos
Message 1 of 9
(7,183 Views)
Hi webprofile,

There are quite a few programs that can be found in the TestStand examples directory. Please look in the following location for an example written in VB.Net:
[TestStand Install Location]\Examples\Demo\dotnet

You may also want to examine the operator interfaces written in C# and VB.Net:
[TestStand Install Location]\OperatorInterfaces\NI\Full-Featured\CSharp
[TestStand Install Location]\OperatorInterfaces\NI\Full-Featured\VB.Net

For more details about TestStand API, please refer to the section in the TestStand help titled:
"Using the TestStand API in Different Programming Languages"

Regards,
Message 2 of 9
(7,149 Views)

I am wanting to read .NET assemblies then programmability call these from teststand.  For instance, I have a configuration file, listing instrument drivers that are written in .NET.  I can read the contents of the configuration file and store the assembly location and class that I want to construct in my StationGlobals.  Now what I need to be able to do is to create the required class as part of a sequence that runs when teststand loads. This would create an object reference that instances of the step use in my test sequences (as existing object).  

 

The solution would seem to be to use the DotNetModule API class functions to obtain information about my assembly then use the DotNetCall class to create the reference.  The problem is there are precious few examples of how to use the TestStand API from .NET.  The example in the demo directory only shows how to call .NET modules and the topic in the Help file only lists examples in Labview and CVI.

 

I did find four examples of how to use the PropertyObject on .NET but that's about it.  Does anyone have any other examples of how to access the TestStand API in .NET, or ideas on how to accomplish this task?

 

Regards,

 

David

0 Kudos
Message 3 of 9
(6,643 Views)

Hi David

 

Have you ever visited this thead:

http://forums.ni.com/t5/NI-TestStand/How-can-you-pass-Parameters-Result-from-TestStand-to-NET-C/m-p/...

 

It is half the battle, if you have access to TestStand's API Class PropertyObject.

From it you will get access to most other API objects.

 

I recommend to take a look on the Help(F1) that comes with TestStand

or take a look on the API reference poster.

 

Hope this helps

Juergen

 

 

  

 

 

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 4 of 9
(6,634 Views)

@David Jackson wrote:

I am wanting to read .NET assemblies then programmability call these from teststand.  For instance, I have a configuration file, listing instrument drivers that are written in .NET.  I can read the contents of the configuration file and store the assembly location and class that I want to construct in my StationGlobals.  Now what I need to be able to do is to create the required class as part of a sequence that runs when teststand loads. This would create an object reference that instances of the step use in my test sequences (as existing object).  

 

The solution would seem to be to use the DotNetModule API class functions to obtain information about my assembly then use the DotNetCall class to create the reference.  The problem is there are precious few examples of how to use the TestStand API from .NET.  The example in the demo directory only shows how to call .NET modules and the topic in the Help file only lists examples in Labview and CVI.

 

I did find four examples of how to use the PropertyObject on .NET but that's about it.  Does anyone have any other examples of how to access the TestStand API in .NET, or ideas on how to accomplish this task?

 

Regards,

 

David



What version of TestStand are you using? This (programmatically specifying .NET steps) is easier to do in TestStand 2010 than in previous versions. Look at the dotnetmodule, dotnetcall, dotnetparameter and other APIs. You basically would use the engine to create a new sequence file and create a new .NET Action step and insert it into the sequence file and then specify it (using the previously mentioned APIs) and then execute it. It's doable, but not trivial. It might be simpler for you to just implement the logic inside of a .NET module and then just return the reference back up to teststand. In otherwords you could write a code module that reads your config file and creates an instance of the specified class (likely via reflection). Then from teststand you could call that code module to get the reference into teststand. Do you have some common base class for your drivers or something? Otherwise how do you even plan on using this reference from preconfigured steps in teststand?

 

Hope this helps,

-Doug

0 Kudos
Message 5 of 9
(6,622 Views)

Thanks Doug and Juergen for your advice.  I am using Teststand 2010 SP1 which has the new .NET API.  I did follow Juergen's link and found his excellent Builder sequence illustrating the use of some of these API's within Teststand expression steps. This illustrates much of what I want to do, so is an excellent start.  In my application it would be advantageous to create similar functionality within my .NET module using the latest .NET API functions.

 

I'll update you once I've made some progess.

 

Regards,

 

David

0 Kudos
Message 6 of 9
(6,613 Views)

I've found that the new .NET API should make things easier in that there is a function of the DotNetCall class called LoadPrototypeFromSignature that will load the parameter's and prototype information in one go (rather than needing multiple functions via the old API).  Trouble is I am unable to get a reference to an object of type DotNetCall. I've been using Juergen's builder sequence as an example and modifying the Add Assembly to Step statement slightly to try and create this. I've created a new local to hold a DotNetCall object reference and tried to create this using the DotNetCalls.New(index) method, which according to Teststand help "Creates a new DotNetCall object and inserts it into the collection at the specified index." I then want to use the LoadPrototypeFromSignature method on this object.

 

The problem is that I am unable to create an object reference of type DotNetCall; when I call this method I find that I don't have an object refrence of the right type. This is what I have (based on the Builder sequence): My added line is in italics.


// We know that that is NET so we can get the NET Module
Locals.ObjNetModule = Locals.ObjStep.AsStep.Module,
// Path Assembly and Class
Locals.NetModuleProperties.strPathAssembly = Locals.strCurrentDirectory+Locals.NetModuleProperties.strAssemblyName,
// Set the Assembly
Locals.ObjNetModule.AsDotNetModule.SetAssembly(DotNetModule_AssemblyLocation_File,Locals.NetModuleProperties.strPathAssembly), // Make absolute for loading Prototype
Locals.ObjDotNetCall = Locals.ObjNetModule.AsDotNetCalls.New(Locals.MemberIndex). 

 

The error I get is "Incorrect Object Reference type in 'ObjNetModule'. A reference to an object of type 'DotNetCalls' was expected"

 

I know I'm problem missing something simple and obvious here but how should I get a reference to the DotNetCall class so that I can use LoadSignatureFromPrototype?

 

Regards,

 

David

 

 

0 Kudos
Message 7 of 9
(6,593 Views)

I see the problem. The call to New() does not return the dotnetcall it just creates it in the collection. API in expressions always returns something, even for void methods (I know this is odd, but it's an implementation detail), thus you are getting a misleading error message. The real error is that New() doesn't return anything and you are trying to store a return value for it. Get the call from Locals.ObjNetModule.AsDotNetModule.Calls.Item(index) instead.

 

Actually I just realized you are getting the calls collection incorrectly too. It should be done as follows:

 

Locals.ObjNetModule.AsDotNetModule.Calls.New()

 

 

Hope this helps,

-Doug

0 Kudos
Message 8 of 9
(6,577 Views)

I just want to add that rather than use an absolute path, if you want your code modules to be relative to the sequence file, you should save the new sequence file first, insert your step into it, and then specify paths relative to it for the modules.

 

-Doug

0 Kudos
Message 9 of 9
(6,568 Views)