如何解决从Spyder4运行时,PyQt5 QtSerialPort多个端口读取正确,但在Pyinstaller打包后无法正常工作
使用Qt串行GUI读取多个串行条形码扫描仪时,冻结了Q Line Edit 使用Spider可以正常运行,但是在python安装程序打包转换后运行时 扫描3或4个条形码后GUI冻结 请帮助清除此问题 下面给出的最小代码样本,实际上我使用4个串行端口进行读取
如何在不冻结GUI的情况下扫描条形码扫描器
from PyQt5.QtWidgets import QApplication,QVBoxLayout,QWidget
from PyQt5.QtWidgets import QMainWindow,QLabel
from PyQt5.QtCore import Qt,QIODevice
from PyQt5.QtSerialPort import QSerialPort
import sys
class ExampleGUI(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Example")
# Start mainLayout
self.mainLayout = QVBoxLayout()
serialLabel1 = QLineEdit("barcode_1")
self.mainLayout.addWidget(serialLabel1)
serialLabel2 = QLineEdit("barcode_2")
self.mainLayout.addWidget(serialLabel2)
widget = QWidget()
widget.setLayout(self.mainLayout)
self.setCentralWidget(widget)
self.ser1 = QtSerialPort.QSerialPort("COM1",baudRate=QtSerialPort.QSerialPort.Baud9600)
self.ser2 = QtSerialPort.QSerialPort("COM2",baudRate=QtSerialPort.QSerialPort.Baud9600)
self.ser1.open(QIODevice.ReadWrite)
self.ser2.open(QIODevice.ReadWrite)
self.ser1.readyRead.connect(self.bar_read1)
self.ser2.readyRead.connect(self.bar_read2)
def bar_read1(self):
self.ser1.waitForReadyRead(50)
barcode1 = self.ser1.readLine(14)
if len(barcode1)==5 :
barcode = (str(barcode1)[6:9])
self.barcode_1.setText(barcode)
def bar_read2(self):
self.ser2.waitForReadyRead(50)
barcode2 = self.ser2.readLine(14)
if len(barcode2)==5 :
barcode = (str(barcode2)[6:9])
self.barcode_2.setText(barcode)
if __name__ == '__main__':
app = QApplication([])
gui = ExampleGUI()
gui.show()
app.exec_()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。