09-22-2011 01:33 PM
Currently, I have TestStand calling some Python code to run some of our tests. I'm wondering if it's possible to have the Python code manipulate variables from the running TestStand instance? This post shows how to access the TestStand API from Python: http://forums.ni.com/t5/NI-TestStand/Exchange-data-with-TestStand-from-a-python-thread/m-p/1314571#M...
Based on what I've read, it seems that when you get a handle on an ActiveX/COM Engine object, its not the same Engine as is currently running (that called the python script). (see post 6 of this post: http://forums.ni.com/t5/NI-TestStand/using-C-as-User-Interface-in-TestStand/m-p/1404192#M31492).
If this is true, then the engine I get in Python isn't the engine I want.
Can anybody confirm/deny?
09-23-2011 09:03 AM
Does your python code run in the same process as TestStand or is it launched as a separate executeable? If it is in the same process then it will be the same engine. If it's in a separate process than you need to pass a reference to the TestStand API objects across processes somehow. If it's out of process let me know and I will suggest some ways to pass the references across processes.
-Doug
09-23-2011 10:21 AM
Thanks for the quick response Doug. I'm using the "call executable" step type to run the Python script. Python runs in a separate process.
09-24-2011 09:14 AM
Ok. Probably the easiest way to pass a reference across processes is to use the TestStand synchronization step types and corresponding synchronization manager API. On the TestStand side, before launching your python process, create a queue or notification (using the corresponding synchronization step type), giving it a name that begins with an '*' character. Synchronization objects whose name begins with an '*' character are global per machine. Then before, launching your python app, either enqueue the reference you wish to pass to python or set the notification with such a reference. Then inside of your python code, create a new instance of the engine, and call GetSyncManager() on it with the name you used for your queue or notification. You also need to import the TestStand synchronization manager type library, which will then allow you to convert the sync manager reference to a SyncManager data type. Call GetQueue or GetNotification on it, then call the corresponding method on the queue or notification to dequeue or wait for the notification. You will need to create a destination object using the engine as follows: engine.NewPropertyObject(PropValType_Reference, false, "", 0). See the API help for teststand for more information.
Hope this helps,
-Doug
09-26-2011 11:01 AM
Thanks for the response, Doug. That's more complicated than I was anticipating, so I will stick with using return values for now.