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() except pyca.pyexc, e: print 'pyca exception: %s' % (e)
def reconfigStream(cameraPvName, streamName, verbose=False): streamPvName = cameraPvName + ":" + streamName try: streamTypePv = Pv(streamPvName + ":StreamType") streamTypePv.connect(0.5) streamTypePv.get(timeout=1.0) except Exception, msg: if verbose: print "Stream %s not found." % streamName return
def caget(pvname, timeout=1.0): try: pv = Pv(pvname) pv.connect(timeout) pv.get(ctrl=False, timeout=timeout) v = pv.value pv.disconnect() return v except pyca.pyexc, e: print 'pyca exception: %s' % (e) return None
def connectPv(name, timeout=-1.0): try: pv = Pv(name) if timeout < 0: pv.connect_cb = lambda isconn: __connect_callback(pv, isconn) pv.connect(timeout) else: pv.connect(timeout) pv.get(False, timeout) return pv except: return None
def caGetValue(pvName, verbose=True, timeout=0.1): try: # See if this PV exists pv = Pv(pvName) pv.connect(timeout) pv.get() return pv.value except Exception, msg: if verbose: print "Unable to connect to PV: %s" % pvName if showCAErrors: print >> sys.stderr, "failed: pyca exception: ", msg return None
def printPvNameValue(pvName): try: pv = Pv(pvName) pv.connect(0.1) pv.get() if isinstance(pv.value, str): print "%s \"%-.30s\"" % (pv.name, pv.value) else: print "%s %-.30s" % (pv.name, pv.value) except pyca.pyexc, msg: if showCAErrors: print >> sys.stderr, "failed: pyca exception: ", msg pass
class LclsEvent(object): """ Contains methods to view and change parameters from the lcls event/timing system screen. """ def __init__(self): self._bykik_abort_pv = Pv(ioc_base + "BYKIK_ABTACT") self._bykik_period_pv = Pv(ioc_base + "BYKIK_ABTPRD") def edm_screen(self): """ Open up the lcls event/timing screen. """ subprocess.Popen([ "sh", "/reg/g/pcds/package/epics/3.14-dev/screens/edm/common/current/lcls/lclsSystemArea.sh" ]) def bykik_status(self): """ Return status of bykik abort (Disable or Enable) """ val = self._bykik_abort_pv.get() if val == 0: return "Disable" else: return "Enable" def bykik_disable(self): """ Disable bykik abort """ self._bykik_abort_pv.put(0) def bykik_enable(self): """ Enable bykik abort """ self._bykik_abort_pv.put(1) def bykik_get_period(self): """ Get number of events between bykik aborts """ return self._bykik_period_pv.get() def bykik_set_period(self, period): """ Set number of events between bykik aborts """ self._bykik_period_pv.put(period)
def caget(pvname,timeout=30.0): try: pv = Pv(pvname) pv.connect(timeout) pv.get(ctrl=False, timeout=timeout) v = pv.value pv.disconnect() return v except pyca.pyexc as e: print('pyca exception: %s' %(e)) return None except pyca.caexc as e: print('channel access exception: %s' %(e)) return None
def caput(pvname, value, timeout=1.0, **kw): try: pv = Pv(pvname) pv.connect(timeout) pv.get(ctrl=False, timeout=timeout) try: if kw['enum']: pv.set_string_enum(True) except: pass pv.put(value, timeout=timeout) pv.disconnect() except pyca.pyexc, e: print 'pyca exception: %s' % (e)
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 caget(pvname, timeout=1.0, **kw): try: pv = Pv(pvname) pv.connect(timeout) try: if kw['enum']: pv.set_string_enum(True) except: pass pv.get(ctrl=False, timeout=timeout) v = pv.value pv.disconnect() return v except pyca.pyexc as e: print('pyca exception: %s' % (e)) return None except pyca.caexc as e: print('channel access exception: %s' % (e)) return None
class Imager(object): """ Imager object that will encapsulate the various yag screens along the beamline. """ def __init__(self, pv_camera, pv_x, pv_z, detector=Detector()): self.pv_obj_camera = Pv(pv_camera) self.pv_obj_x = Pv(pv_x) self.pv_obj_z = Pv(pv_z) self.detector = detector self.image = None self.centroid = None self.bounding_box = None def get(self): """Get an image from the imager.""" self.image = Pv.get() return self.image def get_centroid(self): """Return the centroid of the image.""" self.centroid, self.bounding_box = self.detector.find(Pv.get()) return self.centroid @property def x(self): return self.pv_obj_x.get() @x.setter def x(self, val): put_val(self.pv_obj_x, val) @property def z(self): return self.pv_obj_z.get() @z.setter def z(self, val): put_val(self.pv_obj_z, val) @property def pos(self): return np.array([self.pv_obj_z.get(), self.pv_obj_x.get()])
class Source(object): def __init__(self, pv_x, pv_xp, pv_y, pv_yp, pv_z): self.pv_obj_x = Pv(pv_x) self.pv_obj_xp = Pv(pv_xp) self.pv_obj_y = Pv(pv_y) self.pv_obj_yp = Pv(pv_yp) self.pv_obj_z = Pv(pv_z) def put_val(self, pv, val): try: pv.put(float(val)) except ValueError: print("Invalid input type. Must be castable to float.") @property def x(self): return self.pv_obj_x.get() @x.setter def x(self, val): put_val(self.pv_obj_x, val) @property def xp(self): return self.pv_obj_xp.get() @xp.setter def xp(self, val): put_val(self.pv_obj_xp, val) @property def y(self): return self.pv_obj_y.get() @y.setter def y(self, val): put_val(self.pv_obj_y, val) @property def yp(self): return self.pv_obj_yp.get() @yp.setter def yp(self, val): put_val(self.pv_obj_yp, val) @property def z(self): return self.pv_obj_z.get() @z.setter def z(self, val): put_val(self.pv_obj_z, val) @property def pos(self): return np.array([self.pv_obj_z.get(), self.pv_obj_x.get()])
class Mirror(object): """ Mirror class to encapsulate the two HOMS (or any) mirrors. """ def __init__(self, pv_x, pv_alpha, pv_z): self.pv_obj_x = Pv(pv_x) self.pv_obj_xp = Pv(pv_xp) self.pv_obj_z = Pv(pv_z) @property def x(self): return self.pv_obj_x.get() @x.setter def x(self, val): put_val(self.pv_obj_x, val) @property def alpha(self): return self.pv_obj_alpha.get() @alpha.setter def alpha(self, val): put_val(self.pv_obj_alpha, val) @property def z(self): return self.pv_obj_z.get() @z.setter def z(self, val): put_val(self.pv_obj_z, val) @property def pos(self): return np.array([self.pv_obj_z.get(), self.pv_obj_x.get()])
def get_centroid(self): """Return the centroid of the image.""" self.centroid, self.bounding_box = self.detector.find(Pv.get()) return self.centroid
def get(self): """Get an image from the imager.""" self.image = Pv.get() return self.image
def caget(pvname): pv = Pv(pvname) pv.connect(5.) pv.get(False, 5.) pv.disconnect() return pv.value
# ---------------------------------------------------------------------- if __name__ == "__main__": options = Options(['cameraPv', 'stream'], [], ['verbose']) try: options.parse() except Exception, msg: options.usage(str(msg)) sys.exit() cameraPvName = options.cameraPv streamName = options.stream try: camSizeXPv = Pv(cameraPvName + ":ArraySizeX_RBV") camSizeXPv.connect(0.1) camSizeXPv.get(timeout=1.0) except Exception, msg: print "Camera not accessible: ", msg sys.exit() verbose = False if options.verbose is not None: verbose = True if streamName != 'all': reconfigStream(cameraPvName, streamName, verbose=verbose) else: showCAErrors = False reconfigStream(cameraPvName, "DATA1", verbose=verbose) reconfigStream(cameraPvName, "IMAGE1", verbose=verbose) reconfigStream(cameraPvName, "IMAGE2", verbose=verbose) reconfigStream(cameraPvName, "THUMBNAIL", verbose=verbose)
if "cfg_id" not in key: _pv = Pv(prefix + ':' + key) _pv.connect(1.0) if type(val['value']) == list: _pv.put(tuple(val['value'])) else: _pv.put(val['value']) pyca.flush_io() # TODO: avoid creating Pv multiple times and avoid multiple connects for key, val in pvdb.items(): if "cfg_id" not in key: _pv = Pv(prefix + ':' + key) _pv.connect(1.0) _pv.get(False, 1.0) # config keys for pvNames are the strings after the last colon xtcDict = {} for key, val in pvNames.items(): if type(val['value']) == tuple: xtcDict[key.split(':')[-1]] = list(val['value']) else: xtcDict[key.split(':')[-1]] = val['value'] # Save configure transition to xtc.json config = {} config['alg'] = {} config['alg']['software'] = 'hsdConfig' config['alg']['version'] = list([1, 2, 4])