Permalink
Browse files

Add a test mode so that I don't keep uncommenting the serial part whe…

…n testing at home.
  • Loading branch information...
1 parent d129fe0 commit 2021d6a6f105edaf86c687e5356ec50675978ffb @ibrahima committed Apr 16, 2012
Showing with 16 additions and 4 deletions.
  1. +16 −4 matplotlib_plotter.py
View
@@ -26,6 +26,7 @@
import wx
import serial
from datetime import datetime # Yeah, screw you too Python
+import argparse
# The recommended way to use wx with mpl is with the WXAgg
# backend.
@@ -372,7 +373,7 @@ def append_random(self):
class SerialPlotter(object):
def __init__(self, frame, port=6, baud=38400):
self.frame = frame
- #self.ser = serial.Serial(port, baud, timeout=1)
+ self.ser = serial.Serial(port, baud, timeout=1)
TIMER_ID = 123
self.timer = wx.Timer(frame, TIMER_ID)
self.timer.Start(1)
@@ -397,12 +398,23 @@ def read_line(self):
s = self.ser.readline()
print s
self.parse_line(s)
+
+def parse_args():
+ parser = argparse.ArgumentParser(description='Plot values taken from serial input.')
+ parser.add_argument('-t', '--test', action='store_true')
+ return parser.parse_args()
if __name__ == '__main__':
+ args = parse_args()
+
app = wx.PySimpleApp()
app.frame = GraphFrame()
- #sp = SerialPlotter(app.frame, 6, 38400)
- rp = RandomPlotter(app.frame)
+ if args.test:
+ rp = RandomPlotter(app.frame)
+ else:
+ sp = SerialPlotter(app.frame, 6, 38400)
+
app.frame.Show()
app.MainLoop()
- #sp.close_port()
+ if not args.test:
+ sp.close_port()

0 comments on commit 2021d6a

Please sign in to comment.