epicsdev 2.1.0__py3-none-any.whl → 2.1.1__py3-none-any.whl
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.
- epicsdev/epicsdev.py +23 -26
- epicsdev/multiadc.py +48 -35
- {epicsdev-2.1.0.dist-info → epicsdev-2.1.1.dist-info}/METADATA +5 -5
- epicsdev-2.1.1.dist-info/RECORD +7 -0
- epicsdev-2.1.0.dist-info/RECORD +0 -7
- {epicsdev-2.1.0.dist-info → epicsdev-2.1.1.dist-info}/WHEEL +0 -0
- {epicsdev-2.1.0.dist-info → epicsdev-2.1.1.dist-info}/licenses/LICENSE +0 -0
epicsdev/epicsdev.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"""Skeleton and helper functions for creating EPICS PVAccess server"""
|
|
2
2
|
# pylint: disable=invalid-name
|
|
3
|
-
__version__= 'v2.1.
|
|
4
|
-
#TODO add mandatory PV: host, to identify the server host.
|
|
3
|
+
__version__= 'v2.1.1 26-02-05'# sleep() returns False if a periodic update occurred. Simplified waveform randomization.
|
|
5
4
|
#Issue: There is no way in PVAccess to specify if string PV is writable.
|
|
6
5
|
# As a workaround we append description with suffix ' Features: W' to indicate that.
|
|
7
6
|
|
|
@@ -31,7 +30,7 @@ class C_():
|
|
|
31
30
|
PVs = {}
|
|
32
31
|
PVDefs = []
|
|
33
32
|
serverStateChanged = _serverStateChanged
|
|
34
|
-
lastCycleTime =
|
|
33
|
+
lastCycleTime = timer()
|
|
35
34
|
lastUpdateTime = 0.
|
|
36
35
|
cycleTimeSum = 0.
|
|
37
36
|
cyclesAfterUpdate = 0
|
|
@@ -332,13 +331,17 @@ def init_epicsdev(prefix:str, pvDefs:list, verbose=0,
|
|
|
332
331
|
|
|
333
332
|
def sleep():
|
|
334
333
|
"""Sleep function to be called in the main loop. It updates cycleTime PV
|
|
335
|
-
and sleeps for the time specified in sleep PV.
|
|
336
|
-
|
|
334
|
+
and sleeps for the time specified in sleep PV.
|
|
335
|
+
Returns False if a periodic update occurred.
|
|
336
|
+
"""
|
|
337
|
+
time.sleep(pvv('sleep'))
|
|
338
|
+
tnow = timer()
|
|
337
339
|
C_.cycleTimeSum += tnow - C_.lastCycleTime
|
|
338
340
|
C_.lastCycleTime = tnow
|
|
339
341
|
C_.cyclesAfterUpdate += 1
|
|
340
342
|
C_.cycle += 1
|
|
341
343
|
printv(f'cycle {C_.cycle}')
|
|
344
|
+
sleeping = True
|
|
342
345
|
if tnow - C_.lastUpdateTime > PeriodicUpdateInterval:
|
|
343
346
|
avgCycleTime = C_.cycleTimeSum / C_.cyclesAfterUpdate
|
|
344
347
|
printv(f'Average cycle time: {avgCycleTime:.6f} S.')
|
|
@@ -347,7 +350,8 @@ def sleep():
|
|
|
347
350
|
C_.lastUpdateTime = tnow
|
|
348
351
|
C_.cycleTimeSum = 0.
|
|
349
352
|
C_.cyclesAfterUpdate = 0
|
|
350
|
-
|
|
353
|
+
sleeping = False
|
|
354
|
+
return sleeping
|
|
351
355
|
|
|
352
356
|
#``````````````````Demo````````````````````````````````````````````````````````
|
|
353
357
|
if __name__ == "__main__":
|
|
@@ -359,20 +363,20 @@ if __name__ == "__main__":
|
|
|
359
363
|
SET,U,LL,LH = 'setter','units','limitLow','limitHigh'
|
|
360
364
|
alarm = {'valueAlarm':{'lowAlarmLimit':-9., 'highAlarmLimit':9.}}
|
|
361
365
|
return [ # device-specific PVs
|
|
362
|
-
['noiseLevel', 'Noise amplitude', SPV(1
|
|
366
|
+
['noiseLevel', 'Noise amplitude', SPV(1.,'W'), {U:'V'}],
|
|
363
367
|
['tAxis', 'Full scale of horizontal axis', SPV([0.]), {U:'S'}],
|
|
364
368
|
['recordLength','Max number of points', SPV(100,'W','u32'),
|
|
365
369
|
{LL:4,LH:1000000, SET:set_recordLength}],
|
|
370
|
+
['throughput', 'Performance metrics, points per second', SPV(0.), {U:'Mpts/s'}],
|
|
366
371
|
['c01Offset', 'Offset', SPV(0.,'W'), {U:'du'}],
|
|
367
|
-
['c01VoltsPerDiv', 'Vertical scale', SPV(
|
|
372
|
+
['c01VoltsPerDiv', 'Vertical scale', SPV(0.1,'W'), {U:'V/du'}],
|
|
368
373
|
['c01Waveform', 'Waveform array', SPV([0.]), {U:'du'}],
|
|
369
374
|
['c01Mean', 'Mean of the waveform', SPV(0.,'A'), {U:'du'}],
|
|
370
375
|
['c01Peak2Peak','Peak-to-peak amplitude', SPV(0.,'A'), {U:'du',**alarm}],
|
|
371
376
|
['alarm', 'PV with alarm', SPV(0,'WA'), {U:'du',**alarm}],
|
|
372
377
|
]
|
|
373
|
-
nPatterns = 100 # number of waveform patterns.
|
|
374
378
|
pargs = None
|
|
375
|
-
rng = np.random.default_rng(
|
|
379
|
+
rng = np.random.default_rng()
|
|
376
380
|
nPoints = 100
|
|
377
381
|
|
|
378
382
|
def set_recordLength(value, *_):
|
|
@@ -381,18 +385,6 @@ if __name__ == "__main__":
|
|
|
381
385
|
printi(f'Setting tAxis to {value}')
|
|
382
386
|
publish('tAxis', np.arange(value)*1.E-6)
|
|
383
387
|
publish('recordLength', value)
|
|
384
|
-
# Re-initialize noise array, because its size depends on recordLength
|
|
385
|
-
set_noise(pvv('noiseLevel'))
|
|
386
|
-
|
|
387
|
-
def set_noise(level, *_):
|
|
388
|
-
"""Noise level have changed. Update noise array."""
|
|
389
|
-
v = float(level)
|
|
390
|
-
recordLength = pvv('recordLength')
|
|
391
|
-
ts = timer()
|
|
392
|
-
pargs.noise = np.random.normal(scale=0.5*level,
|
|
393
|
-
size=recordLength+nPatterns)# 45ms/1e6 points
|
|
394
|
-
printi(f'Noise array[{len(pargs.noise)}] updated with level {v:.4g} V. in {timer()-ts:.4g} S.')
|
|
395
|
-
publish('noiseLevel', level)
|
|
396
388
|
|
|
397
389
|
def init(recordLength):
|
|
398
390
|
"""Example of device initialization function"""
|
|
@@ -401,14 +393,15 @@ if __name__ == "__main__":
|
|
|
401
393
|
|
|
402
394
|
def poll():
|
|
403
395
|
"""Example of polling function. Called every cycle when server is running."""
|
|
404
|
-
#
|
|
405
|
-
|
|
406
|
-
wf = pargs.noise[pattern:pattern+pvv('recordLength')].copy()
|
|
396
|
+
#ts = timer()
|
|
397
|
+
wf = rng.random(pvv('recordLength'))*pvv('noiseLevel')# it takes 5ms for 1M points
|
|
407
398
|
wf /= pvv('c01VoltsPerDiv')
|
|
408
399
|
wf += pvv('c01Offset')
|
|
400
|
+
#print(f'Waveform updated in {timer()-ts:.6g} S.')
|
|
409
401
|
publish('c01Waveform', wf)
|
|
410
402
|
publish('c01Peak2Peak', np.ptp(wf))
|
|
411
403
|
publish('c01Mean', np.mean(wf))
|
|
404
|
+
#print(f'Polling completed in {timer()-ts:.6g} S.')
|
|
412
405
|
|
|
413
406
|
# Argument parsing
|
|
414
407
|
parser = argparse.ArgumentParser(description = __doc__,
|
|
@@ -449,5 +442,9 @@ if __name__ == "__main__":
|
|
|
449
442
|
break
|
|
450
443
|
if not state.startswith('Stop'):
|
|
451
444
|
poll()
|
|
452
|
-
sleep()
|
|
445
|
+
if not sleep():# Sleep and update performance metrics periodically
|
|
446
|
+
if not state.startswith('Stop'):
|
|
447
|
+
pointsPerSecond = len(pvv('c01Waveform'))/(pvv('cycleTime')-pvv('sleep'))/1.E6
|
|
448
|
+
publish('throughput', round(pointsPerSecond,6))
|
|
449
|
+
printv(f'periodic update. Performance: {pointsPerSecond:.3g} Mpts/s')
|
|
453
450
|
printi('Server is exited')
|
epicsdev/multiadc.py
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"""Simulated multi-channel ADC device server using epicsdev module."""
|
|
2
2
|
# pylint: disable=invalid-name
|
|
3
|
-
__version__= 'v2.1.
|
|
3
|
+
__version__= 'v2.1.1 26-02-04'# added timing, throughput and c0$VoltOffset PVs
|
|
4
4
|
|
|
5
5
|
import sys
|
|
6
|
-
import time
|
|
7
6
|
from time import perf_counter as timer
|
|
8
|
-
import numpy as np
|
|
9
7
|
import argparse
|
|
8
|
+
import numpy as np
|
|
10
9
|
|
|
11
10
|
from .epicsdev import Server, Context, init_epicsdev, serverState, publish
|
|
12
11
|
from .epicsdev import pvv, printi, printv, SPV, set_server, sleep
|
|
@@ -20,17 +19,20 @@ def myPVDefs():
|
|
|
20
19
|
['channels', 'Number of device channels', SPV(pargs.channels), {}],
|
|
21
20
|
['externalControl', 'Name of external PV, which controls the server',
|
|
22
21
|
SPV('Start Stop Clear Exit Started Stopped Exited'.split(), 'WD'), {}],
|
|
23
|
-
['noiseLevel', 'Noise amplitude', SPV(
|
|
22
|
+
['noiseLevel', 'Noise amplitude', SPV(0.05,'W'), {U:'V'}],
|
|
24
23
|
['tAxis', 'Full scale of horizontal axis', SPV([0.]), {U:'S'}],
|
|
25
24
|
['recordLength','Max number of points', SPV(100,'W','u32'),
|
|
26
25
|
{LL:4,LH:1000000, SET:set_recordLength}],
|
|
27
26
|
['alarm', 'PV with alarm', SPV(0,'WA'), {U:'du',**alarm}],
|
|
27
|
+
#``````````````````Auxiliary PVs
|
|
28
|
+
['timing', 'Elapsed time for waveform generation, publishing, total]', SPV([0.]), {U:'S'}],
|
|
29
|
+
['throughput', 'Total number of points processed per second', SPV(0.), {U:'Mpts/s'}],
|
|
28
30
|
]
|
|
29
31
|
|
|
30
32
|
# Templates for channel-related PVs. Important: SPV cannot be used in this list!
|
|
31
33
|
ChannelTemplates = [
|
|
32
|
-
['c0$VoltsPerDiv', 'Vertical scale', (
|
|
33
|
-
|
|
34
|
+
['c0$VoltsPerDiv', 'Vertical scale', (0.1,'W'), {U:'V/du'}],
|
|
35
|
+
['c0$VoltOffset', 'Vertical offset', (0.,'W'), {U:'V'}],
|
|
34
36
|
['c0$Waveform', 'Waveform array', ([0.],), {U:'du'}],
|
|
35
37
|
['c0$Mean', 'Mean of the waveform', (0.,'A'), {U:'du'}],
|
|
36
38
|
['c0$Peak2Peak','Peak-to-peak amplitude', (0.,'A'), {U:'du',**alarm}],
|
|
@@ -44,9 +46,11 @@ def myPVDefs():
|
|
|
44
46
|
pvDefs.append(newpvdef)
|
|
45
47
|
return pvDefs
|
|
46
48
|
|
|
47
|
-
#``````````````````Module
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
#``````````````````Module attributes
|
|
50
|
+
rng = np.random.default_rng()
|
|
51
|
+
ElapsedTime = {'waveform': 0., 'publish': 0., 'poll': 0.}
|
|
52
|
+
class C_():
|
|
53
|
+
cyclesSinceUpdate = 0
|
|
50
54
|
|
|
51
55
|
#``````````````````Setter functions for PVs```````````````````````````````````
|
|
52
56
|
def set_recordLength(value, *_):
|
|
@@ -54,18 +58,6 @@ def set_recordLength(value, *_):
|
|
|
54
58
|
printi(f'Setting tAxis to {value}')
|
|
55
59
|
publish('tAxis', np.arange(value)*1.E-6)
|
|
56
60
|
publish('recordLength', value)
|
|
57
|
-
# Re-initialize noise array, because its size depends on recordLength
|
|
58
|
-
set_noise(pvv('noiseLevel'))
|
|
59
|
-
|
|
60
|
-
def set_noise(level, *_):
|
|
61
|
-
"""Noise level have changed. Update noise array."""
|
|
62
|
-
v = float(level)
|
|
63
|
-
recordLength = pvv('recordLength')
|
|
64
|
-
ts = timer()
|
|
65
|
-
|
|
66
|
-
pargs.noise = np.random.normal(scale=0.5*level, size=recordLength+nPatterns)# 45ms/1e6 points
|
|
67
|
-
printi(f'Noise array[{len(pargs.noise)}] updated with level {v:.4g} V. in {timer()-ts:.4g} S.')
|
|
68
|
-
publish('noiseLevel', level)
|
|
69
61
|
|
|
70
62
|
def set_externalControl(value, *_):
|
|
71
63
|
"""External control PV have changed. Control the server accordingly."""
|
|
@@ -94,21 +86,43 @@ def serverStateChanged(newState:str):
|
|
|
94
86
|
def init(recordLength):
|
|
95
87
|
"""Device initialization function"""
|
|
96
88
|
set_recordLength(recordLength)
|
|
89
|
+
# Set offset of each channel = channel index
|
|
90
|
+
for ch in range(pargs.channels):
|
|
91
|
+
publish(f'c{ch+1:02}VoltOffset', ch)
|
|
97
92
|
#set_externalControl(pargs.prefix + pargs.external)
|
|
93
|
+
publish('sleep', pargs.sleep)
|
|
98
94
|
|
|
99
95
|
def poll():
|
|
100
96
|
"""Device polling function, called every cycle when server is running"""
|
|
97
|
+
C_.cyclesSinceUpdate += 1
|
|
98
|
+
ts0 = timer()
|
|
101
99
|
for ch in range(pargs.channels):
|
|
102
|
-
|
|
100
|
+
ts1 = timer()
|
|
103
101
|
chstr = f'c{ch+1:02}'
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
publish(f'{chstr}Waveform',
|
|
102
|
+
rwf = rng.random(pvv('recordLength'))*pvv('noiseLevel')
|
|
103
|
+
wf = rwf/pvv(f'{chstr}VoltsPerDiv') + pvv(f'{chstr}VoltOffset')# the time is comparable with rng.random
|
|
104
|
+
ts2 = timer()
|
|
105
|
+
ElapsedTime['waveform'] += ts2 - ts1
|
|
106
|
+
#print(f'ElapsedTime: {C_.cyclesSinceUpdate, ElapsedTime["waveform"]}')
|
|
107
|
+
publish(f'{chstr}Waveform', wf)
|
|
110
108
|
publish(f'{chstr}Peak2Peak', np.ptp(wf))
|
|
111
109
|
publish(f'{chstr}Mean', np.mean(wf))
|
|
110
|
+
ElapsedTime['publish'] += timer() - ts2
|
|
111
|
+
ElapsedTime['poll'] += timer() - ts0
|
|
112
|
+
|
|
113
|
+
def periodic_update():
|
|
114
|
+
"""Perform periodic update"""
|
|
115
|
+
#printi(f'periodic update for {C_.cyclesSinceUpdate} cycles: {ElapsedTime}')
|
|
116
|
+
times = [(round(i/C_.cyclesSinceUpdate,6)) for i in ElapsedTime.values()]
|
|
117
|
+
publish('timing', times)
|
|
118
|
+
C_.cyclesSinceUpdate = 0
|
|
119
|
+
for key in ElapsedTime:
|
|
120
|
+
ElapsedTime[key] = 0.
|
|
121
|
+
pointsPerSecond = len(pvv('tAxis'))/(pvv('cycleTime')-pvv('sleep'))/1.E6
|
|
122
|
+
pointsPerSecond *= pvv('channels')
|
|
123
|
+
publish('throughput', round(pointsPerSecond,6))
|
|
124
|
+
printv(f'periodic update. Performance: {pointsPerSecond:.3g} Mpts/s')
|
|
125
|
+
|
|
112
126
|
|
|
113
127
|
# Argument parsing
|
|
114
128
|
parser = argparse.ArgumentParser(description = __doc__,
|
|
@@ -127,6 +141,8 @@ parser.add_argument('-i', '--index', default='0', help=
|
|
|
127
141
|
# The rest of arguments are not essential, they can be changed at runtime using PVs.
|
|
128
142
|
parser.add_argument('-n', '--npoints', type=int, default=100, help=
|
|
129
143
|
'Number of points in the waveform')
|
|
144
|
+
parser.add_argument('-s', '--sleep', type=float, default=1.0, help=
|
|
145
|
+
'Sleep time per cycle')
|
|
130
146
|
parser.add_argument('-v', '--verbose', action='count', default=0, help=
|
|
131
147
|
'Show more log messages (-vv: show even more)')
|
|
132
148
|
pargs = parser.parse_args()
|
|
@@ -136,10 +152,6 @@ print(f'pargs: {pargs}')
|
|
|
136
152
|
pargs.prefix = f'{pargs.device}{pargs.index}:'
|
|
137
153
|
PVs = init_epicsdev(pargs.prefix, myPVDefs(), pargs.verbose,
|
|
138
154
|
serverStateChanged, pargs.list)
|
|
139
|
-
# if pargs.list != '':
|
|
140
|
-
# print('List of PVs:')
|
|
141
|
-
# for _pvname in PVs:
|
|
142
|
-
# print(_pvname)
|
|
143
155
|
|
|
144
156
|
# Initialize the device, using pargs if needed.
|
|
145
157
|
# That can be used to set the number of points in the waveform, for example.
|
|
@@ -150,12 +162,13 @@ set_server('Start')
|
|
|
150
162
|
|
|
151
163
|
#``````````````````Main loop``````````````````````````````````````````````````
|
|
152
164
|
server = Server(providers=[PVs])
|
|
153
|
-
printi(f'Server started. Sleeping per cycle: {
|
|
165
|
+
printi(f'Server started. Sleeping per cycle: {float(pvv("sleep")):.3f} S.')
|
|
154
166
|
while True:
|
|
155
167
|
state = serverState()
|
|
156
168
|
if state.startswith('Exit'):
|
|
157
169
|
break
|
|
158
170
|
if not state.startswith('Stop'):
|
|
159
171
|
poll()
|
|
160
|
-
sleep()
|
|
161
|
-
|
|
172
|
+
if not sleep():
|
|
173
|
+
periodic_update()
|
|
174
|
+
printi('Server has exited')
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: epicsdev
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.1
|
|
4
4
|
Summary: Helper module for creating EPICS PVAccess servers using p4p
|
|
5
5
|
Project-URL: Homepage, https://github.com/ASukhanov/epicsdev
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/ASukhanov/epicsdev
|
|
@@ -30,10 +30,10 @@ python -m pypeto -c config -f epicsdev
|
|
|
30
30
|
|
|
31
31
|
## Multi-channel waveform generator
|
|
32
32
|
Module **epicdev.multiadc** can generate large amount of data for stress-testing
|
|
33
|
-
the EPICS environment. For example the following command will generate
|
|
34
|
-
|
|
33
|
+
the EPICS environment. For example the following command will generate 10000 of
|
|
34
|
+
100-pont noisy waveforms and 40000 of scalar parameters per second.
|
|
35
35
|
```
|
|
36
|
-
python -m epicsdev.multiadc -
|
|
36
|
+
python -m epicsdev.multiadc -s0.1 -c10000 -n100
|
|
37
37
|
```
|
|
38
38
|
The GUI for monitoring:<br>
|
|
39
39
|
```python -m pypeto -c config -f multiadc```
|
|
@@ -42,4 +42,4 @@ The graphs should look like this:
|
|
|
42
42
|
[control page](docs/epicsdev_pypet.png),
|
|
43
43
|
[plots](docs/epicsdev_pvplot.jpg).
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
Example of [Phoebus display](docs/phoebus_epicsdev.jpg), as defined in config/epicsdev.bob.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
epicsdev/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
epicsdev/epicsdev.py,sha256=dVPuuQ0xXF8ibw28DpvxQfkG_9k7WubNp_9rWXRvTVw,17970
|
|
3
|
+
epicsdev/multiadc.py,sha256=2sg_VmIfylG5XHJzx5bgi_Bb9VPiX2TtyI-8JuAiBmQ,7219
|
|
4
|
+
epicsdev-2.1.1.dist-info/METADATA,sha256=2tMnntNmRcksDUO0fAH9PCrmICCWS4ad7GRcGwnnAtc,1382
|
|
5
|
+
epicsdev-2.1.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
6
|
+
epicsdev-2.1.1.dist-info/licenses/LICENSE,sha256=qj3cUKUrX4oXTb0NwuJQ44ThYDEMUfOeIjw9kkT6Qck,1072
|
|
7
|
+
epicsdev-2.1.1.dist-info/RECORD,,
|
epicsdev-2.1.0.dist-info/RECORD
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
epicsdev/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
epicsdev/epicsdev.py,sha256=aOiVWY8sIrEGqxHJ9niyRtGl3z2Qg0ep5MFbnZskWxg,18017
|
|
3
|
-
epicsdev/multiadc.py,sha256=ZVsA1wzl4GfOepC_zQdjisNKQFcpJuEMV6vt1y3zBnw,6520
|
|
4
|
-
epicsdev-2.1.0.dist-info/METADATA,sha256=8bFFHdc7SnDooPlzHZsnzYAy9QnpqkYoZX7VGmVtfrE,1270
|
|
5
|
-
epicsdev-2.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
6
|
-
epicsdev-2.1.0.dist-info/licenses/LICENSE,sha256=qj3cUKUrX4oXTb0NwuJQ44ThYDEMUfOeIjw9kkT6Qck,1072
|
|
7
|
-
epicsdev-2.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|