09-27-2011 02:58 AM
Hi,
I have no idea how to solve this problem. I have a .NET assembly which I am calling from TestStand. It has following structure and method:
public struct t_Param { public string Type; public string Val; public string Min; public string Max; public string Valid; }; public struct t_InputRow { public string Test_Type; public string Command; public t_Param[] Param; public t_InputRow(string aString) { this.Test_Type = aString; this.Command = aString; Param = new t_Param[4]; } };
public void GenerateOutputStrings(t_InputRow aInRow) /*! This is the method which is called from TestStand */
{
}
In teststand I have imported the above 2 struct. While importing the size of Param in t_InputRow is not defined., so I change the struct in TestStand and defined size as 4.
While running program, the following error appears in teststand.
An error occurred within the .NET code.
An error occurred while evaluating the expression for the element 'Param'.
All input parameters must have an expression specified.
-17500; Operation Failed.
Do not know how to solve this issue. Because I can not define size of pram array without using struct construct. An if I use construct, then the size is not recognized by TestStand and I have to modify the struct with size value.
Any expereince in programming this way?
Ciao
RB
Solved! Go to Solution.
09-27-2011 09:12 AM
What version of TestStand are you using? If you are not using TestStand 2010 or higher, I highly recommend you consider doing so. Many improvements and bug fixes were made to the .NET adapter in that version. It should not matter what size you set the array to on the TestStand side. If it is used as an input parameter, the equivalent sized parameter will be created on the .NET side, if it is an output parameter, the array will be resized as needed. If you are using a version of TestStand earlier than 2010, you might want to download the eval version of 2010 or later and see if the issue you are encountering has been fixed.
Hope this helps,
-Doug
09-27-2011 09:30 AM
Hi,
Since your type contains an array of structs within it, you will need to make some modifications to the type to get it working properly. By default, when you create a type from that struct, your "Param" array will have a type of "Array of Containers" since TS does not automatically map that to the corresponding type for that struct. You can modify the type (from the types pallette) and change the type of the Param field to be "Array of <your created type mapping to t_Param>".
To get struct passing to work, you will then have to go into the properties for your type and choose the .NET Struct Passing tab. You can then choose the Param field, and type in the name of the corresponding field in the struct ("Param" again in this case). This is necessary since we changed the type of that field, which clears out this setting.
You should then be able to create a variable of this type and change that array to be any size you want.
Your other option is to use your struct type as if it were a class, and create an object reference variable to store your struct object. You should be able to first use a .NET Adapter step and select t_InputRow as your "root class", and then call its constructor to create an instance of it, and store it in a local variable. You can also get and set any fields on the object using the .NET Adapter. Then, on your following step where you call GenerateOutputStrings(), you can pass your object reference variable to the method.
Let me know if you need any more clarification on any of these steps.
-Jeff
09-28-2011 09:12 AM
Thanks Jeff. It worked.
Doug, that sounds good like a fairy tale (or may be I have not tried it yet). I am using TestStand 4.2.1 and we do not wish to jump to next version in next 3 years.
09-28-2011 10:36 AM
If you are using the .NET adapter heavily, I recommend you consider upgrading, but ultimately it's up to you. You can always try out the eval version and see what you think. There have been signficant usability enhancements to the adapter as well as internal changes. You can use dot notation to access subproperties/fields and call methods on them, you can use generic types, and many other enhancements. If you are not a heavy user of the .NET adapter, then never mind.
-Doug