Question

Quelqu'un pourrait-il me donner un exemple sur la façon de QSocketNotifier d'installation pour déclencher un événement si quelque chose arrive sur / dev / ttyS0 ? (De préférence en python / pyqt4)

Était-ce utile?

La solution

Voici un exemple qui ne cesse de lire à partir d'un fichier en utilisant QSocketNotifier. Remplacez simplement que « foo.txt » avec « / dev / ttyS0 » et vous devriez être bon d'aller.


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_()

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top