class FunctionGenerator(ScannableMotionBase):
    
    def __init__(self, name):
        self.setName(name)
        num = int(name[-1])
        #EPICS PVs
        func="BL11I-EA-FGEN-0%d:FUNC" % num
        output="BL11I-EA-FGEN-0%d:OUT" % num
        freq="BL11I-EA-FGEN-0%d:FREQ" % num
        freqrbv="BL11I-EA-FGEN-0%d:FREQ:RBV" % num
        amp="BL11I-EA-FGEN-0%d:AMP" % num
        amprbv="BL11I-EA-FGEN-0%d:AMP:RBV" % num
        offset="BL11I-EA-FGEN-0%d:OFF" % num
        offsetrbv="BL11I-EA-FGEN-0%d:OFF:RBV" % num
        sym="BL11I-EA-FGEN-0%d:SYMM" % num
        symrbv="BL11I-EA-FGEN-0%d:SYMM:RBV" % num
        
        dutycyc="BL11I-EA-FGEN-0%d:DCYC" % num
        dutycycrbv="BL11I-EA-FGEN-0%d:DCYC:RBV" % num
        trigger="BL11I-EA-FGEN-0%d:TRIGSRC" % num
        burstmode="BL11I-EA-FGEN-0%d:BURSTMODE" % num
        burstncyc="BL11I-EA-FGEN-0%d:BURSTNCYC" % num
        burstncycrbv="BL11I-EA-FGEN-0%d:BURSTNCYC:RBV" % num
        burststate="BL11I-EA-FGEN-0%d:BURST" % num
        disable="BL11I-EA-FGEN-0%d:DISABLE" % num        
        
        self.setInputNames(["frequency","amplitude","shift","symmetry"])
        self.setExtraNames([])
        self.function=CAClient(func)
        self.output=CAClient(output)
        self.frequency=CAClient(freq)
        self.frequencyrbv=CAClient(freqrbv)
        self.amplitude=CAClient(amp)
        self.amplituderbv=CAClient(amprbv)
        self.shiftcli=CAClient(offset)
        self.shiftrbv=CAClient(offsetrbv)
        self.symmetry=CAClient(sym)
        self.symmetryrbv=CAClient(symrbv)
        self.dutycycle=CAClient(dutycyc)
        self.dutycyclerbv=CAClient(dutycycrbv)
        self.triggersrc=CAClient(trigger)
        self.burstmode=CAClient(burstmode)
        self.burstncyc=CAClient(burstncyc)
        self.burstncycrbv=CAClient(burstncycrbv)
        self.burststate=CAClient(burststate)
        self.disable=CAClient(disable)
        
    # function generator controls
    def setFunction(self, function):
        try:
            if not self.function.isConfigured():
                self.function.configure()
            self.function.caputWait(function)
        except FactoryException, e:
            print "create channel error (%s): %s" % (self.function.getChannel().getName(),e)
        except CAException, e:
            print "caput Error (%s): %s" % (self.function.getChannel().getName(),e)
示例#2
0
class AutoGainAmplifier(ScannableMotionBase):
    '''
    classdocs
    '''
    def __init__(self,
                 name,
                 rootPvName,
                 lowerthreshold,
                 upperthreshold,
                 formatstring,
                 gainMap=gainmap):
        '''
        Constructor
        '''
        self.setName(name)
        self.setInputNames([name])
        self.setExtraNames(["Actual_Value"])
        self.setOutputFormat([formatstring, formatstring])
        self.setLevel(5)
        self.current = CAClient(rootPvName + ":I")
        self.gain = CAClient(rootPvName + ":GAIN")
        self.lowerthreshold = lowerthreshold
        self.upperthreshold = upperthreshold
        self.gainMap = gainMap
        self.gainAtScanStart = 1

    def atScanStart(self):
        if not self.current.isConfigured():
            self.current.configure()
        if not self.gain.isConfigured():
            self.gain.configure()
        self.gainAtScanStart = int(self.gain.caget())

    def atPointStart(self):
        currentGain = int(self.gain.caget())
        currentValue = float(self.current.caget())
        while currentValue < self.lowerthreshold and currentGain < len(
                self.gainMap) - 1:
            #up gain
            self.gain.caputWait(currentValue + 1)
            currentGain = int(self.gain.caget())
            sleep(0.1)
            currentValue = float(self.current.caget())
        while currentValue > self.upperthreshold and currentGain != 0:
            #down gain
            self.gain.caputWait(currentValue - 1)
            currentGain = int(self.gain.caget())
            sleep(0.1)
            currentValue = float(self.current.caget())

    def rawGetPosition(self):
        if not self.gain.isConfigured():
            self.gain.configure()
        if not self.current.isConfigured():
            self.current.configure()
        currentGain = int(self.gain.caget())
        currentValue = float(self.current.caget())
        return [currentValue, currentValue / float(gainmap[currentGain])]

    def rawAsynchronousMoveTo(self, new_position):
        pass

    def isBusy(self):
        return False

    def atPointEnd(self):
        pass

    def atScanEnd(self):
        self.gain.caput(self.gainAtScanStart)

    def stop(self):
        pass

    def toFormattedString(self):
        return self.name + " : " + self.getInputNames()[0] + " : " + str(
            self.getPosition()[0]) + ", " + self.getExtraNames(
            )[0] + " : " + str(self.getPosition()[1])