Ejemplo n.º 1
0
    def __init__(self, ctrl, rbv, rbv_done):
        """
        ctrl : PV that sets the FEL 
        rbv  : PV that changes once the FEL has settled to new energy
        rbv_done: Value that indicates FEL has reached new energy
        """

        # Setup logger
        self.__logger = logging.getLogger(__name__)

        # String for CTRL and RBV PVs
        self.ctrl_pv = ctrl
        self.rbv_pv = rbv

        # Set up ctrl and rbv PVs
        self.__ctrl = Pv(ctrl)
        self.__rbv = Pv(rbv)

        self.rbv_done = rbv_done

        # Connect to Pvs
        self.__connect()

        # Threading event to signal when shutter has changed state
        self.__done = threading.Event()

        # Start monitors to live update shutter status
        # ..as soon as monitor starts, it will update self._open and
        # self._close
        self.__start_monitors()
Ejemplo n.º 2
0
 def connect(self):
     Pv.connect(self, timeout=1.0)
     self.connected = True
     # self.monitor_cb = self.changed
     evtmask = pyca.DBE_VALUE | pyca.DBE_LOG | pyca.DBE_ALARM
     self.monitor(evtmask)
     pyca.flush_io()
Ejemplo n.º 3
0
 def __init__(self, name):
     pycaPv.__init__(self, name)
     self.connect(time_out_connect)
     self.monitor_cb = self.monitor_handler
     self.values = []
     self.ismonitored = False
     self.last_update = "Never"
Ejemplo n.º 4
0
class Follower(object):
    def __init__(self, pvmonitor, pvfollower, follower_func):
        print "Creating Follower: Monitor(%s) Follow(%s)" % (pvmonitor,
                                                             pvfollower)

        # Create pyca.capv to connect to PV
        self.__pvmonitor = Pv(pvmonitor)
        self.__pvfollower = Pv(pvfollower)

        print "Monitor Name:", self.__pvmonitor.name
        print "Follower Name:", self.__pvfollower.name

        # Set Monitor call-back for pvmonitor
        self.__pvmonitor.monitor_cb = self.update_follower

        # Set up function to calculate new value of pvfollower based
        # on pvmonitor
        self.__follower_func = follower_func

    def create_channel(self):
        print "Connecting to PVs (please be patient)"

        try:
            self.__pvmonitor.connect(1.0)
            self.__pvfollower.connect(1.0)
        except pyca.pyexc, e:
            print "ERROR: Failed to connect:", e
            raise
        except pyca.caexc, e:
            print "ERROR, Channel Access Error:", e
            raise
Ejemplo n.º 5
0
 def __init__(self, name, adata=None):
     Pv.__init__(self, name)
     self.connected = False
     self._name = name
     self.evt = threading.Event()
     if adata != None:
         self.set_processor(adata)
     self.connect()
Ejemplo n.º 6
0
 def __init__(self, name):
     Pv.__init__(self, name)
     self.monitor_cb = self.monitor_handler
     self.__sem = threading.Event()
     self.__moving = False
     timeout = 1.0
     self.connect(timeout)
     evtmask = pyca.DBE_VALUE | pyca.DBE_LOG | pyca.DBE_ALARM
     self.monitor(evtmask, ctrl=False)
Ejemplo n.º 7
0
def caput(pvname, value, timeout=1.0):
    try:
        pv = Pv(pvname)
        pv.connect(timeout)
        pv.get(ctrl=False, timeout=timeout)
        pv.put(value, timeout)
        pv.disconnect()
        print 'caput', pvname, value
    except pyca.pyexc, e:
        print 'pyca exception: %s' % (e)
Ejemplo n.º 8
0
class fel_energy:
    """
    Class to control FEL energy.
    Takes two pvs:
     - a PV to set the FEL energy
     - a PV that changes once the FEL has settled to new energy
    """
    def __init__(self, ctrl, rbv, rbv_done):
        """
        ctrl : PV that sets the FEL 
        rbv  : PV that changes once the FEL has settled to new energy
        rbv_done: Value that indicates FEL has reached new energy
        """

        # Setup logger
        self.__logger = logging.getLogger(__name__)

        # String for CTRL and RBV PVs
        self.ctrl_pv = ctrl
        self.rbv_pv = rbv

        # Set up ctrl and rbv PVs
        self.__ctrl = Pv(ctrl)
        self.__rbv = Pv(rbv)

        self.rbv_done = rbv_done

        # Connect to Pvs
        self.__connect()

        # Threading event to signal when shutter has changed state
        self.__done = threading.Event()

        # Start monitors to live update shutter status
        # ..as soon as monitor starts, it will update self._open and
        # self._close
        self.__start_monitors()

    def __connect(self):
        """
        Connect to PVs
        """
        try:
            self.__ctrl.connect(1.0)
            self.__rbv.connect(1.0)
        except pyca.pyexc, e:
            self.__logger.error("Failed to connect or was already opened: %s" %
                                e)
            raise
        except pyca.caexc, e:
            self.__logger.error("Channel Access Error: %s" % e)
            raise
