03-02-2012 05:40 PM
Hello,
I'm trying to figure out how to return a Container object to TestStand that is populated with one or more values (of mixed types... strings, numbers, etc) from a C# DLL method call.
Is this possible?
Thanks!
03-02-2012 09:40 PM
You will need to create a custom data type in TestStand that matches the struct. You will then need to specify how to map the struct to the data type through the .NET Struct Passing dialog.
http://zone.ni.com/reference/en-XX/help/370052J-01/tsref/infotopics/db_datatypeprop_netstruct_tab/
You can do this automatically if you have an Assembly with the struct defined through the .NET Pane.
http://zone.ni.com/reference/en-XX/help/370052J-01/tsref/infotopics/pane_module_net/
See the section: Create Type from Struct
03-05-2012 12:38 PM
Thanks for the reply. I understand now how to work with structs that are defined ahead of time, but the DLL we have deals with dynamic data and the structure of the returned data is unknown until runtime. I don't see any way to handle that in the references you posted. Did I overlook something?
-Aaron
03-05-2012 03:35 PM - edited 03-05-2012 03:37 PM
Keep using propertyobjects and a container as the return value like you probably are doing. Return the container into an Object Reference variable (not a container variable). Then, if you really want to make it a local variable directly, rather than a object reference, so you can directly access it with expressions, do something like the following:
If you are sharing the container with other things:
Locals.SetPropertyObject("MyNewLocal", PropOption_InsertIfMissing | PropOption_NotOwning | PropOption_ReferToAlias, Locals.MyreturnValStoredinAnObjectReferenceVariable)
If the returned container is now owned and referenced only by the sequence:
Locals.SetPropertyObject("MyNewLocal", PropOption_InsertIfMissing, Locals.MyreturnValStoredinAnObjectReferenceVariable)
If you want to make a copy of the container that was returned:
Locals.SetPropertyObject("MyNewLocal", PropOption_InsertIfMissing, Locals.MyreturnValStoredinAnObjectReferenceVariable.Clone("", PropOption_DoNotShareProperties | PropOption_CopyAllFlags)
Hope this helps,
-Doug