NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

how to pass parameter values to the string object in teststand sequence file programatically using c#

I have created a dll named ClassLibrary1.

Class named as class1 defining a property returning a string.

 


I am developing a window application using .Net to create a sequence file dynamically in test stand.

The code in .Net is

 

            EngineClass myEngine = new EngineClass();

            myEngine.LoadTypePaletteFilesEx(TypeConflictHandlerTypes.ConflictHandler_Prompt, 0);

          

            Step myStep = myEngine.NewStep(AdapterKeyNames.DotNetAdapterKeyname,StepTypes.StepType_Action);

            myStep.Name = "CreatesrtingObject";

 

            DotNetModule dotnetmodule = myStep.Module as DotNetModule;

           

//calling the dynamic link library.

 dotnetmodule.SetAssembly(DotNetModuleAssemblyLocations.DotNetModule_AssemblyLocation_File,@" C:\Documents and Settings\My Documents\Visual Studio 2005\Projects\ClassLibrary1");

 

//specifying the classname.

            dotnetmodule.ClassName = "Class1";

            dotnetmodule.MemberType = DotNetModuleMemberTypes.DotNetMember_GetProperty;

            dotnetmodule.MemberName = "stringobject"

Sequence mySequence = myEngine.NewSequence();

 

//creating an string object in the action step.

          mySequence.Locals.NewSubProperty("stringobject", PropertyValueTypes.PropValType_String, false, "", 0);

//Getting the property object

                mySequence.Locals.GetPropertyObject("stringobject",0);

                Class1 value = new Class1();

                string svalue = value.Reference;

                mySequence.Locals.GetValString("stringobject", 0);

 

//Here I need to pass the parameter values from the .Net to the TestStand stringobject.

Download All
0 Kudos
Message 1 of 2
(3,863 Views)

When you assign the DotNetModule.ClassName, you must assign the full class name of your type, including the namespace. For example, if your namespace is ClassLibrary1 and your class is Class1, you should be doing DotNetModule.ClassName = "ClassLibrary1.Class1";

 

You will then have to specify whether you are creating the object (DotNetModule.CreateObject), or you already have an existing object and will be using an object reference to access it (DotNetModule.ClassReference). If your class contains one or more constructors, you will also need to define the appropriate constructor (DotNetModule.LoadConstructorPrototypeFromMetadataToken(), this is not trivial; see the forum post linked below for a discussion of this method). If the class has not defined a constructor, then TestStand will automatically handle that for you.

 

Once you've specified the DotNetModule.MemberName, you must decide how you want to populate the parameter table for this member. You can either manually create the parameter elements, or you can use the TestStand API to populate it for you (DotNetModule.LoadPrototypeFromMetadataToken(), this is also not trivial; again, see the forum post linked below for a discussion of this method).

 

Finally, once you've populated the parameter table for the member, you should be able to access the specific parameter using DotNetModule.Parameters to get a collection of the parameter elements (this returns an object reference of type DotNetParameters). Using DotNetParameters, you can get the number of parameter elements (DotNetParameters.Count) and index through them (DotNetParameters.Item; this returns an object reference of type DotNetParameter). Once you've found the specific parameter you would like to read/configure, you can use the properties and methods of the DotNetParameter class to do so.

 

The DotNetModule.LoadConstructorPrototypeFromMetadataToken() and DotNetModule.LoadPrototypeFromMetadataToken() methods require that you provide a Metadata Token value that corresponds to the particular constructor and member that you want to use. The TestStand API does not provide a straight forward way of getting this MetadataToken value. As mentioned earlier in this post, please see my post on the forum thread linked below for a discussion on programmatically creating DotNet Steps and using the MetadataToken methods to do so:

 

API TestStand for ModuleAdapter DotNet

 

Hope this helps.

Manooch H.
National Instruments
0 Kudos
Message 2 of 2
(3,842 Views)