pyqt5 - PYTHON: Serial read freeze the GUI -
i'm implementing gui pyqt5 , pycharm ide 1 of systems communicates through serial interface. when send appropriate command, system starts data stream packets defined following:
| 0x01 | 0x00 | 0x00 | 0x02 | [...32 bytes...] | 0x03 |
the first, fourth, , last byte markers, second , third control bytes, , remaining 32 bytes information.
when start stream, system receives command gui freezes. started debug watching variable store incoming values.
the simplified code is
def main(): app = qtgui.qapplication(sys.argv) main = mainwindow() main.show() # app.connect(notifier, signal('activated(int)'), update) timer = qtcore.qtimer() timer.timeout.connect(main.update) timer.start(2) app.exec_() def update(self): if self.read == true: self.datain = self.serport.take() # if self.datain == none: # pass # else: self.datalist = list(self.datain) self.disp_chan_1.settext('%f' % (self.datalist[0] * 0.000535434481)) self.disp_chan_2.settext('%f' % (self.datalist[1] * 0.000535694653)) self.disp_chan_3.settext('%f' % (self.datalist[2] * 0.000537407175)) self.disp_chan_4.settext('%f' % (self.datalist[3] * 0.000534853598)) self.disp_chan_5.settext('%f' % (self.datalist[4] * 0.000536425262)) self.disp_chan_6.settext('%f' % (self.datalist[5] * 0.000536408834)) self.disp_chan_7.settext('%f' % (self.datalist[6] * 0.000536337893)) self.disp_chan_8.settext('%f' % (self.datalist[7] * 0.000536237792)) else: pass def take(self): rxtemp1 = self.ser.read(4) rxdata = self.ser.read(32) rxtemp2 = self.ser.read(1) value = struct.unpack('f'*4, rxdata) return value and output of debugger these variables is
rxdata = {bytes}b'\xf2\xa4\xe7=\xc0y\xc4=\xdc\x15\xdc=\xae\xf2\xed=\x9ai;>\xff\xc3\xfe=\xab\x0e\x13>\xebd:a' rxtemp1 = {bytes}b'\x01\x00\x00\x02' rxtemp2 = {bytes}b'\x03' it shows rxtemp1 , rxtemp2 variables correct (they collect markers , control bytes) , rxdata variable collects information seems correct.
but gui freezes , have kill process.
what causing error?
i found solution. application freeze because line
value = struct.unpack('f'*4, rxdata) in rxdata there 32 bytes unpack command above wants 4 group of 4 bytes, 16 in all. correct command is
value = struct.unpack('f'*8, rxdata) i haven't see the output message error because pycharm set wrong.
Comments
Post a Comment