]> Pileus Git - ~andy/csm213a-hw/blobdiff - vis/device.py
Switch to Python 3 and Gtk 3
[~andy/csm213a-hw] / vis / device.py
index b729f02fc80ecddca1705cd3cecaa8ba3cf8a770..385a142f1e9d14c4cd3fcf8385b16a9a25af8b27 100644 (file)
@@ -46,12 +46,14 @@ class Device:
 
        def process(self):
                items = []
+               count = 0
+               limit = 100
                while self.serial.readable():
                        try:
-                               char = self.serial.read()
+                               char = self.serial.read().decode()
                        except Exception as ex:
                                char = ''
-                       if char == '':
+                       if len(char) == 0:
                                break
                        if char == '\r' or char == '\n':
                                if len(self.inbuf) == 0:
@@ -62,6 +64,10 @@ class Device:
                                self.inbuf = []
                        else:
                                self.inbuf.append(char)
+                       if count > limit:
+                               print("Eror: exceeded read limit")
+                               break
+                       count += 1
                return items
 
        # Private methods