I'm writing simple application using PyQT5 to read data from serial port, but readyRead
is not emitted when data is received from serial port.
If application is blocked by waitForReadyRead()
dataReady()
is called when data is received.
Using Windows 10 with Python 3.7.4, PyQt5 5.13.1
Minimal code to reproduce problem:
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.setGeometry(50,50,500,300)
self.setWindowTitle("Example")
# Start mainLayout
self.mainLayout = QVBoxLayout()
serialLabel = QLabel("Example program")
self.mainLayout.addWidget(serialLabel)
widget = QWidget()
widget.setLayout(self.mainLayout)
self.setCentralWidget(widget)
self.serPort = QSerialPort()
self.serPort.readyRead.connect(self.dataReady)
self.serPort.setPortName("COM4")
self.serPort.setBaudRate(9600)
self.serPort.open(QIODevice.ReadWrite)
self.serPort.writeData("Hi".encode())
# self.serPort.waitForReadyRead()
def dataReady(self):
print(bytes(self.serPort.readAll()))
if __name__ == '__main__':
app = QApplication([])
gui = ExampleGUI()
gui.show()
app.exec_()
Appears it is bug within Qt https://bugreports.qt.io/browse/QTBUG-78086. Using older version 5.13.0 solves the problem.