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

import glob
import os
import time
import random

class GPIBplotter:#(GPIB):
    """
    A mockup thet will find in a directory some HPGL files and feed them randomly
    """
    def __init__(self, device="/dev/ttyUSB0", baudrate=115200, timeout=0.1,
                 address=5):
        self._timeout = timeout
        self.filenames = glob.glob('examples/*.plt')
        self._next = random.randint(10,50)
        self._num = 0

    def plotStarted(self):
        pass
        
    def load_plot(self, wait_timeout=0):
        if wait_timeout:
            time.sleep(wait_timeout)
        self._num += 1
        if self._num > self._next:
            ret = open(random.choice(self.filenames)).read()
            if len(ret)>0:
                self.plotStarted()
                self._num = 0
                self._next = random.randint(10,100)
                time.sleep(random.randint(1,3))
                return ret
            return None
        return None
    
        

mercurial