I want to do an app constantly watching the serial port and changing the user interface according to the input received from the port. I've managed to read lines from the port with pyserial under Linux, but I'm not sure how to do this in a regular fashion: create a separate thread and check for input on a timer event? How do i make sure I don't miss anything? (implementing some kind of handshake/protocol seems like an overkill for this...) And most importantly: How do I do it with the facilities of qt4?
Edit: This is what I'm doing now (I want to do this periodically with the rest of the app running and not waiting)
class MessageBox(QtGui.QWidget): def init(self, parent=None): QtGui.QWidget.init(self, parent)
ser = serial.Serial('/dev/ttyS0', 9600, bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
timeout=None,
xonxoff=0,
rtscts=0,
interCharTimeout=None)
self.label = QtGui.QLabel(ser.readline(), self)
self.label.move(15, 10)
ser.close()
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Authentication')
self.color = QtGui.QColor(0, 0, 0)
self.square = QtGui.QWidget(self)
self.square.setGeometry(120, 20, 100, 100)
self.square.setStyleSheet("QWidget { background-color: %s }" % self.color.name())