diff --git a/raspberry/roberto/Serial.py b/raspberry/roberto/Serial.py index 5cab0d3..04baecd 100644 --- a/raspberry/roberto/Serial.py +++ b/raspberry/roberto/Serial.py @@ -45,24 +45,29 @@ class Serial(object): def reader(self): try: while self.alive and self.serialport: - data = self.serialport.read(self.serialport.in_waiting or 1) + #data = self.serialport.read(self.serialport.in_waiting or 1) + data = self.serialport.readline() if data: print(data) + if isinstance(data, bytes): + data = data.decode(encoding='utf8') command = data[0] argument = data[2:].strip() if command and command in self._callbacks: cb = self._callbacks[command] if cb: cb(argument) + else: + print("no callback found for command '%s'" % command) except serial.SerialException: pass #self.alive = False #raise - def add_callback(cmd, callback): + def add_callback(self, cmd, callback): self._callbacks[cmd] = callback - def del_callback(cmd, callback): + def del_callback(self, cmd, callback): if cmd in self._callbacks: del self._callbacks[cmd]