def __init__(self, provider_name, *, base, root, pvMap=None, syncRead=True): self._srv = StaticProvider(provider_name) self._root = root self._base = base self._log = pyrogue.logInit(cls=self) self._syncRead = syncRead self.pvs = [] if not root.running: raise Exception( "Epics can not be setup on a tree which is not started") if pvMap is None: doAll = True self._pvMap = {} else: doAll = False self._pvMap = pvMap # Create PVs for v in self._root.variableList: self._addPv(v, doAll)
def run(self): self.provider = StaticProvider(__name__) self.fieldNames = SharedPV(initial=NTScalar('as').wrap( {'value': ['pid%02x' % i for i in range(31)]}), handler=DefaultPVHandler(self)) # 'i' (integer) or 'f' (float) self.fieldTypes = SharedPV(initial=NTScalar('aB').wrap( {'value': [ord('i')] * 31}), handler=DefaultPVHandler(self)) self.fieldMask = SharedPV(initial=NTScalar('I').wrap({'value': 0x8000}), handler=DefaultPVHandler(self)) self.payload = SharedPV(initial=Value(Type([]), {}), handler=DefaultPVHandler(self)) print('Hosting {:}HPS:FIELDMASK'.format(self.prefix)) self.provider.add(self.prefix + 'HPS:FIELDNAMES', self.fieldNames) self.provider.add(self.prefix + 'HPS:FIELDTYPES', self.fieldTypes) self.provider.add(self.prefix + 'HPS:FIELDMASK', self.fieldMask) self.provider.add(self.prefix + 'PAYLOAD', self.payload) self.update() try: Server.forever(providers=[self.provider]) except: print('Server exited')
def __init__(self, provider_name, prefix): self.provider = StaticProvider(provider_name) self.prefix = prefix self.pvs = [] self.fieldNames = SharedPV(initial=NTScalar('as').wrap( {'value': ['pid%02x' % i for i in range(31)]}), handler=DefaultPVHandler(self)) # 'i' (integer) or 'f' (float) self.fieldTypes = SharedPV(initial=NTScalar('aB').wrap( {'value': [ord('i')] * 31}), handler=DefaultPVHandler(self)) self.fieldMask = SharedPV(initial=NTScalar('I').wrap({'value': 0x1}), handler=DefaultPVHandler(self)) self.payload = SharedPV(initial=Value(Type([]), {}), handler=DefaultPVHandler(self)) self.provider.add(prefix + 'HPS:FIELDNAMES', self.fieldNames) self.provider.add(prefix + 'HPS:FIELDTYPES', self.fieldTypes) self.provider.add(prefix + 'HPS:FIELDMASK', self.fieldMask) self.provider.add(prefix + 'PAYLOAD', self.payload) self.update()
def __init__(self, name, comm_addr, export_addr, aggregate=False): self.base = name self.ctx = zmq.Context() self.export = self.ctx.socket(zmq.SUB) self.export.setsockopt_string(zmq.SUBSCRIBE, "") self.export.connect(export_addr) self.comm = self.ctx.socket(zmq.REQ) self.comm.connect(comm_addr) self.queue = ThreadedWorkQueue(maxsize=20, workers=1) # pva server provider self.provider = StaticProvider(name) self.rpc_provider = NTURIDispatcher(self.queue, target=PvaExportRpcHandler( self.ctx, comm_addr), name="%s:cmd" % self.base, prefix="%s:cmd:" % self.base) self.server_thread = threading.Thread(target=self.server, name='pvaserv') self.server_thread.daemon = True self.aggregate = aggregate self.pvs = {} self.ignored = set() self.graph_pvbase = "ana" self.data_pvbase = "data" self.info_pvbase = "info" self.cmd_pvs = {'command'} self.payload_cmd_pvs = {'add', 'set', 'del'}
def __init__(self): self.provider = StaticProvider('ttfex_provider') self.pvs = {} pv = SharedPV(nt=NTScalar('d'), initial=0.0) self.provider.add('DRP:ATM:CAM:01:Pva:FLTPOS', pv) self.pvs['FLTPOS'] = pv
def __init__(self, provider_name, prefix): self.provider = StaticProvider(provider_name) self.prefix = prefix # Monitoring self.image = SharedPV(initial=NTScalar('ai').wrap({'value': [0] * 128}), handler=DefaultPVHandler()) self.provider.add(prefix, self.image)
def main(args): provider = StaticProvider('mailbox') # 'mailbox' is an arbitrary name pvs = [ ] # we must keep a reference in order to keep the Handler from being collected for name in args.name: pv = SharedPV(initial=types['int'], handler=MailboxHandler()) provider.add(name, pv) pvs.append(pv) Server.forever(providers=[provider]) print('Done')
def run(self): self.provider = StaticProvider(__name__) self._pv = [] self._msgHeader = 0 def addPV(label,cmd): pv = SharedPV(initial=NTScalar('I').wrap(0), handler=PVHandler(cmd)) name = self._name+':'+label print('Registering {:}'.format(name)) self.provider.add(name,pv) self._pv.append(pv) addPV('GroupL0Reset' , self.l0Reset) addPV('GroupL0Enable' , self.l0Enable) addPV('GroupL0Disable' , self.l0Disable) addPV('GroupMsgInsert' , self.msgInsert) addPV('PART:0:Master' , self.master) addPV('PART:0:MsgHeader', self.msgHeader) with Server(providers=[self.provider]): while True: time.sleep(1)
def main(): global pvdb pvdb = {} # start with empty dictionary global prefix prefix = '' global provider parser = argparse.ArgumentParser(prog=sys.argv[0], description='host PVs for KCU') parser.add_argument('-i', '--interval', type=int, help='PV update interval', default=10) parser.add_argument('-H', '--hsd', action='store_true', help='HSD node', default=False) args = parser.parse_args() # Set base base = pr.Root(name='KCUr', description='') coreMap = rogue.hardware.axi.AxiMemMap('/dev/datadev_0') base.add(Top(memBase=coreMap)) # Start the system base.start( pollEn=False, initRead=False, zmqPort=None, ) kcu = base.KCU if args.hsd: kcu.I2cBus.selectDevice('QSFP0') print(kcu.I2cBus.QSFP0.getRxPwr()) else: print(kcu.TDetTiming.getClkRates()) print(kcu.TDetSemi.getRTT()) provider = StaticProvider(__name__) pvstats = PVStats( 'DAQ:LAB2:' + socket.gethostname().replace('-', '_').upper(), kcu, args.hsd) # process PVA transactions updatePeriod = args.interval with Server(providers=[provider]): try: pvstats.init() while True: prev = time.perf_counter() pvstats.update() curr = time.perf_counter() delta = prev + updatePeriod - curr # print('Delta {:.2f} Update {:.2f} curr {:.2f} prev {:.2f}'.format(delta,curr-prev,curr,prev)) if delta > 0: time.sleep(delta) except KeyboardInterrupt: pass
initial = self.pos final = op.value() delta = abs(final-initial) op.info("Moving %s -> %s"%(initial, final)) while delta>=1.0: op.info("Moving %s"%delta) delta -= 1.0 cothread.Sleep(1.0) # move at 1 step per second self.pos = final op.done() finally: self.busy = False pv = SharedPV(nt=NTScalar('d'), initial=0.0, handler=MoveHandler()) provider = StaticProvider('move') # 'move' is an arbitrary name provider.add("foo", pv) with Server(providers=[provider]): print('Running') try: cothread.WaitForQuit() except KeyboardInterrupt: pass print('Done')
def __init__(self, provider_name): self.provider = StaticProvider(provider_name) self.pvs = []
def __init__(self, provider_name, prefix, start): self.provider = StaticProvider(provider_name) self.chip = ChipServer(self.provider, prefix, start)
prefix = sys.argv[1] list_type = NTScalar('as') types = { 'int': NTScalar('i').wrap(0), 'float': NTScalar('d').wrap(0.0), 'str': NTScalar('s').wrap(''), 'enum': NTEnum().wrap(0), } pvs_lock = Lock() pvs = {} provider = StaticProvider('dynamicbox') class MailboxHandler(object): def put(self, pv, op): pv.post(op.value()) op.done() addpv = SharedPV(initial=NTScalar('s').wrap('Only RPC')) delpv = SharedPV(initial=NTScalar('s').wrap('Only RPC')) listpv = SharedPV(nt=list_type, initial=[]) provider.add(prefix + "add", addpv) provider.add(prefix + "del", delpv) provider.add(prefix + "list", listpv)
def main(): global pvdb pvdb = {} # start with empty dictionary global prefix prefix = '' parser = argparse.ArgumentParser(prog=sys.argv[0], description='host PVs for XPM') parser.add_argument('-P', required=True, help='e.g. DAQ:LAB2:XPM:1', metavar='PREFIX') parser.add_argument('-v', '--verbose', action='store_true', help='be verbose') parser.add_argument('--ip', type=str, required=True, help="IP address") parser.add_argument( '--db', type=str, default=None, help= "save/restore db, for example [https://pswww.slac.stanford.edu/ws-auth/devconfigdb/ws/,configDB,LAB2,PROD]" ) parser.add_argument('-I', action='store_true', help='initialize Cu timing') parser.add_argument('-L', action='store_true', help='bypass AMC Locks') parser.add_argument('-F', type=float, default=1.076923e-6, help='fiducial period (sec)') parser.add_argument('-C', type=int, default=200, help='clocks per fiducial') args = parser.parse_args() if args.verbose: # logging.basicConfig(level=logging.DEBUG) setVerbose(True) # Set base base = pr.Root(name='AMCc', description='') base.add(Top( name='XPM', ipAddr=args.ip, fidPrescale=args.C, )) # Start the system base.start( # pollEn = False, # initRead = False, # zmqPort = None, ) xpm = base.XPM app = base.XPM.XpmApp # Print the AxiVersion Summary xpm.AxiVersion.printStatus() provider = StaticProvider(__name__) lock = Lock() pvstats = PVStats(provider, lock, args.P, xpm, args.F) # pvctrls = PVCtrls(provider, lock, name=args.P, ip=args.ip, xpm=xpm, stats=pvstats._groups, handle=pvstats.handle, db=args.db, cuInit=True) pvctrls = PVCtrls(provider, lock, name=args.P, ip=args.ip, xpm=xpm, stats=pvstats._groups, handle=pvstats.handle, db=args.db, cuInit=args.I, fidPrescale=args.C, fidPeriod=args.F * 1.e9) pvxtpg = None # process PVA transactions updatePeriod = 1.0 cycle = 0 with Server(providers=[provider]): try: if pvxtpg is not None: pvxtpg.init() pvstats.init() while True: prev = time.perf_counter() pvstats.update(cycle) pvctrls.update(cycle) # We have to delay the startup of some classes if cycle == 5: pvxtpg = PVXTpg(provider, lock, args.P, xpm, xpm.mmcmParms, cuMode='xtpg' in xpm.AxiVersion.ImageName.get(), bypassLock=args.L) pvxtpg.init() elif cycle < 5: print('pvxtpg in %d' % (5 - cycle)) if pvxtpg is not None: pvxtpg.update() curr = time.perf_counter() delta = prev + updatePeriod - curr # print('Delta {:.2f} Update {:.2f} curr {:.2f} prev {:.2f}'.format(delta,curr-prev,curr,prev)) if delta > 0: time.sleep(delta) cycle += 1 except KeyboardInterrupt: pass
def __init__(self, provider_name, prefix): self.provider = StaticProvider(provider_name) self.a = ChipServer(self.provider, prefix+':A') self.b = ChipServer(self.provider, prefix+':B')
def main(): global pvdb pvdb = {} # start with empty dictionary global prefix prefix = '' parser = argparse.ArgumentParser(prog=sys.argv[0], description='host PVs for XPM') parser.add_argument('-P', required=True, help='e.g. DAQ:LAB2:XPM:1', metavar='PREFIX') parser.add_argument('-v', '--verbose', action='store_true', help='be verbose') parser.add_argument('--ip', type=str, required=True, help="IP address" ) parser.add_argument('--db', type=str, default=None, help="save/restore db, for example [https://pswww.slac.stanford.edu/ws-auth/devconfigdb/ws/,configDB,LAB2,PROD]") args = parser.parse_args() if args.verbose: # logging.basicConfig(level=logging.DEBUG) setVerbose(True) # Set base base = pr.Root(name='AMCc',description='') base.add(Top( name = 'XPM', ipAddr = args.ip )) # Start the system base.start( pollEn = False, initRead = False, zmqPort = None, ) xpm = base.XPM app = base.XPM.XpmApp # Print the AxiVersion Summary xpm.AxiVersion.printStatus() provider = StaticProvider(__name__) lock = Lock() pvstats = PVStats(provider, lock, args.P, xpm) pvctrls = PVCtrls(provider, lock, name=args.P, ip=args.ip, xpm=xpm, stats=pvstats._groups, db=args.db) pvxtpg = PVXTpg(provider, lock, args.P, xpm, xpm.mmcmParms, cuMode='xtpg' in xpm.AxiVersion.ImageName.get()) # process PVA transactions updatePeriod = 1.0 with Server(providers=[provider]): try: if pvxtpg is not None: pvxtpg .init() pvstats.init() while True: prev = time.perf_counter() if pvxtpg is not None: pvxtpg .update() pvstats.update() pvctrls.update() curr = time.perf_counter() delta = prev+updatePeriod-curr # print('Delta {:.2f} Update {:.2f} curr {:.2f} prev {:.2f}'.format(delta,curr-prev,curr,prev)) if delta>0: time.sleep(delta) except KeyboardInterrupt: pass
from p4p.server import Server, StaticProvider from . import v4l, color def getargs(): from argparse import ArgumentParser P = ArgumentParser() P.add_argument('video', help='A V4L2 device (eg. /dev/video0') P.add_argument('pvname') return P args = getargs().parse_args() pv = SharedPV(nt=NTNDArray(), initial=numpy.zeros((0,0), dtype='u1')) provider = StaticProvider('capture') provider.add(args.pvname, pv) # open the capture device, and run the Server with open(args.video, 'r+b', 0) as F, Server(providers=[provider]): caps = v4l.query_capabilities(F.fileno()) print('capabilities', caps) if 'VIDEO_CAPTURE' not in caps['capabilities']: print("Not a capture device") sys.exit(1) idx = -1 for fmt in v4l.list_formats(F.fileno()): print('Supported:', fmt)
else: _log.info("Tick %s", self.count) self.pv.post(NT.wrap(self.count)) self.count += 1 def onLastDisconnect(self, pv): _log.info("Last client disconnects") # mark in-active, but don't immediately close() self.active = False def put(self, pv, op): # force counter value self.count = op.value().value op.done() pv = SharedPV(handler=LazyCounter()) provider = StaticProvider('lazy') # 'lazy' is an arbitrary name provider.add("foo", pv) with Server(providers=[provider]): print('Running') try: cothread.WaitForQuit() except KeyboardInterrupt: pass print('Done')