pypeto 0.6.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pypeto-0.6.6/LICENSE +21 -0
- pypeto-0.6.6/PKG-INFO +50 -0
- pypeto-0.6.6/README.md +34 -0
- pypeto-0.6.6/cad_epics/__init__.py +0 -0
- pypeto-0.6.6/cad_epics/epics.py +191 -0
- pypeto-0.6.6/pypeto/__init__.py +0 -0
- pypeto-0.6.6/pypeto/__main__.py +2067 -0
- pypeto-0.6.6/pyproject.toml +25 -0
pypeto-0.6.6/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Andrei Sukhanov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
pypeto-0.6.6/PKG-INFO
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: pypeto
|
|
3
|
+
Version: 0.6.6
|
|
4
|
+
Summary: Spreadsheet view of process variables from EPICS or liteServers
|
|
5
|
+
Project-URL: Homepage, https://github.com/ASukhanov/pypeto
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/ASukhanov/pypeto/issues
|
|
7
|
+
Author-email: Andrei Sukhanov <cyxandr@gmail.com>
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Requires-Python: >=3.8
|
|
13
|
+
Requires-Dist: caproto
|
|
14
|
+
Requires-Dist: qtpy
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# pypeto
|
|
18
|
+
PyQt-based tabular user interface for designing and implementing control screens for EPICS and LiteServer devices.
|
|
19
|
+
|
|
20
|
+
Supported:
|
|
21
|
+
- control of EPICS PVs and liteServer PVs,
|
|
22
|
+
- automatic page generation,
|
|
23
|
+
- merged cells, adjustable size of rows and columns, fonts and colors,
|
|
24
|
+
- horizontal and vertical slider widgets,
|
|
25
|
+
- configuration using python,
|
|
26
|
+
- macro substitution from command line: single configuration file can be used for many similar devices,
|
|
27
|
+
- embedding displays of other programs to a range of cells,
|
|
28
|
+
- plotting of selected cells using pvplot,
|
|
29
|
+
- content-driven cell coloring,
|
|
30
|
+
- snapshots: full page can be saved and the selected cells could be restored from the saved snapshots,
|
|
31
|
+
- slicing of vector parameters.
|
|
32
|
+
|
|
33
|
+
## Tests:
|
|
34
|
+
|
|
35
|
+
### Control of the litePeakSimulator
|
|
36
|
+
Start the litePeakSimulator liteserver on localhost if it is not running yet.
|
|
37
|
+
cd ~/github/liteServer
|
|
38
|
+
python3 -m liteserver.device.litePeakSimulator -ilo
|
|
39
|
+
|
|
40
|
+
Connect to litePeakSimulator from pypeto:
|
|
41
|
+
cd ~/github/pypeto
|
|
42
|
+
python3 -m pypeto -aLITE localhost:dev1&
|
|
43
|
+
|
|
44
|
+
Using interactive selection of configurations
|
|
45
|
+
|
|
46
|
+
pypeto
|
|
47
|
+
|
|
48
|
+
Using pypeto configuration file:
|
|
49
|
+
|
|
50
|
+
pypeto -f tst
|
pypeto-0.6.6/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# pypeto
|
|
2
|
+
PyQt-based tabular user interface for designing and implementing control screens for EPICS and LiteServer devices.
|
|
3
|
+
|
|
4
|
+
Supported:
|
|
5
|
+
- control of EPICS PVs and liteServer PVs,
|
|
6
|
+
- automatic page generation,
|
|
7
|
+
- merged cells, adjustable size of rows and columns, fonts and colors,
|
|
8
|
+
- horizontal and vertical slider widgets,
|
|
9
|
+
- configuration using python,
|
|
10
|
+
- macro substitution from command line: single configuration file can be used for many similar devices,
|
|
11
|
+
- embedding displays of other programs to a range of cells,
|
|
12
|
+
- plotting of selected cells using pvplot,
|
|
13
|
+
- content-driven cell coloring,
|
|
14
|
+
- snapshots: full page can be saved and the selected cells could be restored from the saved snapshots,
|
|
15
|
+
- slicing of vector parameters.
|
|
16
|
+
|
|
17
|
+
## Tests:
|
|
18
|
+
|
|
19
|
+
### Control of the litePeakSimulator
|
|
20
|
+
Start the litePeakSimulator liteserver on localhost if it is not running yet.
|
|
21
|
+
cd ~/github/liteServer
|
|
22
|
+
python3 -m liteserver.device.litePeakSimulator -ilo
|
|
23
|
+
|
|
24
|
+
Connect to litePeakSimulator from pypeto:
|
|
25
|
+
cd ~/github/pypeto
|
|
26
|
+
python3 -m pypeto -aLITE localhost:dev1&
|
|
27
|
+
|
|
28
|
+
Using interactive selection of configurations
|
|
29
|
+
|
|
30
|
+
pypeto
|
|
31
|
+
|
|
32
|
+
Using pypeto configuration file:
|
|
33
|
+
|
|
34
|
+
pypeto -f tst
|
|
File without changes
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"""Basic EPICS access API using caproto threading.
|
|
2
|
+
The API is similar to cad_io.
|
|
3
|
+
The devPar argument is tuple (deviceName,parameterName).
|
|
4
|
+
The EPICS PV name is concatenation of the deviceName and parameterName
|
|
5
|
+
|
|
6
|
+
For example: epics.get(('testAPD:scope1:','MaxValue_RBV')) returns
|
|
7
|
+
{('testAPD:scope1:', 'MaxValue_RBV'): {'value': 1.5620877339306638, 'timestamp': 1681488886.923712, 'alarm': 0}}
|
|
8
|
+
"""
|
|
9
|
+
__version__ = 'v0.0.2 2023-04-14'# No colon separation when splitting PV name to (device,parameter) tuple.
|
|
10
|
+
|
|
11
|
+
#from time import perf_counter as timer
|
|
12
|
+
|
|
13
|
+
from caproto.threading.client import Context
|
|
14
|
+
_Ctx = Context()
|
|
15
|
+
|
|
16
|
+
_PVCache = {}# cache of PVs
|
|
17
|
+
# the key is EPICS PV name, the fields are as follows:
|
|
18
|
+
_PVC_PV = 0# EPICS PV object
|
|
19
|
+
_PVC_CB = 1# callback
|
|
20
|
+
_PVC_Props = 2# PV properties
|
|
21
|
+
_PVC_DevPar = 3# (deviceName, ParameterName)
|
|
22
|
+
|
|
23
|
+
_Subscriptions = []# list of EPICS PV subscriptions
|
|
24
|
+
|
|
25
|
+
_CA_data_type_STRING = 14
|
|
26
|
+
|
|
27
|
+
_dbg = False
|
|
28
|
+
def _printd(msg):
|
|
29
|
+
if _dbg:
|
|
30
|
+
print(f'CPAccess:{msg}')
|
|
31
|
+
|
|
32
|
+
def init():
|
|
33
|
+
return
|
|
34
|
+
|
|
35
|
+
def _get_pv(devPar:tuple):
|
|
36
|
+
pvName = ''.join(devPar)
|
|
37
|
+
r = _PVCache.get(pvName)
|
|
38
|
+
if r is None:
|
|
39
|
+
_printd(f'register pv {pvName} {devPar}')
|
|
40
|
+
pv,*_ = _Ctx.get_pvs(''.join(pvName), timeout=2)
|
|
41
|
+
_PVCache[pvName] = [pv, None, None, devPar]
|
|
42
|
+
_fill_PVCacheProps(pv)
|
|
43
|
+
else:
|
|
44
|
+
pv,*_ = r
|
|
45
|
+
return pv
|
|
46
|
+
|
|
47
|
+
def _fill_PVCacheProps(pv):
|
|
48
|
+
pvName = pv.name
|
|
49
|
+
pvData = pv.read(data_type='time')
|
|
50
|
+
val = pvData.data
|
|
51
|
+
if len(val) == 1:
|
|
52
|
+
try:
|
|
53
|
+
# treat it as numpy
|
|
54
|
+
val = pvData.data[0].item()
|
|
55
|
+
except:
|
|
56
|
+
# data is not numpy
|
|
57
|
+
val = pvData.data[0]
|
|
58
|
+
|
|
59
|
+
# get properties
|
|
60
|
+
#ISSUE: the caproto reports timestamp as float, the precision for float64
|
|
61
|
+
#presentation is ~300ns
|
|
62
|
+
featureBit2Letter = {1:'R', 2:'WE'}
|
|
63
|
+
featureCode = pv.access_rights
|
|
64
|
+
features = ''
|
|
65
|
+
for bit, letter in featureBit2Letter.items():
|
|
66
|
+
if bit & featureCode:
|
|
67
|
+
features += letter
|
|
68
|
+
pvControl = pv.read(data_type='control')
|
|
69
|
+
#_printd(f'pvcontrol {pvName}: {pvControl}')
|
|
70
|
+
datatype = pvControl.data_type
|
|
71
|
+
#_printd(f'data_type:{datatype}')
|
|
72
|
+
if datatype == _CA_data_type_STRING:# convert text bytearray to str
|
|
73
|
+
val = val.decode()
|
|
74
|
+
props = {'value':val}
|
|
75
|
+
props['timestamp'] = pvData.metadata.timestamp
|
|
76
|
+
props['count'] = len(pvData.data)
|
|
77
|
+
props['features'] = features
|
|
78
|
+
try:
|
|
79
|
+
props['units'] = pvControl.metadata.units.decode()
|
|
80
|
+
if props['units'] == '': props['units'] = None
|
|
81
|
+
except: pass
|
|
82
|
+
|
|
83
|
+
try: props['engLow'] = pvControl.metadata.lower_ctrl_limit
|
|
84
|
+
except: pass
|
|
85
|
+
|
|
86
|
+
try:
|
|
87
|
+
props['engHigh'] = pvControl.metadata.upper_ctrl_limit
|
|
88
|
+
if props['engHigh'] == 0.0 and props['engHigh'] == 0.0:
|
|
89
|
+
props['engHigh'], props['engLow'] = None, None
|
|
90
|
+
except: pass
|
|
91
|
+
|
|
92
|
+
try:
|
|
93
|
+
props['alarm'] = pvControl.metadata.severity
|
|
94
|
+
#_printd(f'status {pvControl.metadata.severity}')
|
|
95
|
+
if props['alarm'] == 17:# UDF
|
|
96
|
+
props['alarm'] = None
|
|
97
|
+
except: pass
|
|
98
|
+
|
|
99
|
+
try: # legalValues
|
|
100
|
+
enum_strings = pvControl.metadata.enum_strings
|
|
101
|
+
props['legalValues'] = [i.decode() for i in enum_strings]
|
|
102
|
+
props['value'] = props['legalValues'][val]
|
|
103
|
+
except:
|
|
104
|
+
#props['legalValues'] = None
|
|
105
|
+
if 'legalValues' in props:
|
|
106
|
+
del props['legalValues']
|
|
107
|
+
#_printd(f'_props {props}')
|
|
108
|
+
_PVCache[pvName][_PVC_Props] = props
|
|
109
|
+
|
|
110
|
+
def info(devPar:tuple):
|
|
111
|
+
"""Abridged PV info"""
|
|
112
|
+
pvName = ''.join(devPar)
|
|
113
|
+
pv = _get_pv(devPar)
|
|
114
|
+
return {devPar:_PVCache[pvName][_PVC_Props]}
|
|
115
|
+
|
|
116
|
+
def get(devPar:tuple, *args, **kwargs):
|
|
117
|
+
'''Returns devPar-keyed map of PV properties: {'value','timestamp'...}'''
|
|
118
|
+
pvName = ''.join(devPar)
|
|
119
|
+
pv = _get_pv(devPar)
|
|
120
|
+
pvData = pv.read(data_type='time')
|
|
121
|
+
rDict = _unpack_ReadNotifyResponse(pvName, pvData)
|
|
122
|
+
return rDict
|
|
123
|
+
|
|
124
|
+
def set(devParValue:tuple):
|
|
125
|
+
'''Sets the PV value. The devParValue is (deviceName, ParameterName, value)
|
|
126
|
+
'''
|
|
127
|
+
dev, par, value = devParValue
|
|
128
|
+
#print(f'epicsAccess.set({dev,par,value})')
|
|
129
|
+
pvName = ''.join((dev,par))
|
|
130
|
+
pv = _get_pv((dev,par))
|
|
131
|
+
try: # if PV has legalValues then the value should be index of legalValues
|
|
132
|
+
value = _PVCache[pvName][_PVC_Props]['legalValues'].index(value)
|
|
133
|
+
except Exception as e:
|
|
134
|
+
#print(f'in epicsAccess.set. Value not in legalValues: {e}')
|
|
135
|
+
pass
|
|
136
|
+
pv.write(value)
|
|
137
|
+
return 1
|
|
138
|
+
|
|
139
|
+
def _unpack_ReadNotifyResponse(pvName:str, pvData):
|
|
140
|
+
val = pvData.data
|
|
141
|
+
if len(val) == 1:
|
|
142
|
+
try: #it as numpy
|
|
143
|
+
val = pvData.data[0].item()
|
|
144
|
+
except: # it is not numpy
|
|
145
|
+
val = pvData.data[0]
|
|
146
|
+
#_printd(f'pvData:{pvData}')
|
|
147
|
+
#_printd(f'val:{val}, {pvData.data_type}')
|
|
148
|
+
if pvData.data_type == _CA_data_type_STRING:
|
|
149
|
+
val = val.decode()
|
|
150
|
+
|
|
151
|
+
legalValues = _PVCache[pvName][_PVC_Props].get('legalValues')
|
|
152
|
+
if legalValues is not None:
|
|
153
|
+
#rDict['value'] = legalValues[int(val)]
|
|
154
|
+
val = legalValues[int(val)]
|
|
155
|
+
alarm = pvData.metadata.severity
|
|
156
|
+
key = _PVCache[pvName][_PVC_DevPar]
|
|
157
|
+
rDict = {key: {'value':val\
|
|
158
|
+
, 'timestamp':pvData.metadata.timestamp, 'alarm': alarm}}
|
|
159
|
+
return rDict
|
|
160
|
+
|
|
161
|
+
def _callback(subscription, pvData):
|
|
162
|
+
#tMark = [timer(), 0., 0.]
|
|
163
|
+
pvName = subscription.pv.name
|
|
164
|
+
_printd(f'>epicsAccess._callback: {pvName}')#{pvData})')
|
|
165
|
+
rDict = _unpack_ReadNotifyResponse(pvName, pvData)
|
|
166
|
+
#tMark[1] = timer()
|
|
167
|
+
cache = _PVCache.get(pvName)
|
|
168
|
+
cb = cache[_PVC_CB]
|
|
169
|
+
if cb:
|
|
170
|
+
cb(rDict)
|
|
171
|
+
#tMark[2] = timer() - tMark[1]
|
|
172
|
+
#tMark[1] -= tMark[0]
|
|
173
|
+
##_printd(f'caproto cb times {tMark}')# 20-30 uS
|
|
174
|
+
|
|
175
|
+
def subscribe(callback:callable, devPar:tuple):
|
|
176
|
+
'''Subscribe callback method to changes of PVs, defined by devPar'''
|
|
177
|
+
pvName = ''.join(devPar)
|
|
178
|
+
pv = _get_pv(devPar)
|
|
179
|
+
subscription = pv.subscribe(data_type='time')
|
|
180
|
+
_PVCache[pvName][_PVC_CB] = callback
|
|
181
|
+
subscription.add_callback(_callback)
|
|
182
|
+
_Subscriptions.append(subscription)
|
|
183
|
+
|
|
184
|
+
def unsubscribe():
|
|
185
|
+
'''Unsubscribe all subscriptions'''
|
|
186
|
+
global _Subscriptions
|
|
187
|
+
for subscription in _Subscriptions:
|
|
188
|
+
#print(f'>epicsAccess clear subs: {subscription}')
|
|
189
|
+
subscription.clear()
|
|
190
|
+
_Subscriptions = []
|
|
191
|
+
|
|
File without changes
|