EPICS Proxy example¶
The epics proxy should provide methods that look the same as those in pyepics https://cars9.uchicago.edu/software/python/pyepics3/
In [1]:
Copied!
# Useful for debugging
%load_ext autoreload
%autoreload 2
# Useful for debugging
%load_ext autoreload
%autoreload 2
In [2]:
Copied!
from lcls_live.epics import epics_proxy
import os
from lcls_live.epics import epics_proxy
import os
In [3]:
Copied!
epics = epics_proxy('data/epics_snapshot_2018-03-06T15:21:15.000000-08:00.json', verbose=True)
epics = epics_proxy('data/epics_snapshot_2018-03-06T15:21:15.000000-08:00.json', verbose=True)
Loaded data/epics_snapshot_2018-03-06T15:21:15.000000-08:00.json with 2065 PVs
In [4]:
Copied!
# Data is kept internally as a dict in .pvdata:
list(epics.pvdata)[0:10]
# Data is kept internally as a dict in .pvdata:
list(epics.pvdata)[0:10]
Out[4]:
['ACCL:IN20:350:FUDGE', 'ACCL:LI21:180:L1X_S_AV', 'ACCL:LI21:180:L1X_S_PV', 'ACCL:LI21:1:FUDGE', 'ACCL:LI21:1:L1S_S_PV', 'ACCL:LI22:1:FUDGE', 'ACCL:LI24:100:KLY_PDES', 'ACCL:LI24:200:KLY_PDES', 'ACCL:LI24:300:KLY_PDES', 'ACCL:LI25:1:FUDGE']
In [5]:
Copied!
# caget fetches from .pvdata
epics.caget('KLYS:LI21:11:ENLD')
# caget fetches from .pvdata
epics.caget('KLYS:LI21:11:ENLD')
Out[5]:
115.836
In [6]:
Copied!
# caput writes to .pvdata
epics.caput('KLYS:LI21:11:ENLD', 3)
epics.caget('KLYS:LI21:11:ENLD')
# caput writes to .pvdata
epics.caput('KLYS:LI21:11:ENLD', 3)
epics.caget('KLYS:LI21:11:ENLD')
Out[6]:
3
In [7]:
Copied!
# PV
pv = epics.PV('KLYS:LI21:11:ENLD')
pv.get()
# PV
pv = epics.PV('KLYS:LI21:11:ENLD')
pv.get()
PV for KLYS:LI21:11:ENLD
Out[7]:
3
In [8]:
Copied!
# caget_many
epics.caget_many(['KLYS:LI21:11:ENLD',
'ACCL:LI21:1:L1S_S_PV',
'KLYS:LI21:11:PDES',
'KLYS:LI21:11:SWRD',
'KLYS:LI21:11:STAT',
'KLYS:LI21:11:HDSC',
'KLYS:LI21:11:DSTA',
'KLYS:LI21:11:BEAMCODE1_STAT',
'ACCL:LI21:180:L1X_S_AV',
'ACCL:LI21:180:L1X_S_PV'])
# caget_many
epics.caget_many(['KLYS:LI21:11:ENLD',
'ACCL:LI21:1:L1S_S_PV',
'KLYS:LI21:11:PDES',
'KLYS:LI21:11:SWRD',
'KLYS:LI21:11:STAT',
'KLYS:LI21:11:HDSC',
'KLYS:LI21:11:DSTA',
'KLYS:LI21:11:BEAMCODE1_STAT',
'ACCL:LI21:180:L1X_S_AV',
'ACCL:LI21:180:L1X_S_PV'])
Out[8]:
[3, -26.12494033014282, -24.5, 0, 1, 1048577.0, [1610612738.0, 528640.0], 1.0, 20.01551950520014, -159.9562692633193]
In [9]:
Copied!
# Non-epics routine to save .pvdata to a JSON file
epics.save(filename='test.json')
# Non-epics routine to save .pvdata to a JSON file
epics.save(filename='test.json')
Saved test.json
In [10]:
Copied!
# Corresponding load routine
epics.load(filename='test.json')
# Corresponding load routine
epics.load(filename='test.json')
Loaded test.json with 2065 PVs
In [11]:
Copied!
# Cleanup
os.remove('test.json')
# Cleanup
os.remove('test.json')
Nested proxies¶
In [12]:
Copied!
# Start with a 'base' source of epics data
epics0 = epics_proxy('data/epics_snapshot_2018-03-06T15:21:15.000000-08:00.json', verbose=True)
# Make another proxy
epics1 = epics_proxy('cache.json', epics=epics0, verbose=True)
# Start with a 'base' source of epics data
epics0 = epics_proxy('data/epics_snapshot_2018-03-06T15:21:15.000000-08:00.json', verbose=True)
# Make another proxy
epics1 = epics_proxy('cache.json', epics=epics0, verbose=True)
Loaded data/epics_snapshot_2018-03-06T15:21:15.000000-08:00.json with 2065 PVs
In [13]:
Copied!
# Get a value
epics1.caget('KLYS:LI21:11:ENLD')
# Get a value
epics1.caget('KLYS:LI21:11:ENLD')
Error: pv not cached: KLYS:LI21:11:ENLD Loading from epics
Out[13]:
115.836
In [14]:
Copied!
# This is the internal data
epics1.pvdata
# This is the internal data
epics1.pvdata
Out[14]:
{'KLYS:LI21:11:ENLD': 115.836}
In [15]:
Copied!
epics1.caget_many(['KLYS:LI21:11:ENLD', 'KLYS:LI21:11:DSTA'])
epics1.caget_many(['KLYS:LI21:11:ENLD', 'KLYS:LI21:11:DSTA'])
Out[15]:
[115.836, [1610612738.0, 528640.0]]
In [16]:
Copied!
# This is the internal data
epics1.pvdata
# This is the internal data
epics1.pvdata
Out[16]:
{'KLYS:LI21:11:ENLD': 115.836}
In [17]:
Copied!
# Save to JSON
epics1.save()
# Save to JSON
epics1.save()
Saved cache.json
In [18]:
Copied!
# Cleanup
os.remove('cache.json')
# Cleanup
os.remove('cache.json')