¿Cómo puedo ver un puerto serie con QSocketNotifier (Linux)?
-
16-09-2019 - |
Pregunta
Podría alguien darme un ejemplo de como configurar QSocketNotifier para disparar un evento si surge algo en / dev / ttyS0 ? (Preferiblemente en pitón / PyQt4)
Solución
Este es un ejemplo que sólo sigue la lectura de un archivo usando QSocketNotifier. Solamente se cambia eso foo.txt "con '/ dev / ttyS0' y usted debe ser bueno para ir.
import os
from PyQt4.QtCore import QCoreApplication, QSocketNotifier, SIGNAL
def readAllData(fd):
bufferSize = 1024
while True:
data = os.read(fd, bufferSize)
if not data:
break
print 'data read:'
print repr(data)
a = QCoreApplication([])
fd = os.open('foo.txt', os.O_RDONLY)
notifier = QSocketNotifier(fd, QSocketNotifier.Read)
a.connect(notifier, SIGNAL('activated(int)'), readAllData)
a.exec_()
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow