Results 1 to 1 of 1

Thread: PyQt5 QSerialPort QSocketNotifier: Invalid socket specified

  1. #1
    Join Date
    Jul 2016
    Qt products
    Unix/X11 Windows

    Default PyQt5 QSerialPort QSocketNotifier: Invalid socket specified

    I had a code on PyQt4 and I was working with pyserial, like this:

    Qt Code:
    1. import serial
    2. global ser
    4. def setting_COMPort():
    5. global ser
    6. ser = serial.Serial(
    7. port='/dev/ttyAMA0',
    8. baudrate = 115200,
    9. parity=serial.PARITY_NONE,
    10. stopbits=serial.STOPBITS_ONE,
    11. bytesize=serial.EIGHTBITS,
    12. timeout=1)
    To copy to clipboard, switch view to plain text mode 
    and when I wanted to send something to serial port I did just:

    Qt Code:
    1. ser.write(":010600000044b5\r\n")
    To copy to clipboard, switch view to plain text mode 
    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:

    Qt Code:
    1. from PyQt5.QtSerialPort import QSerialPort
    2. from PyQt5 import QtCore
    4. def setting_COMPort(ser): # ser is an object of QSerialPort
    5. ser.setBaudRate(QSerialPort.Baud115200)
    6. ser.setParity(QSerialPort.NoParity)
    7. ser.setOpenMode(QSerialPort.ReadWrite)
    8. ser.setStopBits(QSerialPort.OneStop)
    9. ser.setDataBits(QSerialPort.Data8)
    To copy to clipboard, switch view to plain text mode 
    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:

    Qt Code:
    1. # ser is the same object of QSerialPort
    2. s=":010600000044b5\r\n"
    3. data_to_send=QtCore.QByteAray(s)
    4. ser.write(data_to_send)
    To copy to clipboard, switch view to plain text mode 
    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?
    Last edited by Blitzor DDD; 16th August 2017 at 11:23.

Similar Threads

  1. QSocketNotifier: Invalid socket specified
    By Askar in forum Qt Programming
    Replies: 0
    Last Post: 4th August 2011, 08:14
  2. Replies: 2
    Last Post: 22nd May 2011, 21:31
  3. Replies: 9
    Last Post: 13th October 2010, 14:09
  4. QSocketNotifier: Invalid socket 12 and type 'Read', disabling...
    By kunalnandi in forum General Programming
    Replies: 1
    Last Post: 24th September 2008, 18:09
  5. Replies: 10
    Last Post: 20th March 2007, 22:19

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.