]> jspc29.x-matter.uni-frankfurt.de Git - labtools.git/commitdiff
pt100: feed.py the log file
authorMaps <maps@ikf>
Tue, 8 Sep 2015 15:07:15 +0000 (17:07 +0200)
committerMaps <maps@ikf>
Tue, 8 Sep 2015 15:07:15 +0000 (17:07 +0200)
sensors/data/feed.py [new file with mode: 0755]

diff --git a/sensors/data/feed.py b/sensors/data/feed.py
new file mode 100755 (executable)
index 0000000..6162c9b
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+
+import argparse
+import sys
+import time
+
+import serial
+
+parser = argparse.ArgumentParser()
+parser.add_argument('--timestamps', action='store_true', help='Add timestamps to the output')
+parser.add_argument('device', help='The serial port to open')
+args = parser.parse_args()
+
+
+ser = serial.Serial(args.device, baudrate=38400, timeout=0.1)
+
+output = sys.stdout
+
+last_time = int(time.time()) - 1
+
+try:
+    while True:
+        now = int(time.time())
+        if args.timestamps and now != last_time:
+            output.write(b'#{}\n'.format(now))
+            last_time = now
+        line = ser.readline()
+        if not line: continue
+        line = line.strip()
+        output.write(line + b'\n')
+        output.flush()
+except KeyboardInterrupt:
+    sys.stderr.write(b'Ctrl-C pressed, exiting...\n')
+    sys.exit(1)
+