我有一个带有两个简单按钮的小 GUI,用于访问 LabJack IO 模块。该模块用于打开或关闭与其连接的外部设备。我编写了一个初始化设备的类和几个方法来对设备做一些事情,其中两个是打开和关闭。我要以这种方式访问 LAbJack 的原因是因为我希望代码简洁明了,并且我将有多个设备连接到我的机器,每个设备都有特定的 IO 命令。
这是我的 LabJack 代码:
import u3
class LabJack:
def __init__(self):
try:
self.Switch = u3.U3()
except:
print "Labjack Error"
#Define State Registers for RB12 Relay Card
self.Chan0 = 6008
Chan1 = 6009
Chan2 = 6010
Chan3 = 6011
Chan4 = 6012
Chan5 = 6013
#Turn the channel on
def IO_On(self,Channel):
self.Switch.writeRegister(Channel,0)
#Turn the channel off
def IO_Off(self,Channel):
self.Switch.writeRegister(Channel,1)
#The State of the Channel
def StateSetting(self,Channel):
self.Switch.readRegister(Channel)
if Switch.readRegister(Channel) == 0:
print ('Channel is On')
else:
print('Channel is Off')
#Direction of Current Flow
def CurrentDirection(self,Channel):
self.Switch.readRegister(6108)
print self.Switch.readRegister(6108)
这是我的 GUI 代码:
import re
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
from LabJackIO import *
from Piezo902 import *
import ui_aldmainwindow
class ALDMainWindow(QMainWindow,ui_aldmainwindow.Ui_ALDMainWindow):
def __init__(self, parent=None):
super(ALDMainWindow,self).__init__(parent)
self.setupUi(self)
self.ValveControl = LabJack()
self.Valve_ON.clicked.connect(self.ValveControl.IO_On(6008))
self.Valve_OFF.clicked.connect(self.ValveControl.IO_Off(self.ValveControl.Chan0))
self.statusBar().showMessage('Valve Off')
app = QApplication(sys.argv)
app.setStyle('motif')
form = ALDMainWindow()
form.show()
app.exec_()
运行代码时出现以下错误:
Traceback (most recent call last):
File "ALDSoftwareMainWindow.py", line 26, in <module>
form = ALDMainWindow()
File "ALDSoftwareMainWindow.py", line 20, in __init__
self.Valve_ON.clicked.connect(self.ValveControl.IO_On(6008))
TypeError: connect() slot argument should be a callable or a signal, not 'int'
我无法弄清楚我做错了什么。任何帮助将不胜感激。
谢谢。