plotter/gpib_plotter_mockup.py

Fri, 25 Jan 2008 21:00:34 +0100

author
David Douard <david.douard@logilab.fr>
date
Fri, 25 Jan 2008 21:00:34 +0100
changeset 32
59da528bc470
parent 27
gpib_plotter_mockup.py@0f8f2621418f
permissions
-rw-r--r--

refactoring: created a 'plotter' subdirectory and put everything related to GPIB/HPGL plotting under it

27
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
1 import glob
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
2 import os
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
3 import time
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
4 import random
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
5
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
6 class GPIBplotter:#(GPIB):
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
7 """
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
8 A mockup thet will find in a directory some HPGL files and feed them randomly
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
9 """
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
10 def __init__(self, device="/dev/ttyUSB0", baudrate=115200, timeout=0.1,
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
11 address=5):
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
12 self._timeout = timeout
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
13 self.filenames = glob.glob('examples/*.plt')
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
14 self._next = random.randint(10,50)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
15 self._num = 0
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
16
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
17 def plotStarted(self):
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
18 pass
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
19
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
20 def load_plot(self, wait_timeout=0):
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
21 if wait_timeout:
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
22 time.sleep(wait_timeout)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
23 self._num += 1
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
24 if self._num > self._next:
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
25 ret = open(random.choice(self.filenames)).read()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
26 if len(ret)>0:
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
27 self.plotStarted()
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
28 self._num = 0
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
29 self._next = random.randint(10,100)
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
30 time.sleep(random.randint(1,3))
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
31 return ret
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
32 return None
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
33 return None
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
34
0f8f2621418f added a gpib plot receiver mockup for testing purpose. Seems to work.
David Douard <david.douard@logilab.fr>
parents:
diff changeset
35

mercurial