From 29cf16b36a104c771a1ea205c5dffac3cb42c829 Mon Sep 17 00:00:00 2001 From: Christian Aurich Date: Sun, 14 Apr 2013 21:00:03 +0200 Subject: [PATCH 1/2] quickhack: improved stability, had lockups befor this change - now the python module sends out a command that causes the loop to start again - including sending a new request --- arduino/arduino.py | 1 + prototype.pde | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/arduino/arduino.py b/arduino/arduino.py index ae8ec42..58f3890 100644 --- a/arduino/arduino.py +++ b/arduino/arduino.py @@ -8,6 +8,7 @@ class Arduino(object): def __init__(self, port, baudrate=115200): self.serial = serial.Serial(port, baudrate) + self.serial.write('99') def __str__(self): return "Arduino is on port %s at %d baudrate" %(self.serial.port, self.serial.baudrate) diff --git a/prototype.pde b/prototype.pde index db5d14a..37127aa 100644 --- a/prototype.pde +++ b/prototype.pde @@ -34,6 +34,10 @@ void loop() { case 4 : //read analog value Serial.println(analogRead(readData())); + case 99: + //just dummy to cancel the current read, needed to prevent lock when the PC side + //dropped the "w" that we sent + break; } } From 65aab36b043c58e9a9b2e21f7e5af23f6c346d37 Mon Sep 17 00:00:00 2001 From: Christian Aurich Date: Mon, 15 Apr 2013 00:26:17 +0200 Subject: [PATCH 2/2] - added break before the '99' case, just to be sure nothing goes wrong when the code is extended in the future - made comment lines shorter than 80 chars --- prototype.pde | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/prototype.pde b/prototype.pde index 37127aa..524d5ae 100644 --- a/prototype.pde +++ b/prototype.pde @@ -33,10 +33,10 @@ void loop() { analogWrite(readData(), readData()); break; case 4 : //read analog value - Serial.println(analogRead(readData())); + Serial.println(analogRead(readData())); break; case 99: - //just dummy to cancel the current read, needed to prevent lock when the PC side - //dropped the "w" that we sent + //just dummy to cancel the current read, needed to prevent lock + //when the PC side dropped the "w" that we sent break; } } @@ -48,4 +48,4 @@ char readData() { return Serial.parseInt(); } } -} +}