Ejemplo n.º 9
0
 def get(self, handle_no_ioc=True):
     """ returns current value for the Pv """
     if (is_debug_on()):
         logprint("caget %s: " % self.name)
     try:
         pycaPv.get(self, False, time_out_get)
         self.last_update = self.timestr()
         if (is_debug_on()):
             logprint("got %s\n" % self.value.__str__())
         return self.value
     except pyca.pyexc:
         logprint("caget %s: " % self.name, newline=False)
         logprint("failed (PV timed out) !!, returning nan")
         return numpy.nan
    def __intialize(self) :
        """
        Private method to call basepv.RINI PV and wait for it to
        complete 
        """

        # Create PV to basepv.RINI        
        init_pv = Pv(self.__basepv + ".RINI")

        # Connect to the PV
        try: 
            init_pv.connect(1.0)
        except pyca.pyexc, e:
            self.__logger.error("Failed to connect or was already opened: %s"%e)
            raise
Ejemplo n.º 11
0
    def __init__(self, gasdetpv):
        """
        gasdetpv: Base EPCIS PV for FEE gas detector        
        """

        # Set up gas detector PV
        self.__basepv = gasdetpv

        # Connect to gas detector PVs
        self.__energy_pv = Pv(self.__basepv + ":ENRC")

        # Internal dropped shot counter
        self.__dropped_shot = 0

        # Internal threshold to define dropped shots
        self.__threshold = 0.0
Ejemplo n.º 12
0
    def __init__(self,
                 motor_channel,
                 motor_name=None,
                 active_monitoring=False):
        self.motor_channel = motor_channel
        self.motor_name = motor_name
        self.active_monitoring = active_monitoring

        self.__move_pv = Pv(motor_channel)
        self.__move_pv.connect(1.0)
        #        self.__pos_pv = Pv(self.__get_pv_name('.RBV'))
        #        self.__pos_pv.connect(1.0)
        self.__dmovpv = donemoving(self.__get_pv_name('.DMOV'))

        self.update()
        pass
Ejemplo n.º 13
0
    def __init__(self, pvmonitor, pvfollower, follower_func):
        print "Creating Follower: Monitor(%s) Follow(%s)" % (pvmonitor,
                                                             pvfollower)

        # Create pyca.capv to connect to PV
        self.__pvmonitor = Pv(pvmonitor)
        self.__pvfollower = Pv(pvfollower)

        print "Monitor Name:", self.__pvmonitor.name
        print "Follower Name:", self.__pvfollower.name

        # Set Monitor call-back for pvmonitor
        self.__pvmonitor.monitor_cb = self.update_follower

        # Set up function to calculate new value of pvfollower based
        # on pvmonitor
        self.__follower_func = follower_func
Ejemplo n.º 14
0
def caget(pvname, timeout=1.0):
    try:
        pv = Pv(pvname)
        pv.connect(timeout)
        pv.get(ctrl=False, timeout=timeout)
        v = pv.value
        pv.disconnect()
        print 'caget', pvname, v
        return v
    except pyca.pyexc, e:
        print 'pyca exception: %s' % (e)
        return []
    def __init__(self, motorpv,timeout=1.0) :
        """
        motorpv : Base EPICS PV for IMS motors
        """
        # Set up logger
        self.__logger = logging.getLogger(__name__)
        
        # Set up motor  base pv
        self.__basepv = motorpv
        self.__logger.debug("%s Creating motor"%self.__basepv)


        # Create pyca variables
        # - Move to position (.VAL)
        self.__val = Pv(self.__basepv + ".VAL")
        # - Relative Move (Tweak) 
        self.__twv = Pv(self.__basepv + ".TWV") # Tweak Value
        self.__twf = Pv(self.__basepv + ".TWF") # Tweak Forward
        self.__twr = Pv(self.__basepv + ".TWR") # Tweak Reverse
        # - Motor position (.RBV)
        self.__rbv = Pv(self.__basepv + ".RBV")  
        # - Motor finished moving (.DMOV)
        self.__dmov = Pv(self.__basepv + ".DMOV")

        # Create threading event to signal when motion in progress
        self.__motion_done = threading.Event()

        # Connect to PVs
        self.__connect(timeout)


        # Start monitors to asynchronously track motor status
        self.__start_monitors()
