NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to I acquire a DotNetModule reference in vb.Net

I am using VB.Net to programatically specify the dotNet module settings for a step that I have inserted into a sequence. I have passed the Teststand sequenceContext to my VB.NET function, and I have successfully acquired a reference to the step and specified the adapter per the sample code below:

 

Dim SeqContextSequence As NationalInstruments.TestStand.Interop.API.Sequence

Dim objTSStep As NationalInstruments.TestStand.Interop.API.Step

Dim objTSModule As NationalInstruments.TestStand.Interop.API.Module

 

SeqContextSequence = SeqContext.Sequence

objTSStep = SeqContextSequence.GetStepByUniqueId(SeqContext.Step.AsPropertyObject.GetValString("TS.Id", 0))

objTSStep.Module.Step.ChangeAdapter("DotNet Adapter")   'need this, as the adapter has not yet been specified

objTSModule = objTSStep.Module

 

I now need to acquire a reference to the DotNetModule class so that I can specify the Assembly and class name to load.  Furthermore I will then need to acquire a reference to the DotNetModule Calls interface(DotNetCall) so that I can call the LoadPrototypeFromSignature method.  The problem is that I cannot acquire the derived reference to the DotNetModule.  I have read the article at: http://zone.ni.com/reference/en-XX/help/370052J-01/tsapiref/infotopics/acquiring_objects_net/ which provides a example of how to obtain a reference to a step object using the PropertyObject class PropertyObject method but cannot see how to apply this to my problem.

 

Using the API directly from TestStand it is possible to simply cast a reference e.g..;

Locals.objTSModule  = Locals.objTSStep.AsStep.Module,

Locals.ObjNetModule.AsDotNetModule.SetAssembly(DotNetModule_AssemblyLocation_File,Locals.strPathAssembly).

 

In Labview it seems it is possible to cast a reference using the Variant To Data function: https://decibel.ni.com/content/docs/DOC-16465.  However, I cannot work out how to do this in vb.NET.  Is there anyone with experience of using the Teststand API to acquire these derived classes in VB.NET who can provide a vb.NET example?

 

Regards,

 

David

 

 

 

 

 

 

 

0 Kudos
Message 1 of 2
(2,832 Views)

I found the answer to my question which was to add a reference to NationalInstruments.TestStand.Interop.AdapterAPI.  This has visibility of all of the adapter specific API classes, including those I needed. The following updated code works for me and allows me to programatically specify and load a .NET assembly in my step. It will only work with TestStand 2010 onwards as it uses the new dotNet module clases.

 

Dim objTSStep As NationalInstruments.TestStand.Interop.API.Step 'reference to TS step
Dim objTSModule As NationalInstruments.TestStand.Interop.API.Module
Dim objNetModule As NationalInstruments.TestStand.Interop.AdapterAPI.DotNetModule
Dim objDotNetCall As NationalInstruments.TestStand.Interop.AdapterAPI.DotNetCall
Dim objdotnetParams As NationalInstruments.TestStand.Interop.AdapterAPI.DotNetParameter

 

objTSStep = SeqContextSequence.GetStepByUniqueId(SeqContext.Step.AsPropertyObject.GetValString("TS.Id", 0))

'adapter is currently none so needs changing
objTSStep.Module.Step.ChangeAdapter("DotNet Adapter")
objTSModule = objTSStep.Module
objNetModule = CType(objTSModule, NationalInstruments.TestStand.Interop.AdapterAPI.DotNetModule)
objNetModule.SetAssembly(NationalInstruments.TestStand.Interop.AdapterAPI.DotNetModuleAssemblyLocations.DotNetModule_AssemblyLocation_File, _
minstrDialog.assemblyLocation)   'minstrDialog.assemblyLocation holds my assembly location
objNetModule.ClassName = minstrDialog.selectedClass   'minstrDialog.selectedClass holds the name of my class.

 

'create a new dotNet Call an set this to a dotNetCall object, then load prototype

objNetModule.Calls.[New](0)
objDotNetCall = objNetModule.Calls.Item(0)
blnLoadProtoCall = objDotNetCall.LoadPrototypeFromSignature("Use Existing Object", True, 0)  'since it already exists

'create a new parameter item and set to objdottetParams

objdotnetParams = objDotNetCall.Parameters.Item(0)
objdotnetParams.DisposeObject = True
objdotnetParams.ValueExpr = "StationGlobals.Driver.DeviceParamsArray[1].ClassRef"  'this is wher my existing object reference is called.

 

Maybe this wil help someone someday?

 

Regards,

 

David

Message 2 of 2
(2,806 Views)