2009-04-25 9 views

Répondre

5

Voici un exemple qui continue de lire depuis un fichier en utilisant QSocketNotifier. Remplacez simplement 'foo.txt' par '/ dev/ttyS0' et vous devriez être prêt à partir.


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

Questions connexes