I\'m trying to write some Python code to talk to the Thorlabs APT ActiveX control. I\'m basing my code on the code found on this page, but trying to use PyQt4 ActiveX container
Turns out I had the syntax quite wrong, worked it out by using the generateDocumentation()
function as mentioned here, and some parameter help from here. The working code looks like:
import sys
from PyQt4 import QtGui
from PyQt4 import QAxContainer
from PyQt4.QtCore import QVariant
class APTSystem(QAxContainer.QAxWidget):
def __init__(self, parent):
super(APTSystem, self).__init__()
# connect to control
self.setControl('{B74DB4BA-8C1E-4570-906E-FF65698D632E}')
# required by device
self.dynamicCall('StartCtrl()')
# args must be list of QVariants
typ = QVariant(6)
num = QVariant(0)
args = [typ, num]
self.dynamicCall('GetNumHWUnits(int, int&)', args)
# only list items are updated, not the original ints!
if args[1].toInt()[1]:
print 'Num of HW units =', args[1].toInt()[0]
self.dynamicCall('StopCtrl()')
app = QtGui.QApplication(sys.argv)
a = APTSystem(app)
The second item in the args
list contains the correct value, but num
is never updated by the call.