Ejemplo n.º 16
0
    def __init__(self, ctrl, rbv, open_val, close_val):
        """
        ctrl: PV to command shutter to open/close
        rbv : PV to readback shutter status

        open_val : Value that opens shutter
        close_val: Value thst closes shutter
        """

        # Setup logger
        self.__logger = logging.getLogger(__name__)

        # Set up ctrl and rbv PVs
        self.__ctrl = Pv(ctrl)
        self.__rbv = Pv(rbv)

        # Set up values for shutter open/close
        self.__open_val = open_val
        self.__close_val = close_val

        # Boolean values that define if a shutter is in or out
        self.__open = False
        self.__close = False

        # Connect to Pvs
        self.__connect()

        # Threading event to signal when shutter has changed state
        self.__state_change = threading.Event()

        # Timing and event threads to wait after shutter has opened/closed
        #self.__wait_done = threading.Event()
        #self.__wait_thread = threading.Timer(wait,self.__wait_done_cb)
        #self.__wait_thread.setName("Wait Thread")

        # Start monitors to live update shutter status
        # ..as soon as monitor starts, it will update self._open and
        # self._close
        self.__start_monitors()
Ejemplo n.º 17
0
 def _connectPv(self, name, timeout=1.0):
     try:
         pv = Pv(name)
         pv.connect(timeout)
         pv.get(False, timeout)
         return pv
     except:
         pass
Ejemplo n.º 18
0
class epics_gasdet:
    """
    Wrapper for FEE gas detector.
    Provides convenience methods to grab FEE gas detector PVs, and
    monitor for dropped shots
    """
    def __init__(self, gasdetpv):
        """
        gasdetpv: Base EPCIS PV for FEE gas detector        
        """

        # Set up gas detector PV
        self.__basepv = gasdetpv

        # Connect to gas detector PVs
        self.__energy_pv = Pv(self.__basepv + ":ENRC")

        # Internal dropped shot counter
        self.__dropped_shot = 0

        # Internal threshold to define dropped shots
        self.__threshold = 0.0

    def connect(self, timeout=1.0):
        """
        connect to gas detector
        timeout: time to wait for EPICS connectrion (option)
        """
        try:
            self.__energy_pv.connect(timeout)
            print "Gas-detector", self.__basepv, "connected"
        except pyca.pyexc, e:
            print "ERROR: Failed to connect or was already opened:", e
            raise
        except pyca.caexc, e:
            print "ERROR: Channel Access Error:", e
            raise
Ejemplo n.º 19
0
    def __init__(self, camerapv) :
        """
        camerapv: Base EPICS PV for the camera
        """        
        # Set up logger
        self.__logger = logging.getLogger(__name__)

        # Set up camera PVs 
        self.__basepv = camerapv

        # Get row and columns, bit-depth, and model
        # Using caget as we only need these values once
        self.__nrow = caget(self.__basepv + ":N_OF_ROW")
        self.__ncol = caget(self.__basepv + ":N_OF_COL")
        self.__nbit = caget(self.__basepv + ":N_OF_BITS")
        self.__model = caget(self.__basepv + ":Model")

        # Print out status
        print self.__basepv,self.__model
        print self.__nrow,"by",self.__ncol,"@",self.__nbit

        # Create PV to LIVE_IMAGE_FAST and average image
        # Using Pv class, as we'll be wanting these PVs all the time
        self.__liveimage_pv = Pv(self.__basepv + ":LIVE_IMAGE_FULL")
        self.__avgimage_pv = Pv(self.__basepv + ":AVG_IMAGE")
        self.__navgimage_pv = Pv(self.__basepv + ":AVERAGER.A")

        # Create PV to get horizontal projection
        self.__hproj_pv = Pv(self.__basepv + ":IMAGE_CMPX:HPrj")
                
        
        # Create Threading Event objects to signal when new images are
        # available  
        self.__new_liveimage = threading.Event()
        self.__new_avgimage = threading.Event()
        self.__new_hproj = threading.Event()


        # Connect to PVs
        self.connect()


        # Start monitors to asynchronously update Live Image, Average
        # Image, and horizontal projection
        self.__start_monitors()
Ejemplo n.º 20
0
def update_labels(evrPvName, outputNum, write):
    triggerName = evrPvName + ":TRIG%1d:" % (outputNum)
    try:
        # See if this trigger exists
        tDesPv = Pv(triggerName + "TDES")
        tDesPv.connect(0.1)
        tDesPv.get(False, 0.1)
    except Exception, msg:
        if showCAErrors:
            print >> sys.stderr, "failed: pyca exception: ", msg
        return
