NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing Object Reference from C#

Hi,

 

I am developing a script that shows FileGlobals variable inside a small C# interface, a sort of debugging view to keep track of a couple of variable while testing units.

 

I managed to display an Array of number that shows as is in TestStand:

ThomasPujolle_0-1593700818944.png

The corresponding C# script is as follow (ObjectList is in FileGlobals):

private NationalInstruments.TestStand.Interop.API.SequenceContext mSequenceContext;

this.objList=this.mSequenceContext.FileGlobals.GetPropertyObject("ObjectList",0);
double[] myArray = (double[])this.objList.GetValVariant("", 0);
this.testLabel2.Text = myArray[0].ToString() + " " + myArray[1].ToString();

In the label I can read "1 5", great success ! 

 

Now I want to reproduce the same thing but with an Array of Object References, here seen in TestStand:

ThomasPujolle_2-1593701546573.png

 

 

 

Should I also start with this.mSequenceContext.FileGlobals.GetPropertyObject ? Does this work as a general approach to retrieve any object?

 

I'm a bit lost when it comes to what to do after that, any help much appreciated.

 

Thanks

 

0 Kudos
Message 1 of 4
(2,285 Views)

If you look at the API for property objects there are a whole bunch of GetValXXX and SetValXXX methods.  https://zone.ni.com/reference/en-XX/help/370052AA-01/tsapiref/reftopics/propertyobject/

 

Some of them say GetValxxxByOffset.  These are used to index arrays.  In your case you could do:

 

this.obj = this.mSequenceContext.FileGlobals.GetValIDispatchByOffset()

https://zone.ni.com/reference/en-XX/help/370052AA-01/tsapiref/reftopics/propertyobject_getvalidispat...

 

Hope this helps,

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 2 of 4
(2,281 Views)

Right ok, I think I got to that point some other way but this.obj is just a C # object and I could not find a way to retrieve the value of what it was pointing to.

0 Kudos
Message 3 of 4
(2,264 Views)

Got it ! To display first element:

this.objList2 = this.mSequenceContext.FileGlobals.GetPropertyObject("ObjectList2", 0);
private NationalInstruments.TestStand.Interop.API.PropertyObject t;

dynamic[] v = this.objList2.GetValVariant("", 0);
this.t = (NationalInstruments.TestStand.Interop.API.PropertyObject)v[0];

t.GetValNumber("", 0).ToString(); // here is the value !

 

0 Kudos
Message 4 of 4
(2,227 Views)