|
|||||||||||||
07-26-2012 06:17 PM
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.St
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
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(Dot
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
07-30-2012 12:26 AM
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.D
Dim objDotNetCall As NationalInstruments.TestStand.Interop.AdapterAPI.D
Dim objdotnetParams As NationalInstruments.TestStand.Interop.AdapterAPI.D
objTSStep = SeqContextSequence.GetStepByUniqueId(SeqContext.St
'adapter is currently none so needs changing
objTSStep.Module.Step.ChangeAdapter("DotNet Adapter")
objTSModule = objTSStep.Module
objNetModule = CType(objTSModule, NationalInstruments.TestStand.Interop.AdapterAPI.D
objNetModule.SetAssembly(NationalInstruments.TestS
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].ClassR
Maybe this wil help someone someday?
Regards,
David
My Profile | Privacy |
Legal |
Contact NI
© 2011 National Instruments Corporation. All rights reserved. | E-Mail this Page
|
||

E-Mail this Page