Ejemplo n.º 21
0
    def __init__(self, timeout=1.0):
        # The definition of the pv names
        self._pvNames = {}
        self._pvSize = {}
        for pvDef in pvDefinitions:
            self._pvNames[pvDef[0]] = pvDef[1]
            self._pvSize[pvDef[0]] = pvDef[2]

        # Make the PV objects
        self._pv = {}
        for k, v in self._pvNames.iteritems():
            self._pv[k] = Pv(v)

        # Open connection to the PVs
        try:
            for pv in self._pv.itervalues():
                pv.connect(timeout=timeout)
        except pyca.pyexc, e:
            print 'ERROR: Failed to connect:', e
            raise
Ejemplo n.º 22
0
 def put(self, value):
     """ put value to the Pv, returns the value itself """
     if (is_debug_on()):
         logprint("caput %s in %s\n" % (value, self.name))
     pycaPv.put(self, value, time_out_get)
     return value
Ejemplo n.º 23
0
def caput(pvname, value):
    pv = Pv(pvname)
    pv.connect(1.)
    pv.put(value, timeout=1.)
    pv.disconnect()
Ejemplo n.º 24
0
    except Exception as msg:
        options.usage(str(msg))
        sys.exit()

    if options.connect_timeout is not None:
        connect_timeout = float(options.connect_timeout)
    else:
        connect_timeout = 1.0
    if options.put_timeout is not None:
        put_timeout = float(options.put_timeout)
    else:
        put_timeout = 1.0

    try:
        value = int(options.value)
    except Exception:
        value = float(options.value)

    try:
        pv = Pv(options.pvname)
        pv.connect(connect_timeout)
        pv.get(ctrl=False, timeout=put_timeout)
        print('Old: %-30s' % (pv.name), pv.value)
        pv.put(value, put_timeout)
        pv.get(ctrl=False, timeout=put_timeout)
        print('New: %-30s' % (pv.name), pv.value)
    except pyca.pyexc as e:
        print('pyca exception: %s' % (e))
    except pyca.caexc as e:
        print('channel access exception: %s' % (e))
Ejemplo n.º 25
0
 def __init__(self, name, maxlen, hex):
     Pv.__init__(self, name)
     self.monitor_cb = self.monitor_handler
     self.__maxlen = maxlen
     self.__hex = hex
Ejemplo n.º 26
0
    def save_motors(self, motors):
        i = 0
        im = len(motors)
        for m in motors:
            er_pvname = m.pvname + ":ER"
            er_pv = Pv(er_pvname)
            er_pv.connect(5)
            er_clr_pv = Pv(m.pvname + ":CLR_ER")
            er_clr_pv.connect(5)
            er_pv.get(timeout=5)
            pyca.pend_io(5)
            er_old = er_pv.data['value']

            pyca.pend_io(5)
            er_pv.get(timeout=5)
            pyca.pend_io(5)
            er_new = er_pv.data['value']
            print "%3d/%3d   %-15s   %2s   %2s" % (int(i + 1), im, m.name,
                                                   str(er_old), str(er_new))
            i += 1
            pass
        pass
Ejemplo n.º 27
0

def update_labels(evrPvName, outputNum, write):
    triggerName = evrPvName + ":TRIG%1d:" % (outputNum)
    try:
        # See if this trigger exists
        tDesPv = Pv(triggerName + "TDES")
        tDesPv.connect(0.1)
        tDesPv.get(False, 0.1)
    except Exception, msg:
        if showCAErrors:
            print >> sys.stderr, "failed: pyca exception: ", msg
        return

    if (outputNum >= 10):
        fpLabelPv = Pv(evrPvName + ":FP%1cL" % (ord('A') + outputNum - 10))
        fpDescPv = Pv(evrPvName + ":FP%1cL.DESC" % (ord('A') + outputNum - 10))
        trigPv = Pv(evrPvName + ":TRIG%1c:TCTL.DESC" %
                    (ord('A') + outputNum - 10))
    else:
        fpLabelPv = Pv(evrPvName + ":FP%1dL" % (outputNum))
        fpDescPv = Pv(evrPvName + ":FP%1dL.DESC" % (outputNum))
        trigPv = Pv(evrPvName + ":TRIG%1d:TCTL.DESC" % (outputNum))

    fpLabelName = ""
    fpDescName = ""
    trigName = ""

    # Connect and get the values for each
    try:
        fpLabelPv.connect(0.1)
