为什么第一个PYQT信号发出而后续信号没有?

时间:2016-02-10 18:38:30

标签: python arduino pyqt qthread

以下代码位于从Arduino Uno板获取数据的线程中。我向其他线程发送信号时遇到问题。第一个信号发射良好并完成它应该做的事情,但后续信号不发射。我尝试重新排列信号的顺序,以便ai2或io0首先发出并且它是相同的。我放在顶部并先跑的信号会被发出而另外两个则没有。有谁知道为什么?

class DaqThread(QtCore.QThread):
     def __init__(self,parent=None):
        super(DaqThread,self).__init__(parent)
        self.exiting = False
    #define QtCore.Signal variables to emit
     ai0 =    QtCore.Signal(str)
     ai2 =    QtCore.Signal(str)
     io0 =    QtCore.Signal(str)
     #io1 =    QtCore.Signal(str)
     #io2 =    QtCore.Signal(str)
     #io3 =    QtCore.Signal(str)
     #io4 =    QtCore.Signal(str)     
     ser = serial.Serial(usbport, 115200) #setup serial


     #get Arduino state

     def arduino(self):       
        lines = self.ser.readline()

        if 'A0' in lines[0:2]:     # -Repeat for other variables   
            stlen = len(lines)      #get string length
            ach0 = (lines[3:(stlen)]) 
            f0 = float(ach0)
            ach0 = f0 / 206.4 #change to volts
            ach0 = str(ach0)

        if 'A2' in lines[0:2]:     # -Repeat for other variables   
            stlen = len(lines)      #get string length
            ach2 = (lines[3:(stlen)]) 
            f2 = float(ach2)
            ach2 = f2 / 206.4 #change to volts            


        if 'D2:' in lines[0:3]:     # -Repeat for other variables   
            stlen = len(lines)      #get string length
            io0 = (lines[3:(stlen)]) 
            io0 = str(io0)


        self.ai0.emit(ach0)
        self.ai2.emit(ach2)
        self.io0.emit(io0)
        self.ser.flush()


     def run(self):
         while 1:
             try:
                 self.arduino()
             except:
                 pass
             time.sleep(0.005)

0 个答案:

没有答案