Added python interface to stripchart program (shell out).
authorW. Trevor King <wking@drexel.edu>
Tue, 28 Oct 2008 11:43:38 +0000 (07:43 -0400)
committerW. Trevor King <wking@drexel.edu>
Tue, 28 Oct 2008 11:43:38 +0000 (07:43 -0400)
stripchart.py [new file with mode: 0644]

diff --git a/stripchart.py b/stripchart.py
new file mode 100644 (file)
index 0000000..bf27ca1
--- /dev/null
@@ -0,0 +1,42 @@
+import os
+
+class stripchart :
+    def __init__(self, pipename='strip_pipe', maxY=10, minY=-10,
+                 npoints=100, title='chart', axes=True) :
+        self.pipename = pipename
+        self.maxY = maxY
+        self.minY = minY
+        self.npoints = npoints
+        self.title = title
+        self.axes = axes
+        self.status = 'closed'
+        self.pipe = None
+    def __del__(self) :
+        self.close()
+    def open(self, debug=False) :
+        if self.status == 'closed' :
+            os.mkfifo(self.pipename)
+            cmd = "stripchart -t '%s' -p '%s' -u -M '%g' -m '%g' -n '%d'" % \
+                (self.title, self.pipename, self.maxY, self.minY,
+                 self.npoints)
+            if self.axes == False :
+                cmd += " -a"
+            cmd += " &"
+            if debug :
+                print cmd
+            os.system(cmd)
+            self.pipe = open(self.pipename,'w')
+            self.status = 'open'
+    def close(self) :
+        if self.status == 'open' :
+            print >> self.pipe, "q"
+            self.pipe.close()
+            self.pipe = None
+            self.status = 'closed'
+    def _add_point(self, point) :
+        print >> self.pipe, point
+    def _flush(self) :
+        self.pipe.flush()
+    def add_point(self, point) :
+        self._add_point(point)
+        self._flush()