pvplot 1.4.0__tar.gz → 1.5.0__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.
pvplot-1.5.0/PKG-INFO ADDED
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.4
2
+ Name: pvplot
3
+ Version: 1.5.0
4
+ Summary: Plotting tool for EPICS PVs, ADO and LITE parameters
5
+ Project-URL: Homepage, https://github.com/ASukhanov/pvplot
6
+ Project-URL: Bug Tracker, https://github.com/ASukhanov/pvplot/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.7
13
+ Requires-Dist: liteaccess
14
+ Description-Content-Type: text/markdown
15
+
16
+ # pvplot
17
+ Package for dynamic plotting of EPICS PVs (both CA and PVA) and [liteServer data objects](https://github.com/ASukhanov/liteServer).
18
+
19
+ ## Examples
20
+ - Sliced array plot of EPICS Channel Access [testAsynPortDriverApp](https://epics.anl.gov/modules/soft/asyn/R4-38/asynDriver.html#testAsynPortDriverApp):<br>
21
+ `python -m pvplot -s0.01 -a'E:testAPD:scope1:' 'Waveform_RBV[1:500]'`
22
+ - Waveform from EPICS PVaccess [simScope](https://github.com/ASukhanov/p4pex):<br>
23
+ `python -m pvplot P:simScope1:Waveform_RBV`
24
+ - Time-series plot (stripchart) of analog inputs of a LabJack U3-HV instrument, served by liteLabjack:<br>
25
+ `python -m pvplot -a'L:localhost:dev1' 'tempU3 ADC_HV[0] ADC_HV[1] ADC_HV[2] ADC_HV[3] ADC_LV'`
26
+ - Fast correlation plot of a litePeakSimulator<br>
27
+ `python -m pvplot -s.01 -a'L:localhost:dev1' 'x,y'`
28
+ - Multiple docks. For example, to plot two scrolling plots in lower dock and a
29
+ correlation plot in upper dock:<br>
30
+ `python -m pvplot -a'L:localhost:dev1:' -#0'yMax yMin' -#1'yMax,yMin'`
31
+ - To change properties of curves: right click on a plot and select 'DataSets Options'
pvplot-1.5.0/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # pvplot
2
+ Package for dynamic plotting of EPICS PVs (both CA and PVA) and [liteServer data objects](https://github.com/ASukhanov/liteServer).
3
+
4
+ ## Examples
5
+ - Sliced array plot of EPICS Channel Access [testAsynPortDriverApp](https://epics.anl.gov/modules/soft/asyn/R4-38/asynDriver.html#testAsynPortDriverApp):<br>
6
+ `python -m pvplot -s0.01 -a'E:testAPD:scope1:' 'Waveform_RBV[1:500]'`
7
+ - Waveform from EPICS PVaccess [simScope](https://github.com/ASukhanov/p4pex):<br>
8
+ `python -m pvplot P:simScope1:Waveform_RBV`
9
+ - Time-series plot (stripchart) of analog inputs of a LabJack U3-HV instrument, served by liteLabjack:<br>
10
+ `python -m pvplot -a'L:localhost:dev1' 'tempU3 ADC_HV[0] ADC_HV[1] ADC_HV[2] ADC_HV[3] ADC_LV'`
11
+ - Fast correlation plot of a litePeakSimulator<br>
12
+ `python -m pvplot -s.01 -a'L:localhost:dev1' 'x,y'`
13
+ - Multiple docks. For example, to plot two scrolling plots in lower dock and a
14
+ correlation plot in upper dock:<br>
15
+ `python -m pvplot -a'L:localhost:dev1:' -#0'yMax yMin' -#1'yMax,yMin'`
16
+ - To change properties of curves: right click on a plot and select 'DataSets Options'
@@ -6,7 +6,7 @@ The EPICS PV name is concatenation of the deviceName and parameterName
6
6
  For example: epics.get(('testAPD:scope1:','MaxValue_RBV')) returns
7
7
  {('testAPD:scope1:', 'MaxValue_RBV'): {'value': 1.5620877339306638, 'timestamp': 1681488886.923712, 'alarm': 0}}
8
8
  """
9
- __version__ = 'v0.0.2 2023-04-14'# No colon separation when splitting PV name to (device,parameter) tuple.
9
+ __version__ = 'v0.0.3 2023-04-14'# No colon separation when splitting PV name to (device,parameter) tuple.
10
10
 
11
11
  #from time import perf_counter as timer
12
12
 
@@ -32,12 +32,15 @@ def _printd(msg):
32
32
  def init():
33
33
  return
34
34
 
35
- def _get_pv(devPar:tuple):
36
- pvName = ''.join(devPar)
35
+ def _pvname(devPar:tuple):
36
+ return ':'.join(devPar)
37
+
38
+ def _get_pv(pvName):
37
39
  r = _PVCache.get(pvName)
38
40
  if r is None:
39
- _printd(f'register pv {pvName} {devPar}')
40
- pv,*_ = _Ctx.get_pvs(''.join(pvName), timeout=2)
41
+ #print(f'register pv {pvName}')
42
+ pv,*_ = _Ctx.get_pvs(pvName, timeout=2)
43
+ devPar = tuple(pvName.rsplit(':',1))
41
44
  _PVCache[pvName] = [pv, None, None, devPar]
42
45
  _fill_PVCacheProps(pv)
43
46
  else:
@@ -109,14 +112,15 @@ def _fill_PVCacheProps(pv):
109
112
 
110
113
  def info(devPar:tuple):
111
114
  """Abridged PV info"""
112
- pvName = ''.join(devPar)
113
- pv = _get_pv(devPar)
115
+ pvName = _pvname(devPar)
116
+ pv = _get_pv(pvName)
114
117
  return {devPar:_PVCache[pvName][_PVC_Props]}
115
118
 
116
119
  def get(devPar:tuple, *args, **kwargs):
117
120
  '''Returns devPar-keyed map of PV properties: {'value','timestamp'...}'''
118
- pvName = ''.join(devPar)
119
- pv = _get_pv(devPar)
121
+ pvName = _pvname(devPar)
122
+ #print(f'>get: {devPar, pvName}')
123
+ pv = _get_pv(pvName)
120
124
  pvData = pv.read(data_type='time')
121
125
  rDict = _unpack_ReadNotifyResponse(pvName, pvData)
122
126
  return rDict
@@ -126,8 +130,8 @@ def set(devParValue:tuple):
126
130
  '''
127
131
  dev, par, value = devParValue
128
132
  #print(f'epicsAccess.set({dev,par,value})')
129
- pvName = ''.join((dev,par))
130
- pv = _get_pv((dev,par))
133
+ pvName = _pvname((dev,par))
134
+ pv = _get_pv(pvName)
131
135
  try: # if PV has legalValues then the value should be index of legalValues
132
136
  value = _PVCache[pvName][_PVC_Props]['legalValues'].index(value)
133
137
  except Exception as e:
@@ -174,8 +178,8 @@ def _callback(subscription, pvData):
174
178
 
175
179
  def subscribe(callback:callable, devPar:tuple):
176
180
  '''Subscribe callback method to changes of PVs, defined by devPar'''
177
- pvName = ''.join(devPar)
178
- pv = _get_pv(devPar)
181
+ pvName = _pvname(devPar)
182
+ pv = _get_pv(pvName)
179
183
  subscription = pv.subscribe(data_type='time')
180
184
  _PVCache[pvName][_PVC_CB] = callback
181
185
  subscription.add_callback(_callback)
@@ -0,0 +1,154 @@
1
+ """Basic EPICS PVAccess API using p4p python wrapper.
2
+ The API is similar to cad_io.
3
+ The devPar argument is tuple (deviceName,parameterName).
4
+
5
+ For example: pvaccess.get(('simScope1','NoiseAmplitude')) returns:
6
+ {('simScope1', 'NoiseAmplitude'): {'value': 3.0, 'timestampSeconds': 1735615833, 'timestampNanoSeconds': 822335958}}
7
+
8
+ To set NoiseAmplitude to 1.:
9
+ pvaccess.set(('simScope1','NoiseAmplitude',1.))
10
+ """
11
+ __version__ = 'v0.1.2 2025-01-05'# _pvname()
12
+
13
+ import time
14
+ #from time import perf_counter as timer
15
+ from functools import partial
16
+ from p4p.client.thread import Context
17
+ from p4p.nt.enum import ntenum
18
+
19
+ _dbg = False
20
+ _Ctx = Context()# provides only PV values
21
+ _CtxRaw = Context(unwrap=False)# provides PV properties
22
+ _PVInfo = {}# cache of PVs
23
+ _Subscriptions = []# list of EPICS PV subscriptions
24
+
25
+ def _printd(msg):
26
+ if _dbg:
27
+ print(f'CPAccess:{msg}')
28
+ def printTime(): return time.strftime("%m%d:%H%M%S")
29
+ def printi(msg): print(f'inf_PVA@{printTime()}: {msg}')
30
+ def printw(msg): print(f'WAR_PVA@{printTime()}: {msg}')
31
+ def printe(msg): print(f'ERR_PVA@{printTime()}: {msg}')
32
+ def init():
33
+ return
34
+
35
+ def _pvname(devPar:tuple):
36
+ return ':'.join(devPar)
37
+
38
+ def info(devPar:tuple):
39
+ """Abridged PV info"""
40
+ pvName = _pvname(devPar)
41
+ v = _CtxRaw.get(pvName)
42
+ #print(f'v of {pvName}: {v.todict()}')
43
+ r = {devPar:{'value':v.value,
44
+ 'timestampSeconds': v.timeStamp.secondsPastEpoch,
45
+ 'timestampNanoSeconds': v.timeStamp.nanoseconds
46
+ }}
47
+
48
+ # With p4p it is impossible to detect if parameter is writable
49
+ r[devPar]['features'] = 'RWE'
50
+
51
+ try: r[devPar]['desc'] = v.display.description
52
+ except: pass
53
+ try: r[devPar]['units'] = v.display.units
54
+ except: pass
55
+ try:
56
+ if not (v.display.limitLow == v.display.limitHigh == 0.0):
57
+ r[devPar]['opLow'] = v.display.limitLow
58
+ r[devPar]['opHigh'] = v.display.limitHigh
59
+ except: pass
60
+ try: r[devPar]['units'] = v.display.units
61
+ except: pass
62
+ try:
63
+ r[devPar]['legalValues'] = v.value['choices']
64
+ r[devPar]['value'] = v.value['choices'][v.value['index']]
65
+ except: pass
66
+ _PVInfo[devPar] = r
67
+ #print(f'info of {pvName}: {r}')
68
+ return r
69
+
70
+ #``````````````````PVCache methods````````````````````````````````````````````
71
+ def _cachedInfo(devPar:tuple):
72
+ pvinfo = _PVInfo.get(devPar)
73
+ if pvinfo is None:
74
+ pvinfo = info(devPar)[devPar]
75
+ print(f'register pvinfo {devPar}: {pvinfo}')
76
+ _PVInfo[devPar] = pvinfo
77
+ return pvinfo
78
+
79
+ def get(devPar:tuple, *args, **kwargs):
80
+ """Returns devPar-keyed map of PV properties: {'value','timestamp'...}"""
81
+ pvName = _pvname(devPar)
82
+ v = _CtxRaw.get(pvName)
83
+ #print(f'got {pvName}: {v.todict()}')
84
+ try: value = v.value['choices'][v.value['index']]
85
+ except: value = v.value
86
+ try: #to interpret it as NTENum
87
+ idx = value.index
88
+ value = value.choices[idx]
89
+ except: pass
90
+ rDict = {devPar:{'value':value,
91
+ 'timestampSeconds': v.timeStamp.secondsPastEpoch,
92
+ 'timestampNanoSeconds': v.timeStamp.nanoseconds
93
+ }}
94
+ return rDict
95
+
96
+ def set(devParValue:tuple):
97
+ """Sets the PV value. The devParValue is (deviceName, ParameterName, value)
98
+ """
99
+ dev, par, value = devParValue
100
+ info = _cachedInfo((dev,par))
101
+ #print(f'>set({dev,par,type(value),value, info})')
102
+ try:
103
+ if value < info['opLow']:
104
+ printw(f'Value {value} is lower than opLow of {dev,par}')
105
+ return False
106
+ except: pass
107
+ try:
108
+ if value > info['opHigh']:
109
+ printw(f'Value {value} is higher than opHigh of {dev,par}')
110
+ return False
111
+ except: pass
112
+ try:
113
+ if value not in info['legalValues']:
114
+ printw(f'Value {value} is not in legalValues of {dev,par}')
115
+ return False
116
+ value = info['legalValues'][value]
117
+ except: pass
118
+ pvName = _pvname((dev,par))
119
+ try:
120
+ _Ctx.put(pvName, value)
121
+ except Exception as e:
122
+ printw(f'Set {dev, par, value}: {e}')
123
+ return False
124
+ return True
125
+
126
+ def _callback(callback, devPar, value):
127
+ vr = value.raw
128
+ #print(f'>_callback: {devPar}, {vr}')#{pvData})')
129
+ if isinstance(value, ntenum):
130
+ d = vr.value.todict()
131
+ v = d['choices'][d['index']]
132
+ else:
133
+ v = vr.value
134
+ r = {devPar:{'value':v,
135
+ 'timestampSeconds':vr.timeStamp.secondsPastEpoch,
136
+ 'timestampNanoSeconds':vr.timeStamp.nanoseconds,
137
+ }}
138
+ #print(f'cb {devPar,r}')
139
+ callback(r)
140
+
141
+ def subscribe(callback:callable, devPar:tuple):
142
+ """Subscribe callback method to changes of PVs, defined by devPar"""
143
+ pvName = _pvname(devPar)
144
+ subscription = _Ctx.monitor(pvName, partial(_callback, callback, devPar))
145
+ _Subscriptions.append((subscription,callback))
146
+
147
+ def unsubscribe():
148
+ """Unsubscribe all subscriptions"""
149
+ global _Subscriptions
150
+ for subs,cb in _Subscriptions:
151
+ #print(f'>pvaccess close subs: {subs}')
152
+ subs.close()
153
+ _Subscriptions = []
154
+
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python3
2
- """Plotting package for EPICS PVs, ADO and LITE parameters.
2
+ """Plotting package for EPICS PVs (CA and PVA), LITE and ADO parameters.
3
3
  """
4
- __version__ = 'v1.4.0 2024-11-12'# fixed: changing dataOptions when plot is stopped
4
+ __version__ = 'v1.5.0 2024-12-31'# added EPICS PVAccess support using p4p
5
5
  #TODO: if backend times out the gui is not responsive
6
6
  #TODO: move Add Dataset to Dataset options
7
7
  #TODO: add dataset arithmetics
@@ -67,6 +67,10 @@ try: from . import cad_epics as EPICSAccess
67
67
  except Exception as e:
68
68
  EPICSAccess = None
69
69
  printw(f'EPICS devices are not supported on this host: {e}')
70
+ try: from . import cad_pvaccess as PVAccess
71
+ except Exception as e:
72
+ PVAccess = None
73
+ printw(f'EPICS PVA devices are not supported on this host: {e}')
70
74
  try:
71
75
  import liteaccess as liteAccess
72
76
  LITEAccess = liteAccess.Access
@@ -82,7 +86,7 @@ except Exception as e:
82
86
  ADOAccess = None
83
87
 
84
88
  def get_pv(adopar:str, prop='value'):
85
- #print(f'>get_pv {adopar}')
89
+ #print(f'>pvp get_pv {adopar}')
86
90
  adopar, vslice = split_slice(adopar)
87
91
  try:
88
92
  access = PVPlot.access[adopar[:2]]
@@ -105,7 +109,7 @@ def get_pv(adopar:str, prop='value'):
105
109
  pass
106
110
  try:
107
111
  ts = rd['timestamp']# EPICS and LITE
108
- except: # ADO
112
+ except: # ADO & PVA
109
113
  ts = rd['timestampSeconds'] + rd['timestampNanoSeconds']*1.e-9
110
114
 
111
115
  #printv(f"get_pv {adopar}: {rd['value']} {vslice}")
@@ -586,7 +590,7 @@ class MapOfDatasets():
586
590
 
587
591
  def add(dockNum:int, mapOfCurves):
588
592
  """add new datasets, the adoPars is the space delimited string of
589
- source ado:parameters."""
593
+ source device:parameters."""
590
594
  printv(f'>MapOfDatasets.add({dockNum, mapOfCurves})')
591
595
  for i, kv in enumerate(mapOfCurves.items()):
592
596
  curveName,devList = kv
@@ -599,7 +603,7 @@ class MapOfDatasets():
599
603
  pnameAndCount = []
600
604
  for adoPar in devList:
601
605
  adoPar = adoPar.lstrip()#remove leading whitespaces
602
- printv(f'adoPar: {adoPar}')
606
+ #print(f'adoPar: {adoPar}')
603
607
  if adoPar.startswith('device('):
604
608
  e = adoPar.index(')')
605
609
  rest = adoPar[e+1:]# it could be arithmetics
@@ -1027,7 +1031,7 @@ class PVPlot():
1027
1031
  subscribedParMap = {}
1028
1032
  perfmon = False # option for performance monitoring
1029
1033
  legend = {}# unfortunately we have to keep track of legends
1030
- access = {'E:':EPICSAccess, 'L:':LITEAccess}
1034
+ access = {'E:':EPICSAccess, 'L:':LITEAccess, 'P:':PVAccess}
1031
1035
  qWin = None
1032
1036
  qTimer = QtCore.QTimer()
1033
1037
  dockArea = None
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "pvplot"
7
- version = "1.4.0"
7
+ version = "1.5.0"
8
8
  authors = [
9
9
  { name="Andrei Sukhanov", email="cyxandr@gmail.com" },
10
10
  ]
pvplot-1.4.0/PKG-INFO DELETED
@@ -1,26 +0,0 @@
1
- Metadata-Version: 2.3
2
- Name: pvplot
3
- Version: 1.4.0
4
- Summary: Plotting tool for EPICS PVs, ADO and LITE parameters
5
- Project-URL: Homepage, https://github.com/ASukhanov/pvplot
6
- Project-URL: Bug Tracker, https://github.com/ASukhanov/pvplot/issues
7
- Author-email: Andrei Sukhanov <cyxandr@gmail.com>
8
- Classifier: License :: OSI Approved :: MIT License
9
- Classifier: Operating System :: OS Independent
10
- Classifier: Programming Language :: Python :: 3
11
- Requires-Python: >=3.7
12
- Requires-Dist: liteaccess
13
- Description-Content-Type: text/markdown
14
-
15
- # pvplot
16
- Package for dynamic plotting of EPICS PVs and [liteServer data objects](https://github.com/ASukhanov/liteServer).
17
-
18
- ## Examples
19
- - Sliced array plot of an EPICS PV: ```pvplot -s0.01 -a'E:testAPD:scope1:' 'Waveform_RBV[1:500]'```
20
- - Time-series plot (stripchart) of analog inputs of a LabJack U3-HV instrument, served by liteLabjack:<br>
21
- ```pvplot -a'L:localhost:dev1' 'tempU3 ADC_HV[0] ADC_HV[1] ADC_HV[2] ADC_HV[3] ADC_LV'```
22
- - Fast correlation plot of a litePeakSimulator ```pvplot -s.01 -a'L:localhost:dev1' 'x,y'```
23
- - Multiple docks. For example, to plot two scrolling plots in lower dock and a
24
- correlation plot in upper dock:
25
- ```pvplot -a'L:localhost:dev1:' -#0'yMax yMin' -#1'yMax,yMin'```
26
- - To change properties of curves: right click on a plot and select 'DataSets Options'
pvplot-1.4.0/README.md DELETED
@@ -1,12 +0,0 @@
1
- # pvplot
2
- Package for dynamic plotting of EPICS PVs and [liteServer data objects](https://github.com/ASukhanov/liteServer).
3
-
4
- ## Examples
5
- - Sliced array plot of an EPICS PV: ```pvplot -s0.01 -a'E:testAPD:scope1:' 'Waveform_RBV[1:500]'```
6
- - Time-series plot (stripchart) of analog inputs of a LabJack U3-HV instrument, served by liteLabjack:<br>
7
- ```pvplot -a'L:localhost:dev1' 'tempU3 ADC_HV[0] ADC_HV[1] ADC_HV[2] ADC_HV[3] ADC_LV'```
8
- - Fast correlation plot of a litePeakSimulator ```pvplot -s.01 -a'L:localhost:dev1' 'x,y'```
9
- - Multiple docks. For example, to plot two scrolling plots in lower dock and a
10
- correlation plot in upper dock:
11
- ```pvplot -a'L:localhost:dev1:' -#0'yMax yMin' -#1'yMax,yMin'```
12
- - To change properties of curves: right click on a plot and select 'DataSets Options'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes