ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Exchange data with TestStand from a python thread

Probably the easiest way to pass data would be with a TestStand queue where you give it a name beginning with an '*' character so that it is shared across processes. See the API help for Engine.GetSyncManager() as a starting point. The sync manager API is also used by the synchronization step types (the queues created by them are one and the same).

 

-Doug

0 Kudos
Message 11 of 14
(2,354 Views)

Is their a way to pass an object reference from TestStand to a python script? Has anybody had success using IronPython (basically as a .NET wrapper). I'm not sure how to pass a COM object via the command line. It'd be great if you can directly pass a reference, like ThisContext, to a python script but I can't find anybody tackling this on the forums.

0 Kudos
Message 12 of 14
(2,330 Views)

I have not used IronPython; howerver, since it is only a .NET wrapper you can use COM Interop to communicate with TestStand. For more information on this, depending on your specific IronPython version see http://blogs.msdn.com/b/shrib/archive/2008/04/10/ole-automation-idispatch-support-in-ironpython.aspx

 

The name for the COM reference is "NationalInstruments.TestStand.Interop.API", the GUID can be found in the registry under HKEY_CLASSES_ROOT\CLSID (or HKEY_CLASSES_ROOT\Wow6432Node\CLSID in 64-bit systems), just search for the COM reference name.

0 Kudos
Message 13 of 14
(2,293 Views)

 

I have been trying to pass data to Teststand from python/pywin32 and the com interface.

 

I can connect to a running Teststand sequence which creates a queue "*GlobalQueue" and get a the created queue name, however i am unable to get data into the queue using the enqueue method.

 

Code

 

import win32api
import win32com.client
import pythoncom

QUEUE_NAME = "*GlobalQueue"

#Get Engine Reference.
testStandEngine = win32com.client.Dispatch("TestStand.Engine.1")
print ("TestStand Ver: ",str(testStandEngine.MajorVersion)+"."+str(testStandEngine.MinorVersion),"Ready")

#sync with TS engine
syncMgr = testStandEngine.GetSyncManager(QUEUE_NAME)

queue = syncMgr.GetQueue(QUEUE_NAME)
while queue == None:
    print("Unable to get queue:",QUEUE_NAME)
    queue = syncMgr.GetQueue(QUEUE_NAME)

print("Found Queue:",queue.Name)

# TS enqueue usage
# http://zone.ni.com/reference/en-XX/help/370052G-01/tssuppref/reftopics/queue_enqueue_m/
# Queue.Enqueue ( atFront, full Q Option, newElementPropObj, byRef, timeoutInSeconds, sequenceContextObj, processMsgs, waitRes, enqueueRes)

waitRes = -1
enqueueRes = -1
data = "test"
seqContext = None

#create queue object
queueObject = testStandEngine.NewPropertyObject(1, False, "", 0)
queueObject.SetValString("", 0, "Test");

print(queueObject.GetValString("",0))

#create sequence object.
seqObject = testStandEngine.NewPropertyObject(5, False, "", 0)
print(seqObject.GetTypeDefinition ("", 0))
queue.enqueue(False, 0, queueObject, False, 5, seqObject, True,waitRes,enqueueRes)

The error i get is an exception;

 

 

TestStand Ver: 14.0 Ready
Found Queue: *GlobalQueue
Test
None
Traceback (most recent call last):
File "C:\ts\pyTS.py", line 48, in <module>
queue.enqueue(False, 0, queueObject, False, 5, seqObject, True,waitRes,enqueueRes)
File "<COMObject GetQueue>", line 2, in enqueue
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'TSSync', None, None, 0, -2147467261), None)
>>>

I have tried using the OLEviewer and found the prototype.

enqueue.png

 

Any help would be apprieciated.

 

Thanks in advance

Tim

 

 

0 Kudos
Message 14 of 14
(2,075 Views)