PDA

View Full Version : PyQt5 QSerialPort QSocketNotifier: Invalid socket specified



Blitzor DDD
16th August 2017, 10:54
I had a code on PyQt4 and I was working with pyserial, like this:


import serial
global ser

def setting_COMPort():
global ser
ser = serial.Serial(
port='/dev/ttyAMA0',
baudrate = 115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1)
and when I wanted to send something to serial port I did just:


ser.write(":010600000044b5\r\n")
Easy, simple and worked stable and perfect. But I needed some function which were unavaliable in serial, so I changed to PyQt5 and QSerialPort. Now my code have this Gestalt:


from PyQt5.QtSerialPort import QSerialPort
from PyQt5 import QtCore

def setting_COMPort(ser): # ser is an object of QSerialPort
ser.setBaudRate(QSerialPort.Baud115200)
ser.setParity(QSerialPort.NoParity)
ser.setOpenMode(QSerialPort.ReadWrite)
ser.setStopBits(QSerialPort.OneStop)
ser.setDataBits(QSerialPort.Data8)
but sending data to serial seems not to be so easy on this way. So now with the power of PyQt5 I am doing it like this in function:


# ser is the same object of QSerialPort
s=":010600000044b5\r\n"
data_to_send=QtCore.QByteAray(s)
ser.write(data_to_send)
But I am getting the error QSocketNotifier: Invalid socket specified

There are some tries to find a solution on the web, but nothing real.

So what am I doing incorrect, why this way to send a string through QSerialPort does not work?