plotter/gpib_plotter_mockup.py

Mon, 04 Feb 2008 19:19:32 +0100

author
David Douard <david.douard@logilab.fr>
date
Mon, 04 Feb 2008 19:19:32 +0100
changeset 37
e0790756059d
parent 32
59da528bc470
permissions
-rw-r--r--

constant adjustments for string plots

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