Exemple #1
0
    def measure(self, time_ms):
        report("Counters.measure(%s)" % repr(time_ms))

        # Stop counters if running.
        self.stop()

        # Specify time to count.
        self.setTime(time_ms)

        # Sample real time.
        t1 = time()

        # Start timer and counters.
        self.start()

        # Wait until time has elapsed.
        while self.isBusy():
            sleep(0.1)

        # Sample real time.
        t2 = time()

        # Calculate and report real time elapsed.
        taken_ms = int((t2 - t1) * 1000)
        report("Counters.measure(%s) took %d ms" % (repr(time_ms), taken_ms))

        # Read out counter values.
        counts = self.getCounts()

        # Stop counters.
        self.stop()
        self.setTime(0)
        return counts
Exemple #2
0
    def __init__(self, link, aSwitch, aBusy, aTime, aValues):
        report(
            "Counters(aSwitch=%s, aBusy=%s, aTime=%s, aValues=%s)"
            % (repr(aSwitch), repr(aBusy), repr(aTime), repr(aValues))
        )

        self.rSwitch = ToggleRegister(link, aSwitch)
        self.rBusy = ToggleRegister(link, aBusy)
        self.rTime = FloatRegister(link, aTime)
        self.rValues = [DwordRegister(link, aValue) for aValue in aValues]
Exemple #3
0
 def write(self, value):
     nvalue = long(value)
     for offset in self.offsets:
         part = nvalue & self.mask
         nvalue >>= self.eachWidth
         self.link.write(offset, part)
     assert nvalue == 0
     nvalue = self.read()
     if nvalue != value:
         report('addresses [%s], wrote %ld, returned %ld'
                % (', '.join(map(str, self.offsets)), value, nvalue))
     return nvalue
Exemple #4
0
 def write(self, value):
     # Pack into bytes as 1 x 32 bit integer
     data = struct.pack('>I', value)
     # Unpack from bytes as 2 x 16 bit unsigned integers
     lo, hi = struct.unpack('>HH', data)
     # Write individual 16 bit unsigned integers
     self.link.write(self.offset + 0, lo)
     self.link.write(self.offset + 1, hi)
     # Verify written value
     nvalue = self.read()
     if nvalue != value:
         report('address %ld dword, wrote %ld, returned %ld'
                % (self.offset, value, nvalue))
     return nvalue
Exemple #5
0
    def read(self):
        value = 0L
        shift = 0L
        for offset in self.offsets:
            part = self.link.read(offset)

            if (part & self.mask) != part:
                report('address %ld has value %ld too large for %ld bits'
                       % (offset, part, self.eachWidth))

            part <<= shift
            shift += self.eachWidth
            value |= part
        return value
Exemple #6
0
    def write(self, offset, value):
        # Adjust offset due to weirdness.
        offset -= 40000

        # Create request.
        assert offset is not None
        assert offset >= 0
        assert value is not None
        req = WriteSingleRegisterRequest(offset, value)

        # Execute and return response.
        res = self.conn.execute(req)
        assert res is not None
        assert res.value is not None
        nvalue = res.value
        if nvalue != value:
            report('address %d, wrote %d, returned %d'
                   % (offset, value, nvalue))
        return nvalue
Exemple #7
0
 def set(self, value):
     report("Analog.set(%s)" % repr(value))
     self.rValue.write(float(value))
Exemple #8
0
 def __init__(self, link, aValue):
     report("Analog(aValue=%s)" % repr(aValue))
     self.rValue = FloatRegister(link, aValue)
Exemple #9
0
 def disable(self):
     report("Relay.disable()")
     self.rSwitch.write(False)
Exemple #10
0
 def enable(self):
     report("Relay.enable()")
     self.rSwitch.write(True)
Exemple #11
0
 def __init__(self, link, aSwitch):
     report("Relay(aSwitch=%s)" % repr(aSwitch))
     self.rSwitch = ToggleRegister(link, aSwitch)
Exemple #12
0
 def getCounts(self):
     counts = [rValue.read() for rValue in self.rValues]
     report("Counters.getCounts() -> %s" % repr(counts))
     return counts
Exemple #13
0
 def setTime(self, time_ms):
     report("Counters.setTime(%s)" % repr(time_ms))
     self.rTime.write(float(int(time_ms)))
Exemple #14
0
 def isBusy(self):
     done = self.rBusy.read()
     report("Counters.isBusy() -> %s" % repr(done))
     return done
Exemple #15
0
 def start(self):
     report("Counters.start()")
     self.rSwitch.write(True)
Exemple #16
0
 def stop(self):
     report("Counters.stop()")
     self.rSwitch.write(False)