浏览代码

1. commit

kay 4 年之前
父节点
当前提交
e70195082e
共有 3 个文件被更改,包括 25 次插入0 次删除
  1. 0 0
      software/ui/read_i²c.py
  2. 25 0
      software/ui/read_serial.py
  3. 0 0
      software/ui/read_spi.py

+ 0 - 0
software/ui/read_i²c.py


+ 25 - 0
software/ui/read_serial.py

@@ -0,0 +1,25 @@
+import serial
+import io
+import time
+
+class my_serial():
+    def __init__(self, port, baud_rate):
+        self.serial = serial.Serial(port, baud_rate, timeout=1)
+        self.serial_io_wrapped = io.TextIOWrapper(io.BufferedRWPair(self.serial, self.serial))
+
+    # receive message via serial
+    def read(self):
+        read_out = None
+        timeout = time.time() + 0.1
+        while ((self.serial.in_waiting > 0) and (timeout > time.time())):
+            pass
+        if self.serial.in_waiting > 0:
+            read_out = self.serial_io_wrapped.readline()
+        return read_out
+
+ser = my_serial('/dev/ttyUSB0', 9600)
+
+while True:
+    incomingMessage = ser.read()
+    if incomingMessage is not None:
+        print(incomingMessage)

+ 0 - 0
software/ui/read_spi.py