Ejemplo n.º 28
0
    try:
        options.parse()
    except Exception as msg:
        options.usage(str(msg))
        sys.exit()

    pvnames = options.pvnames.split()

    if options.timeout is not None:
        timeout = float(options.timeout)
    else:
        timeout = 1.0

    states = ["never connected", "previously connected", "connected", "closed"]
    access = ['none', 'read only', 'write only', 'read-write']

    for pvname in pvnames:
        try:
            pv = Pv(pvname)
            pv.connect(timeout)
            print(pv.name)
            print('  State: ', states[pv.state()])
            print('  Host:  ', pv.host())
            print('  Access:', access[pv.rwaccess()])
            print('  Type:  ', pv.type())
            print('  Count: ', pv.count())
        except pyca.pyexc as e:
            print('pyca exception: %s' % (e))
        except pyca.caexc as e:
            print('channel access exception: %s' % (e))
Ejemplo n.º 29
0
def update_move(input_motor, output_motor):
    """
    Update output's position usin input's position
    """
    print "input", input_motor.get(), "output", output_motor.get()
    newposition = inputmotor.get() * (-0.5 * inputmotor.get())
    print "output new position", newposition
    output_motor.put(newposition)


evtmask = pyca.DBE_VALUE | pyca.DBE_LOG | pyca.DBE_ALARM

# connect to inputpv
print "Connecting to", inputpv
try:
    input_motor = Pv(inputpv + ".RBV")
    input_motor.monitor_cb = motor_moved
    input_motor.connect(1.0)
    input_motor.monitor(evtmask)

    output_motor = Pv(outputpv + ".VAL")

    print "waiting 10sec for monitoring to connect"
    time.sleep(10)
    print "Starting monitoring"

    for i in range(100):
        print i, datetime.datetime.now()
        time.sleep(10)

    input.unsubscribe_channel()
Ejemplo n.º 30
0
class epics_camera :
    """
    Wrapper to grab an image from a EPICS camera and save it as a
    numpy array.  Additional image manipulation routines are also
    included. 
    """

    def __init__(self, camerapv) :
        """
        camerapv: Base EPICS PV for the camera
        """        
        # Set up logger
        self.__logger = logging.getLogger(__name__)

        # Set up camera PVs 
        self.__basepv = camerapv

        # Get row and columns, bit-depth, and model
        # Using caget as we only need these values once
        self.__nrow = caget(self.__basepv + ":N_OF_ROW")
        self.__ncol = caget(self.__basepv + ":N_OF_COL")
        self.__nbit = caget(self.__basepv + ":N_OF_BITS")
        self.__model = caget(self.__basepv + ":Model")

        # Print out status
        print self.__basepv,self.__model
        print self.__nrow,"by",self.__ncol,"@",self.__nbit

        # Create PV to LIVE_IMAGE_FAST and average image
        # Using Pv class, as we'll be wanting these PVs all the time
        self.__liveimage_pv = Pv(self.__basepv + ":LIVE_IMAGE_FULL")
        self.__avgimage_pv = Pv(self.__basepv + ":AVG_IMAGE")
        self.__navgimage_pv = Pv(self.__basepv + ":AVERAGER.A")

        # Create PV to get horizontal projection
        self.__hproj_pv = Pv(self.__basepv + ":IMAGE_CMPX:HPrj")
                
        
        # Create Threading Event objects to signal when new images are
        # available  
        self.__new_liveimage = threading.Event()
        self.__new_avgimage = threading.Event()
        self.__new_hproj = threading.Event()


        # Connect to PVs
        self.connect()


        # Start monitors to asynchronously update Live Image, Average
        # Image, and horizontal projection
        self.__start_monitors()


    
    # Define properties to return camera model and image size
    @property
    def nrow(self):
        return self.__nrow

    @property
    def ncol(self):
        return self.__ncol

    @property
    def nbit(self):
        return self.__nbit

    @property
    def model(self):
        return self.__model




      
    def connect(self,timeout=300.0) :
        """ 
        connect to camera
        timeout : time to wait for EPICS connection (option)
        """
        # Connect to camera PV and cache number of row,columns
        try: 
            self.__liveimage_pv.connect(timeout)
            self.__avgimage_pv.connect(timeout)
            self.__navgimage_pv.connect(timeout)
            self.__hproj_pv.connect(timeout)
        except pyca.pyexc, e:
            print "ERROR: Failed to connect or was already opened:",e
            raise
        except pyca.caexc, e:
            print "ERROR: Channel Access Error:",e
            raise