我有一個帶有兩個簡單按鈕的小GUI來訪問LabJAck IO模塊。該模塊用於打開或關閉連接到它的外部設備。我已經寫了一個類,在設備和幾種方法來做一些事情與設備兩個是打開和關閉。我以這種方式訪問LAbJack的原因是因爲我希望代碼更加美觀和整潔,並且我將有幾臺設備連接到我的機器,每臺設備都有特定的IO命令。從pyQT中的類訪問方法
這裏是我的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'
我不知道我做錯了什麼。任何幫助將不勝感激。
謝謝。
0123ns也見http://stackoverflow.com/questions/18925241/send-additional-variable-during-pyqt-pushbutton-click – tacaswell