瀏覽代碼

fixed serial parsing exception

subDesTagesMitExtraKaese 3 年之前
父節點
當前提交
e1e2f5ad56
共有 1 個文件被更改,包括 3 次插入3 次删除
  1. 3 3
      raspberry-pi/connection.py

+ 3 - 3
raspberry-pi/connection.py

@@ -134,9 +134,9 @@ class ArduinoSlave(SerialConnection):
   def _readSensors(self):
     while True:
       data = super().readline()
-      if data:
-        data = str(data, "ASCII")
-        vals = data.split('\t')
+      if data and len(data) > 2:
+        data = str(data, encoding="ASCII", errors="ignore")
+        vals = data[:-2].split('\t')
         if vals[0] == "DATA:" and len(vals) >= 13:
           self.sensorData = vals[1:]
           for cb in self._recvCbs: