NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Pass Object reference from C# to teststand using "PropertyObject"

I am trying to pass the reference of an object created from C# to teststand using the PropertyObject method.

I was successfulll passing the string (code snippet given for ref)

pobj.SetValString("String_Variable", 0, "hello world!!!");

I wasnt able to pass the object reference to the teststand by the same method. I tried using

pobj.SetValInterface ("TestStand_ObjRef1", 0, cSharpObject);
pobj.SetValVariant ("TestStand_ObjRef1", 0, cSharpObject);

Can someone help me out on this regard?
0 Kudos
Message 1 of 6
(8,897 Views)
I was able to use SetValInterface successfully to pass a C# object to TestStand.  I verified that the object remained intact by sending it back to C#.  This is the code that I used to accomplish this:

public void GetObj(NationalInstruments.TestStand.Interop.API.PropertyObject p) {
            object test1 = "Hello";
            p.SetValInterface ("Locals.Test", 0, test1);
}

public void SendObj(NationalInstruments.TestStand.Interop.API.PropertyObject p) {
            object o = p.GetValInterface("Locals.Test", 0);
            System.Windows.Forms.MessageBox.Show(o.ToString());
}

In the sequence file, I simply set Locals.Test data type to be an Object Reference.  For the PropertyObject parameter, I passed in the sequence context.

Please note that this feature is not really recommended as it may yield undesired results (for example, it might affect garbage collection).

Message Edited by AndrewMc on 03-23-2007 09:35 AM

Message Edited by AndrewMc on 03-23-2007 09:35 AM

Thanks,

Andy McRorie
NI R&D
Message 2 of 6
(8,877 Views)
Thanks Andy.

I still get the error when i am trying to pass the object created from C# to Teststand. I have explained what i am trying to do. Kindly requesting your assitance on this issue.

I have 2 classes in C# (code given below), I am trying to pass the object of "Counter" (c1) class from the "Mainfrm" to teststand. In teststand(counter.seq), I am trying to access the function "GetCount() and SetCount()". I have attached the snapshot of the error that i get from teststand.

Class Counter
{
    private int count;

    public int GetCount ()
    {
       return (count);
    }

    public void SetCount(int _count)
    {
       count = _count;
    }
}

Class Mainfrm : Form
{
    public Counter c1;

        private void Mainfrm (object sender, EventArgs e)
        {
            InitializeComponent();

            axApplicationMgr1.Start();
            mEngine = axApplicationMgr1.GetEngine();
            currentFile = axApplicationMgr1.OpenSequenceFile(@"Counter.seq");
            pobj = mEngine.NewPropertyObject(NationalInstruments.TestStand.Interop.API.PropertyValueTypes.PropValType_Container, false, "", 0);

            pobj.NewSubProperty("Parameters.ObjRef1", NationalInstruments.TestStand.Interop.API.PropertyValueTypes.PropValType_Reference, false, "", 0);

            pobj.SetValInterface("Parameters.ObjRef1", 0, (object)c1);

            mExecution = mEngine.NewExecution(currentFile, "MainSequence", null, false, 0, pobj, null, null);
        }
   
   
0 Kudos
Message 3 of 6
(8,850 Views)
Ashok,

I do not believe that there is a way to actually use the object in TestStand.  While the object seems to be passed around within the sequence context, this value cannot be used with .NET steps to actually be accessed within TestStand.  That being said, I was able to pass a class out of TestStand (back into C#).  If you want to perform a given operation on the object, what I would recommend is to pass the object into a "wrapper" function that performs whatever function you want to use on that object.

I would like to reemphasize that passing objects between C# and TestStand is not a supported feature as it might yield unexpected results (for example, garbage collection might cause conflicts with this method).
Thanks,

Andy McRorie
NI R&D
0 Kudos
Message 4 of 6
(8,808 Views)

I am insterested in this as well, except that I want to be able to pass a VB.NET object as a parameter to a sequence before running the sequence. If I understand you correctly, Andy, this is not possible with TestStand.

 

I want to be able to pass a reference to some object that my UI makes use of that can be updated in the sequence or by modules called by the sequence.

0 Kudos
Message 5 of 6
(7,287 Views)