I would like to check connection vie COM-Port permanently, I have found here how to check connection, but when I implement it to my application in order to check if device is connected I do not achieve wanted result, perhaps because I am checking it using QTimer every second, but maybe it goes okay only first time during powering on..
Hope with code it will be easier to understand.
So, I open port:
import serial
global ser
from PyQt5.QtCore import QTimer
timer = QTimer()
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)
timer.timeout.connect(self.statusComPort)
in "main" function there is QTimer
global timer
timer.start(1000)
and in slot statusComPort I want to check every second via QTimer if device is connected.
def statusComPort(self):
global ser
colorr=self.palette()
if(ser.isOpen()):
self.lineEdit_6.setText(str("Port is open!"))
print("Port is Open")
colorr.setColor(self.backgroundRole(), QtGui.QColor(155,155,155))
self.setPalette(colorr)
else:
self.lineEdit_6.setText(str("Error! Port is close!"))
colorr.setColor(self.backgroundRole(), QtGui.QColor(155,0,5))
self.setPalette(colorr)
print("Port is close")
In case if connection is lost I change color of my window. The problem is that applied solution which was suggested in link does not work in this case.
So what should I change in my slot to achieve result..?
Maybe use different function, not isOpen() ?
OS - Raspbian
UPDATE 1
link to project, everything is cut, except for needed functionality https://github.com/ivanwolodin/statusofcomport
Summing up. I have Qtimer which acts every second, therefore my app every second goes into slot "statusComPort", where I want to check if device is connected via serial port. So I want to check status of my serial port permanently (every second) and question is: how should I write this slot to achieve correct check