From 2df8221eafbc93f64b68c9f97b4795c0a7b688a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Wed, 26 Mar 2014 14:34:05 +0100 Subject: [PATCH] improved serial init for sensors --- config_files/tmux-sensor-testing.conf | 9 +++++---- sensors2osc/sensors2osc/common.py | 12 +++++------- sensors2osc/sensors2osc/ehealth2osc.py | 2 +- sensors2osc/sensors2osc/pulse2osc.py | 2 +- sensors2osc/sensors2osc/socat_ehealth_test.py | 11 +++++++---- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/config_files/tmux-sensor-testing.conf b/config_files/tmux-sensor-testing.conf index 24efb0a..a587b05 100644 --- a/config_files/tmux-sensor-testing.conf +++ b/config_files/tmux-sensor-testing.conf @@ -37,9 +37,9 @@ new-window -n 'pulse2osc-bjoern' -t 'csession:14' 'pulse2osc -4 -d /tmp/puls new-window -n 'pulse2osc-merle' -t 'csession:15' 'pulse2osc -4 -d /tmp/pulse2osc-merle-out -a merle' new-window -n 'pulse2osc-uwe' -t 'csession:16' 'pulse2osc -4 -d /tmp/pulse2osc-uwe-out -a uwe' -new-window -n 'ehealth2osc-bjoern' -t 'csession:17' 'ehealth2osc -4 -d /tmp/ehealth2osc-bjoern-out -a bjoern' -new-window -n 'ehealth2osc-merle' -t 'csession:18' 'ehealth2osc -4 -d /tmp/ehealth2osc-merle-out -a merle' -new-window -n 'ehealth2osc-uwe' -t 'csession:19' 'ehealth2osc -4 -d /tmp/ehealth2osc-uwe-out -a uwe' +new-window -n 'ehealth2osc-bjoern' -t 'csession:17' 'sleep 1 && ehealth2osc -4 -d /tmp/ehealth2osc-bjoern-out -a bjoern' +new-window -n 'ehealth2osc-merle' -t 'csession:18' 'sleep 1 && ehealth2osc -4 -d /tmp/ehealth2osc-merle-out -a merle' +new-window -n 'ehealth2osc-uwe' -t 'csession:19' 'sleep 1 && ehealth2osc -4 -d /tmp/ehealth2osc-uwe-out -a uwe' new-window -n 'test-ekg-bjoern' -t 'csession:20' 'python /home/stefan/dev/psychose/sensors2osc/sensors2osc/socat_ekg_test.py /tmp/ekg2osc-bjoern-in' new-window -n 'test-ekg-merle' -t 'csession:21' 'python /home/stefan/dev/psychose/sensors2osc/sensors2osc/socat_ekg_test.py /tmp/ekg2osc-merle-in' @@ -52,9 +52,10 @@ new-window -n 'test-pulse-uwe' -t 'csession:25' 'python /home/stefan/dev/ps new-window -n 'test-ehealth-bjoern' -t 'csession:26' 'python /home/stefan/dev/psychose/sensors2osc/sensors2osc/socat_ehealth_test.py /tmp/ehealth2osc-bjoern-in' new-window -n 'test-ehealth-merle' -t 'csession:27' 'python /home/stefan/dev/psychose/sensors2osc/sensors2osc/socat_ehealth_test.py /tmp/ehealth2osc-merle-in' new-window -n 'test-ehealth-uwe' -t 'csession:28' 'python /home/stefan/dev/psychose/sensors2osc/sensors2osc/socat_ehealth_test.py /tmp/ehealth2osc-uwe-in' + # new-window -n 'ekgplotter' -t 'csession:29' 'sleep 5 && ekgplotter -s' # new-window -n 'vlc' -t 'csession:30' 'sleep 10 && vlc "http://localhost:9000/camera.mjpeg"' -new-window -n 'chaosc_emitter' -t 'csession:31' 'chaosc_emitter' +#new-window -n 'chaosc_emitter' -t 'csession:31' 'chaosc_emitter' select-window -t 'csession:1' diff --git a/sensors2osc/sensors2osc/common.py b/sensors2osc/sensors2osc/common.py index d34f4a3..004b911 100644 --- a/sensors2osc/sensors2osc/common.py +++ b/sensors2osc/sensors2osc/common.py @@ -45,17 +45,15 @@ class Platform(object): def connect(self): print "connect serial" - self.serial_sock = serial.Serial() - self.serial_sock.port = self.args.device - self.serial_sock.baudrate = 115200 - self.serial_sock.timeout = 0 print "waiting for the device %r to come up" % self.args.device while 1: try: - self.serial_sock.open() - break - except serial.serialtuil.SerialException: + self.serial_sock = serial.Serial(self.args.device, 115200, timeout=1) + except serial.serialutil.SerialException, e: + print "serial error", e pass + else: + break def close(self): diff --git a/sensors2osc/sensors2osc/ehealth2osc.py b/sensors2osc/sensors2osc/ehealth2osc.py index a336aee..087ebfe 100644 --- a/sensors2osc/sensors2osc/ehealth2osc.py +++ b/sensors2osc/sensors2osc/ehealth2osc.py @@ -42,7 +42,7 @@ def main(): print "serial socket error!!!", msg platform.reconnect() - #print "got data", repr(data) + print "got data", repr(data) try: airFlow, emg, temp = data.split(";") except ValueError, e: diff --git a/sensors2osc/sensors2osc/pulse2osc.py b/sensors2osc/sensors2osc/pulse2osc.py index b86ea5b..707014c 100644 --- a/sensors2osc/sensors2osc/pulse2osc.py +++ b/sensors2osc/sensors2osc/pulse2osc.py @@ -20,7 +20,7 @@ from __future__ import absolute_import -import time +import time, select from datetime import datetime from sensors2osc.common import * diff --git a/sensors2osc/sensors2osc/socat_ehealth_test.py b/sensors2osc/sensors2osc/socat_ehealth_test.py index 15d5b90..fb696a4 100644 --- a/sensors2osc/sensors2osc/socat_ehealth_test.py +++ b/sensors2osc/sensors2osc/socat_ehealth_test.py @@ -21,15 +21,18 @@ # used this line before opening that script # socat -d -d PTY,raw,echo=0,link=/tmp/pty1,b115200,user=stefan PTY,raw,echo=0,link=/tmp/pty2,b115200,user=stefan -import serial, sys, time, random, struct +import serial, time, random, sys serial_sock = serial.Serial() serial_sock.port = sys.argv[1] serial_sock.baudrate = 115200 -serial_sock.timeout = 0 +serial_sock.timeout = 1 +serial_sock.writeTimeout = 1 serial_sock.open() while 1: - serial_sock.write("%d;%d;%d\r\n" % (random.randint(0,1023), random.randint(0,1023), random.randint(0,1023))) - time.sleep(0.05) + a = (random.randint(0,1023), random.randint(0,1023), random.randint(0,1023)) + print "data", a + serial_sock.write("%d;%d;%d\r\n" % a) + time.sleep(0.1)