01-29-2013 06:07 AM
I guess this is another fairly basic question:-
I am using just one step at the moment to do what I want to do and reprot back after it's done; I would ultimately like to use properties as the current method has considerable drawbacks. Problem is: the "object" appears to be disposed as soon as the step has finished executing. How can I make an instatiation stay for long enough to get the data out using properties ?
I hope this made sense to everybody. Coding in C#
Solved! Go to Solution.
01-29-2013 09:20 AM
Make the prototype to your C# method have "out" or "byref" parameters and pass in TestStand variables for those, such as Local variables, or per-step variables.
Hope this helps,
-Doug
01-29-2013 10:08 AM
Thanks Dug but this isn't how properties work. I have done an example to illustrate my problem:-
public classExampleClass//Here's my exmaple class
{
private double variable1; //I want to get this value
private double variable2; //but it is only in existance when the class is instatiated
void ExampleClass() { }
public double Variable1 // so when access this property
{ get {return variable1;} // the variable can only ever be 0 / unititialised.
set {variable1 = value;}
}
public double Variable2
{ get {return variable2;}
set {variable2 = value;}
}
//of course I can call my method and pass data in and out but this isn't a very good solution in some instances.
publicvoid ExampleMethod(SequenceContext seqContext, double variable3, outdouble variable4, outString reportText, outbool errorOccurred, outint errorCode, outString errorMsg)
{
reportText = String.Empty;
errorOccurred = false;
errorCode = 0;
errorMsg = String.Empty;
variable4 = 0.0;
/******************************************************************************************************************
--DO SOMETHING--
*********************************************************************************************************************/
}
}
01-29-2013 10:15 AM
Oh I thought you meant teststand properties. The word "property" is way too generic. 🙂
What you need to do is store a reference to your .NET object in a TestStand Object Reference variable. When you call the constructor from teststand there is a place where you can specify a variable to store it. Then, when you want to access data on that object from another .NET step, specify the "Use Existing Object" option as the first call rather than the constructor, and specify the variable in which you previously stored the .NET object you want to make the call/property access on.
Hope this helps,
-Doug
01-30-2013 01:35 AM
Thanks Doug,
I thought there would be a way; I will give it a go.
01-31-2013 04:34 AM
Ok, it's all working with my simple example: my thanks extended to everyone for their help. One last thing that should be a big problem for my current project but I can foresee could be in the future:-
What happens when you no longer want your object; should you set the reference to Null to dispose it ? I think in C# it is less important to dispose of things because they are automatically marked for garbage collection when they move out of context but this wouldn't be the case if TestStand maintained a reference to it ?
I'm not overly worried, I just like to understand a bit more about how it works.
Many thanks
01-31-2013 09:19 AM
Similarly to C#, as long as TestStand has a reference to an object stored in one of its variables, the object will not get garbage collected. Also, similarly to C# when the last reference to that object goes out of scope or is lost due to the variable being set to something else (such as Nothing), then the object is subject to garbage collection. Disposing of objects is something entirely different from garbage collection. It is a way to tell objects to immediately cleanup any unmanaged resourced they might be holding onto. The TestStand .NET Adapter has support for marking references as requiring Dispose to be called on them by checking a checkbox next to the place where you specify the variable in which to store the reference. When that variable goes out of scope or is set to something else, then Dispose will be called on that object.
Hope this helps,
-Doug
01-31-2013 09:27 AM
Thanks Dug,
You've come through with the answer again. That is very helpfull to know.
Cheers