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)
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)
To copy to clipboard, switch view to plain text mode
and when I wanted to send something to serial port I did just:
ser.write(":010600000044b5\r\n")
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:
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)
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)
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:
# ser is the same object of QSerialPort
s=":010600000044b5\r\n"
data_to_send=QtCore.QByteAray(s)
ser.write(data_to_send)
# ser is the same object of QSerialPort
s=":010600000044b5\r\n"
data_to_send=QtCore.QByteAray(s)
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?
Bookmarks