[PyQt] QSerialPort() basic read question

Phil phil_lor at bigpond.com
Sun Nov 19 09:25:05 GMT 2017


Thank you for reading this.

I'm trying to read serial data, but so far without any success. The only 
thing printed is a blank line or "data = ".

I have, however, been able to write data successfully so the port set up 
is correct.

This is how I've set up the port for both reading and writing:

    self.serial = QSerialPort()
         self.serial.setPortName('/dev/ttyACM0')
         self.serial.open(QIODevice.ReadWrite)
         self.serial.setBaudRate(9600)
         self.serial.setDataBits(8)
         self.serial.setParity(QSerialPort.NoParity)
         self.serial.setStopBits(1)
         self.serial.setFlowControl(QSerialPort.NoFlowControl)

         self.serialRead()

The following is most of what I've tried so far and includes bits that 
I've converted from C++ examples:

     def serialRead(self):
         print("DEBUG: serial received data: ", 
(bytes(self.serial.readAll()).decode('ascii')))

         data = self.serial.readAll();
         print("data = ")

         if self.serial.canReadLine():
             print("DEBUG: processing received serial data")
             self.serialProcess(self.serial.readLine())


I've also tried the following:

while (self.serial.waitForReadyRead(5000)):
     data = self.serial.readAll()
     print(:data = ")

This blocks the main window from displaying, so I might be on the wrong 
track here.

Finally, cat /dev/ttyACM0 show that the data is being received.

Any help at all will be greatly appreciated.

-- 
Regards,
Phil


More information about the PyQt mailing list