NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to access the attributes in an object using TestStand.?

Solved!
Go to solution

hi,

 

I have a class named Status in C# that has 2 data members. There is another Class named Parameter and it has functions that return objects of type Status.

 

I made the DLL of the class Parameter. Then i added that class to NI TestStand and called a fucntion and that function is returning an object of type Status.

 

Is there any way by which i can access the Data Members of the returned Object in TestStand ??

 

Thanx in advance

0 Kudos
Message 1 of 6
(5,653 Views)

If I understand you correctly you are using a .NET step to get the object of type Status and storing that in a local variable of type Object Reference. If so then you can just use that in a second .NET step where you specify Status as the class and your local variable for the class object expression and then you should be able to get and set fields or properties or call methods on the Status object.

 

If I have misunderstood you, please post some example code to illustrate what you mean.

 

Hope this helps,

-Doug

0 Kudos
Message 2 of 6
(5,636 Views)

Thank you for your response.

 

Now here is the signature of the function that i am calling from .NET DLL in TestStand

 

public Status DePressModeButton()

 

Now this functions is returning Status Object. I store this Object in a Local variable in testStand using ObjectReference.

 

Now the class Status Object has the following Data Members:

 

 

private bool errorOccurred;
        private string errorMessage;

 

private bool errorOccurred;  

        private string errorMessage;

 

What i want to do is i want to Access these Data members from the local Vairable in TestStand.

 

So how can we do that ?

 

Sorry i am a newbie in test stand and this is my first assignment. So kindly help me. Thanks in advance.

0 Kudos
Message 3 of 6
(5,626 Views)

I got what you said in ur post and it is working. Thank you for this.

 

But the problem is there are around 6 DLLs and almost each function returns a Status Object. If i follow what you said then after each step in TestStand scipt i will have to add another step.

 

So is there any other solution to this new problem ??

0 Kudos
Message 4 of 6
(5,620 Views)
Solution
Accepted by topic author rogerz

Yes, there is another alternative. If you make Status a value type (i.e. a struct in C#) then you can tell teststand to store it in a corresponding TestStand data structure rather than an object reference variable. This works even for private fields in your struct. To do this:

 

1) First make Status a value type and make whatever other changes are necessary in your code to account for this (value types are copied when passed by value to another method, if this is not what you want you will need to pass them by reference - i.e. ref keyword in C#).

2) Recompile your assembly.

3) In the TestStand .NET module specification panel you should now see a new button next to the expression for the return value of type Status that looks like the TestStand data type icon. Push that button and it will prompt you to create a TestStand custom data type that corresponds to the .NET type. Select to save the type in MyTypes.ini type palette file. You only need to do this once. Once the type is in your MyTypes.ini type palette file it will be available from then on and you only need to update it if you change the .NET type.

4) Create a local variable of the TestStand Custom data type instead of Object Reference. Note that you can expand it and see the properties underneath.

5) Use this new local variable to store the Status return value. TestStand will copy/update the properties of the variable to correspond to those of the .NET struct that the method returns.

 

NOTE: You can also just store the individual fields of a struct in separate variables by expanding the return value of type Status once it's a struct and specifying a separate variable for each field rather than creating a TestStand custom data type.

 

Keep in mind that TestStand is making a copy when you store a struct this way so changes to the struct after this will not be reflected in the copy.

 

Hope this helps,

-Doug

0 Kudos
Message 5 of 6
(5,602 Views)

Hey,

 

Thank so much. I tried it today and it is working now. Thank You so much.

0 Kudos
Message 6 of 6
(5,571 Views)