epicsdev 3.2.2__tar.gz → 3.3.1__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.
Files changed (37) hide show
  1. epicsdev-3.3.1/LICENSE +28 -0
  2. epicsdev-3.3.1/PKG-INFO +58 -0
  3. epicsdev-3.3.1/README.md +43 -0
  4. epicsdev-3.2.2/fallback/multiadc_pp.py → epicsdev-3.3.1/config/epicsdev_pp.py +28 -41
  5. epicsdev-3.2.2/config/epicsdev_pp.py → epicsdev-3.3.1/config/multiadc_pp.py +27 -32
  6. {epicsdev-3.2.2 → epicsdev-3.3.1}/epicsdev/epicsdev.py +20 -17
  7. epicsdev-3.3.1/epicsdev/multiadc.py +152 -0
  8. {epicsdev-3.2.2/new → epicsdev-3.3.1}/pyproject.toml +6 -7
  9. epicsdev-3.2.2/.github/copilot-instructions.md +0 -24
  10. epicsdev-3.2.2/LICENSE +0 -21
  11. epicsdev-3.2.2/PKG-INFO +0 -267
  12. epicsdev-3.2.2/config/epicsSimscope_pp.py +0 -112
  13. epicsdev-3.2.2/config/epicsdev.bob +0 -267
  14. epicsdev-3.2.2/docs/epicsdev_pvplot.jpg +0 -0
  15. epicsdev-3.2.2/docs/epicsdev_pypet.png +0 -0
  16. epicsdev-3.2.2/docs/imagegen.jpg +0 -0
  17. epicsdev-3.2.2/docs/modules.md +0 -57
  18. epicsdev-3.2.2/docs/phoebus_epicsdev.jpg +0 -0
  19. epicsdev-3.2.2/docs/using_imagegen.md +0 -50
  20. epicsdev-3.2.2/examples/ai_imagegen.py +0 -205
  21. epicsdev-3.2.2/examples/ndarray_server.py +0 -27
  22. epicsdev-3.2.2/examples/ntndarray_server.py +0 -19
  23. epicsdev-3.2.2/examples/process_external_waveform.py +0 -21
  24. epicsdev-3.2.2/fallback/epicsdev-300.py +0 -498
  25. epicsdev-3.2.2/fallback/multiadc-v311.py +0 -183
  26. epicsdev-3.2.2/fallback/multiadc.py +0 -151
  27. epicsdev-3.2.2/fallback/multiadc1_pp.py +0 -6
  28. epicsdev-3.2.2/new/README.md +0 -133
  29. epicsdev-3.2.2/new/epicsdev.py +0 -638
  30. epicsdev-3.2.2/new/multiadc.py +0 -183
  31. epicsdev-3.2.2/prompts/image_initial +0 -12
  32. epicsdev-3.2.2/prompts/prompt_epics_development_with_python +0 -9
  33. epicsdev-3.2.2/pyproject.toml +0 -25
  34. {epicsdev-3.2.2 → epicsdev-3.3.1/epicsdev}/README.md +0 -0
  35. {epicsdev-3.2.2 → epicsdev-3.3.1}/epicsdev/__init__.py +0 -0
  36. {epicsdev-3.2.2 → epicsdev-3.3.1}/epicsdev/imagegen.py +0 -0
  37. {epicsdev-3.2.2 → epicsdev-3.3.1}/epicsdev/putlog.py +0 -0
epicsdev-3.3.1/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Electron-Ion Collider
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,58 @@
1
+ Metadata-Version: 2.5
2
+ Name: epicsdev
3
+ Version: 3.3.1
4
+ Summary: Helper module for creating EPICS PVAccess servers using p4p
5
+ Project-URL: Homepage, https://github.com/eicorg/epicsdev
6
+ Project-URL: Bug Tracker, https://github.com/eicorg/epicsdev
7
+ Author-email: Andrey Sukhanov <sukhanov@bnl.gov>
8
+ License-File: LICENSE
9
+ Classifier: License :: OSI Approved :: BSD License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.10
13
+ Requires-Dist: p4p>=4.2.2
14
+ Description-Content-Type: text/markdown
15
+
16
+ # epicsdev
17
+ Python framework that dramatically reduces the effort required
18
+ to create EPICS PVAccess servers using p4p library.
19
+ Device PVs are described  as a compact list of
20
+ `[name, description, initial_value, attributes]` tuples. 
21
+
22
+ The framework handles server creation, periodic updates, autosave/restore, 
23
+ IocStats heartbeat, and PV-put logging automatically.
24
+
25
+ Because all device logic lives in a small, well-structured Python file with a 
26
+ predictable pattern, large-language-model (LLM) assistants such as GitHub 
27
+ Copilot can replicate that pattern for any new instruments given only a 
28
+ manufacturer's programming manual.
29
+
30
+ Device support for following instruments have been developed:
31
+
32
+ ## Power Supplies
33
+ - [CAEN FAST-PS](https://github.com/eicorg/epicsdev_ps_caen_fastps)
34
+
35
+ ## Oscilloscope series
36
+ - [KEYSIGHT (AGILENT) DSO-X](https://github.com/eicorg/epicsdev_osc_keysight_dsox)
37
+ - [RIGOL DHO](https://github.com/eicorg/epicsdev_osc_rigol)
38
+ - [TEKTRONIX MSO](https://github.com/eicorg/epicsdev_osc_tektronix_mso)
39
+ - [LECROY WAVERUNNER](https://github.com/eicorg/epicsdev_osc_lecroy_waverunner)
40
+
41
+ ## Signal generators
42
+ - [SIGLENT SDG series](https://github.com/eicorg/epicsdev_siggen_siglent_sdg)
43
+ - [KEYSIGHT 33000 series](https://github.com/eicorg/epicsdev_siggen_keysight_33000)
44
+
45
+ ## DAQ
46
+ - [CAEN DT5202](https://github.com/eicorg/epicsdev_daq_caen_dt5202)
47
+ - [Labjack U3](https://github.com/eicorg/epicsdev_daq_labjack_u3)
48
+
49
+ ## Magnetometers
50
+ - [LAKESHORE (model 421)](https://github.com/eicorg/epicsdev_magn_lakeshore)
51
+
52
+ ## Simulated instruments<br>
53
+ Multi-channel waveform generator:<br>
54
+ Module **epicdev.multiadc** can generate large amount of data for stress-testing
55
+ the EPICS environment. For example the following command will generate 100 of
56
+ 1000-pont noisy waveforms and 300 of scalar parameters:
57
+ ```python -m epicsdev.multiadc -c100 -n1000```.
58
+
@@ -0,0 +1,43 @@
1
+ # epicsdev
2
+ Python framework that dramatically reduces the effort required
3
+ to create EPICS PVAccess servers using p4p library.
4
+ Device PVs are described  as a compact list of
5
+ `[name, description, initial_value, attributes]` tuples. 
6
+
7
+ The framework handles server creation, periodic updates, autosave/restore, 
8
+ IocStats heartbeat, and PV-put logging automatically.
9
+
10
+ Because all device logic lives in a small, well-structured Python file with a 
11
+ predictable pattern, large-language-model (LLM) assistants such as GitHub 
12
+ Copilot can replicate that pattern for any new instruments given only a 
13
+ manufacturer's programming manual.
14
+
15
+ Device support for following instruments have been developed:
16
+
17
+ ## Power Supplies
18
+ - [CAEN FAST-PS](https://github.com/eicorg/epicsdev_ps_caen_fastps)
19
+
20
+ ## Oscilloscope series
21
+ - [KEYSIGHT (AGILENT) DSO-X](https://github.com/eicorg/epicsdev_osc_keysight_dsox)
22
+ - [RIGOL DHO](https://github.com/eicorg/epicsdev_osc_rigol)
23
+ - [TEKTRONIX MSO](https://github.com/eicorg/epicsdev_osc_tektronix_mso)
24
+ - [LECROY WAVERUNNER](https://github.com/eicorg/epicsdev_osc_lecroy_waverunner)
25
+
26
+ ## Signal generators
27
+ - [SIGLENT SDG series](https://github.com/eicorg/epicsdev_siggen_siglent_sdg)
28
+ - [KEYSIGHT 33000 series](https://github.com/eicorg/epicsdev_siggen_keysight_33000)
29
+
30
+ ## DAQ
31
+ - [CAEN DT5202](https://github.com/eicorg/epicsdev_daq_caen_dt5202)
32
+ - [Labjack U3](https://github.com/eicorg/epicsdev_daq_labjack_u3)
33
+
34
+ ## Magnetometers
35
+ - [LAKESHORE (model 421)](https://github.com/eicorg/epicsdev_magn_lakeshore)
36
+
37
+ ## Simulated instruments<br>
38
+ Multi-channel waveform generator:<br>
39
+ Module **epicdev.multiadc** can generate large amount of data for stress-testing
40
+ the EPICS environment. For example the following command will generate 100 of
41
+ 1000-pont noisy waveforms and 300 of scalar parameters:
42
+ ```python -m epicsdev.multiadc -c100 -n1000```.
43
+
@@ -1,10 +1,7 @@
1
- """Pypet page for epicdev.multiadc, simulated multi-channel ADC device server.
2
- Device instance is configured via environment variable MULTIADC,
3
- default instance is multiadc0:."""
4
- # pylint: disable=invalid-name
5
- __version__ = 'v0.1.0 2026-01-31'#
6
-
7
- import os
1
+ """Pypet page for epicdev.epicsdev module"""
2
+ # format: pypeto 1.2+
3
+ __version__ = 'v0.0.1 2026-01-16'#
4
+ print(f'epicsScope {__version__}')
8
5
 
9
6
  #``````````````````Definitions````````````````````````````````````````````````
10
7
  # python expressions and functions, used in the spreadsheet
@@ -18,30 +15,31 @@ def slider(minValue,maxValue):
18
15
  return {'widget':'hslider','opLimits':[minValue,maxValue],'span':[2,1]}
19
16
 
20
17
  LargeFont = {'color':'light gray', **font(18), 'fgColor':'dark green'}
21
- ButtonFont = {'font':['Open Sans Bold,14']}# Comic Sans MS
18
+ ButtonFont = {'font':['Open Sans Extrabold',14]}# Comic Sans MS
22
19
  LYRow = {'ATTRIBUTES':{'color':'light yellow'}}
23
20
  lColor = color('lightGreen')
24
- PyPath = 'python -m'
25
21
 
26
- try:
27
- Instance = f"multiadc{os.environ['EPICSDEV_MULTIADC']}:"
28
- except KeyError:
29
- Instance = 'multiadc0:'
30
-
31
- #``````````````````Mandatory object PyPage````````````````````````````````````
22
+ # definition for plotting cell
23
+ PyPath = 'python -m'
24
+ PaneP2P = ' '.join([f'ch{i+1:01d}Mean ch{i+1:01d}Peak2Peak' for i in range(1)])
25
+ PaneWF = ' '.join([f'ch{i+1:01d}Waveform' for i in range(1)])
26
+ #PaneT = 'timing[1] timing[3]'
27
+ Plot = {'Plot':{'launch':
28
+ f'{PyPath} pvplot Y-5:5 -aV:epicsDev0: -#0"{PaneP2P}" -#1"{PaneWF}"',# -#2"{PaneT}"',
29
+ **lColor, **ButtonFont}}
30
+ print(f'Plot command: {Plot}')
31
+ #``````````````````PyPage Object``````````````````````````````````````````````
32
32
  class PyPage():
33
- def __init__(self, instance=None,
34
- title=None, channels=6):
33
+ def __init__(self, instance='epicsDev0:',
34
+ title="Simulated oscilloscope", channels=1):
35
35
  """instance: unique name of the page.
36
36
  For EPICS it is usually device prefix
37
37
  """
38
- if instance is None:
39
- instance = Instance
40
38
  print(f'Instantiating Page {instance,title} with {channels} channels')
41
39
 
42
40
  #``````````Mandatory class members starts here````````````````````````
43
41
  self.namespace = 'PVA'
44
- self.title = title if title is not None else instance[:-1]
42
+ self.title = title
45
43
 
46
44
  #``````````Page attributes, optional`````````````````````````
47
45
  self.page = {**color(240,240,240)}
@@ -51,9 +49,9 @@ class PyPage():
51
49
  self.columns = {
52
50
  1: {'width': 120, 'justify': 'right'},
53
51
  2: {'width': 80},
54
- 3: {'width': 80, 'justify': 'right'},
52
+ 3: {'width': 80},
55
53
  4: {'width': 80},
56
- 5: {'width': 80, 'justify': 'right'},
54
+ 5: {'width': 80},
57
55
  6: {'width': 80},
58
56
  7: {'width': 80},
59
57
  8: {'width': 80},
@@ -71,29 +69,18 @@ string or device:parameter and the value is dictionary of the features.
71
69
 
72
70
  #``````````Abbreviations, used in cell definitions
73
71
  def ChLine(suffix):
74
- return [f'{D}c{ch+1:02d}{suffix}' for ch in range(channels)]
75
- PaneP2P = ' '.join([f'c{i+1:02d}Mean c{i+1:02d}Peak2Peak' for i in range(channels)])
76
- PaneWF = ' '.join([f'c{i+1:02d}Waveform' for i in range(channels)])
77
- #PaneT = 'timing[1] timing[3]'
78
- Plot = {'Plot Channels':{'launch':
79
- f'{PyPath} pvplot Y-5:5 -aV:{instance} -#0"{PaneP2P}" -#1"{PaneWF}"',# -#2"{PaneT}"',
80
- **lColor, **ButtonFont}}
81
- print(f'Plot button: {Plot}')
82
- Timing = {'Plot':{'launch':f'{PyPath} pvplot -aV:{instance}timing "[0] [1] [2]"', **lColor}}
83
- print(f'Timing button: {Timing}')
72
+ return [f'{D}ch{ch+1:01d}{suffix}' for ch in range(channels)]
73
+ #FOption = ' -file '+logreqMap.get(D,'')
84
74
  #``````````mandatory member```````````````````````````````````````````
85
75
  self.rows = [
86
- ['Device:',D, D+'server', {D+'channels':just(2)},'chnls, host:',D+'HOSTNAME',D+'VERSION'],
76
+ ['Device:', D, {D+'version':span(2,1)},_,_,_,_],
77
+ ['State:', D+'server','cycle:',D+'cycle',_,_,Plot], # 'Recall:', D+'setup',],
87
78
  ['Status:', {D+'status': span(8,1)}],
88
- ['Cycle time:',D+'cycleTime', 'Sleep:',D+'sleep', 'Cycle:',D+'cycle'],
89
- ['nPoints:',D+'recordLength','Noise:',D+'noiseLevel',
90
- 'Throughput:',D+'throughput',Timing],
91
- [{'ATTRIBUTES':{**color('lightCyan'),**just(1)}},
92
- Plot,'CH1','CH2','CH3','CH4','CH5','CH6'],
79
+ ['Polling Interval:', D+'polling','nPoints:',D+'recordLength',
80
+ 'Noise:',D+'noiseLevel',_],
81
+ [{'ATTRIBUTES':color('lightCyan')},
82
+ 'Channels:','CH1','CH2','CH3','CH4','CH5','CH6'],
93
83
  ['V/div:']+ChLine('VoltsPerDiv'),
94
- ['VoltOffset:']+ChLine('VoltOffset'),
95
84
  ['Mean:']+ChLine('Mean'),
96
85
  ['Peak2Peak:']+ChLine('Peak2Peak'),
97
- #['Waveform:']+ChLine('Waveform'),
98
- ['Timing:',{D+'timing':span(3,1)}],
99
86
  ]
@@ -1,9 +1,8 @@
1
- """Pypet page for epicdev.epicsdev.
2
- """
1
+ """Pypet page for epicdev.epicsdev module"""
3
2
  # pylint: disable=invalid-name
4
- __version__ = 'v0.1.0 2026-01-31'#
5
-
6
- import os
3
+ # format: pypeto 1.2+
4
+ __version__ = 'v0.0.2 2026-01-28'# corrected the Plot action
5
+ print(f'multiadc {__version__}')
7
6
 
8
7
  #``````````````````Definitions````````````````````````````````````````````````
9
8
  # python expressions and functions, used in the spreadsheet
@@ -20,27 +19,28 @@ LargeFont = {'color':'light gray', **font(18), 'fgColor':'dark green'}
20
19
  ButtonFont = {'font':['Open Sans Extrabold',14]}# Comic Sans MS
21
20
  LYRow = {'ATTRIBUTES':{'color':'light yellow'}}
22
21
  lColor = color('lightGreen')
23
- PyPath = 'python -m'
24
-
25
- try:
26
- Instance = f"epicsDev{os.environ['EPICSDEV']}:"
27
- except KeyError:
28
- Instance = 'epicsDev0:'
29
22
 
23
+ # definition for plotting cell
24
+ PyPath = 'python -m'
25
+ PaneP2P = ' '.join([f'c{i+1:02d}Mean c{i+1:02d}Peak2Peak' for i in range(1)])
26
+ PaneWF = ' '.join([f'c{i+1:02d}Waveform' for i in range(1)])
27
+ #PaneT = 'timing[1] timing[3]'
28
+ Plot = {'Plot':{'launch':
29
+ f'{PyPath} pvplot Y-5:5 -aV:multiadc0: -#0"{PaneP2P}" -#1"{PaneWF}"',# -#2"{PaneT}"',
30
+ **lColor, **ButtonFont}}
31
+ print(f'Plot command: {Plot}')
30
32
  #``````````````````PyPage Object``````````````````````````````````````````````
31
33
  class PyPage():
32
- def __init__(self, instance=None,
33
- title="epicsdev", channels=1):
34
+ def __init__(self, instance='multiadc0:',
35
+ title="Simulated oscilloscope", channels=6):
34
36
  """instance: unique name of the page.
35
37
  For EPICS it is usually device prefix
36
38
  """
37
- if instance is None:
38
- instance = Instance
39
39
  print(f'Instantiating Page {instance,title} with {channels} channels')
40
40
 
41
41
  #``````````Mandatory class members starts here````````````````````````
42
42
  self.namespace = 'PVA'
43
- self.title = instance[:-1]
43
+ self.title = title
44
44
 
45
45
  #``````````Page attributes, optional`````````````````````````
46
46
  self.page = {**color(240,240,240)}
@@ -50,9 +50,9 @@ class PyPage():
50
50
  self.columns = {
51
51
  1: {'width': 120, 'justify': 'right'},
52
52
  2: {'width': 80},
53
- 3: {'width': 80, 'justify': 'right'},
53
+ 3: {'width': 80},
54
54
  4: {'width': 80},
55
- 5: {'width': 80, 'justify': 'right'},
55
+ 5: {'width': 80},
56
56
  6: {'width': 80},
57
57
  7: {'width': 80},
58
58
  8: {'width': 80},
@@ -71,23 +71,18 @@ string or device:parameter and the value is dictionary of the features.
71
71
  #``````````Abbreviations, used in cell definitions
72
72
  def ChLine(suffix):
73
73
  return [f'{D}c{ch+1:02d}{suffix}' for ch in range(channels)]
74
- PaneP2P = ' '.join([f'c{i+1:02d}Mean c{i+1:02d}Peak2Peak' for i in range(channels)])
75
- PaneWF = ' '.join([f'c{i+1:02d}Waveform' for i in range(channels)])
76
- #PaneT = 'timing[1] timing[3]'
77
- Plot = {'Plot':{'launch':
78
- f'{PyPath} pvplot Y-5:5 -aV:{instance} -#0"{PaneP2P}" -#1"{PaneWF}"',# -#2"{PaneT}"',
79
- **lColor, **ButtonFont}}
80
- print(f'Plot command: {Plot}')
74
+ #FOption = ' -file '+logreqMap.get(D,'')
81
75
  #``````````mandatory member```````````````````````````````````````````
82
76
  self.rows = [
83
- ['Device:',D, D+'server', D+'VERSION', 'host:',D+'HOSTNAME',D+'CPU_LOAD'],
77
+ ['Device:', D, {D+'version':span(2,1)},_,_,_,_],
78
+ ['State:', D+'server','cycle:',D+'cycle',_,_,Plot], # 'Recall:', D+'setup',],
84
79
  ['Status:', {D+'status': span(8,1)}],
85
- ['Cycle time:',D+'cycleTime', 'Sleep:',D+'sleep', 'Cycle:',D+'cycle', Plot],
86
- ['nPoints:',D+'recordLength','Noise:',D+'noiseLevel',
87
- 'Throughput:',{D+'throughput':span(2,1)},_],
88
- [{'ATTRIBUTES':{**color('lightCyan'),**just(1)}},
89
- 'Channels:', 'CH1', 'CH2', 'CH3', 'CH4', 'CH5', 'CH6'],
80
+ ['Polling Interval:', D+'polling','nPoints:',D+'recordLength',
81
+ 'Noise:',D+'noiseLevel',_],
82
+ [{'ATTRIBUTES':color('lightCyan')},
83
+ 'Channels:','CH1','CH2','CH3','CH4','CH5','CH6'],
90
84
  ['V/div:']+ChLine('VoltsPerDiv'),
91
85
  ['Mean:']+ChLine('Mean'),
92
86
  ['Peak2Peak:']+ChLine('Peak2Peak'),
93
- ]
87
+ ['Waveform:']+ChLine('Waveform'),
88
+ ]
@@ -1,7 +1,8 @@
1
1
  """Helper functions for creating EPICS PVAccess server"""
2
2
  # pylint: disable=invalid-name
3
- __version__= 'v3.2.2 26-04-11'# Notification about autosave permission.
4
- #TODO: Add CBOR-encoded PVs representing arbitrary Python objects, that can be used for storing complex data structures, such as dictionaries, numpy arrays. That will be more efficient than using multiple PVs for each parameter, and more flexible than using JSON-encoded strings.
3
+ __version__= 'v3.3.1 26-09-27'# Limits are handled for read-only PVs.
4
+ #TODO: publish with ifChanged=True, does not work for arrays
5
+ #TODO: ifChanged does not work for enums
5
6
 
6
7
  import sys
7
8
  import time
@@ -40,14 +41,14 @@ def _serverStateChanged(newState:str):
40
41
  return
41
42
 
42
43
  class C_():
43
- """Storage for module members"""
44
+ """ Container for module state variables."""
44
45
  prefix = ''
45
46
  verbose = 0
46
47
  startTime = 0.
47
48
  cycle = 0
48
49
  serverState = ''
49
50
  PVs = {}
50
- PVDefs = []
51
+ PVDefs = []
51
52
  serverStateChanged = _serverStateChanged
52
53
  lastCycleTime = timer()
53
54
  lastUpdateTime = 0.
@@ -219,7 +220,9 @@ def create_PVs(pvDefs, pvcache=None):
219
220
  if field in ['limitLow','limitHigh','format','units']:
220
221
  ntNamedTuples[f'display.{field}'] = extra[field]
221
222
  if field.startswith('limit'):
222
- ntNamedTuples[f'control.{field}'] = extra[field]
223
+ if f'control.{field}' in ntNamedTuples:
224
+ ntNamedTuples[f'control.{field}'] = extra[field]
225
+ ntNamedTuples[f'display.{field}'] = extra[field]
223
226
  if field == 'valueAlarm':
224
227
  for key,value in extra[field].items():
225
228
  ntNamedTuples[f'valueAlarm.{key}'] = value
@@ -251,6 +254,12 @@ def create_PVs(pvDefs, pvcache=None):
251
254
  vr = vv.raw.value
252
255
  ntNamedTuples = spv._wrap(spv.current())
253
256
  oldvr = ntNamedTuples['value']
257
+ try: # if it is ENum
258
+ index = oldvr.index
259
+ oldvr = oldvr.choices[index]
260
+ except: pass
261
+ #printv(f'oldvr: {type(oldvr)},{oldvr}')
262
+
254
263
  # check limits, if they are defined.
255
264
  try:
256
265
  limitLow = ntNamedTuples['control.limitLow']
@@ -265,14 +274,12 @@ def create_PVs(pvDefs, pvcache=None):
265
274
  vr = str(vv)
266
275
  if spv.setter:
267
276
  spv.setter(vr, spv)
268
- # value will be updated by the setter, so get it again
269
- vr = pvv(spv.name)
270
- #vr = spv._wrap(spv.current())['value']
271
- printv(f'putting {spv.name} = {vr}')
277
+ #printv(f'putting {spv.name} = {type(vr)} {vr}')
272
278
  ct = time.time()
273
279
  C_.lastPutTime = ct
274
280
  spv.post(vr, timestamp=ct) # update subscribers
275
281
 
282
+ #printv(f'putlog {spv.name} = {type(vr)} {vr}')
276
283
  if C_.putlogPV is not None:
277
284
  dt = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3].split()
278
285
  ip = op.peer().split(':')[3][:-1]# peer looks like: [::ffff:192.168.27.6]:46362
@@ -292,7 +299,6 @@ def set_verbose(level, *_):
292
299
  """Set verbosity level for debugging"""
293
300
  C_.verbose = level
294
301
  printi(f'Setting verbose to {level}')
295
- publish('verbose',level)
296
302
 
297
303
  def set_server(servState, *_):
298
304
  """Example of the setter for the server PV.
@@ -306,19 +312,15 @@ def set_server(servState, *_):
306
312
  C_.serverStateChanged(servState)
307
313
  if servState == 'Start':
308
314
  printi('Starting the server')
309
- publish('server','Started')
310
315
  publish('status','Started')
311
316
  elif servState == 'Stop':
312
317
  printi('server stopped')
313
- publish('server','Stopped')
314
318
  publish('status','Stopped')
315
319
  elif servState == 'Exit':
316
320
  printi('server is exiting')
317
- publish('server','Exited')
318
321
  publish('status','Exited')
319
322
  elif servState == 'Clear':
320
323
  publish('status','Cleared')
321
- # set server to previous servState
322
324
  set_server(C_.serverState)
323
325
  return
324
326
  C_.serverState = servState
@@ -563,7 +565,6 @@ if __name__ == "__main__":
563
565
  accordingly."""
564
566
  printi(f'Setting tAxis to {value}')
565
567
  publish('tAxis', np.arange(value)*1.E-6)
566
- publish('recordLength', value)
567
568
 
568
569
  def init(recordLength):
569
570
  """Example of device initialization function"""
@@ -622,11 +623,13 @@ if __name__ == "__main__":
622
623
  # The rest of options are not essential, they can be controlled at runtime using PVs.
623
624
  parser.add_argument('-n', '--npoints', type=int, default=100, help=
624
625
  'Number of points in the waveform')
625
- parser.add_argument('-p', '--putlogPV', default='putlog:dump', help=
626
- 'Name of the PV where put operations are logged. If None, then put operations are not logged.')
626
+ parser.add_argument('-p', '--putlogPV', nargs='?', default='', help=
627
+ 'PV name for logging put operations. If given without argument, then putlog is disabled. If not given, then putlog is set to "putlog:dump".')
627
628
  parser.add_argument('-v', '--verbose', action='count', default=0, help=
628
629
  'Show more log messages (-vv: show even more)')
629
630
  pargs = parser.parse_args()
631
+ if pargs.putlogPV == '':
632
+ pargs.putlogPV = 'putlog:dump'
630
633
  print(pargs)
631
634
 
632
635
  # Initialize epicsdev and PVs
@@ -0,0 +1,152 @@
1
+ """Simulated multi-channel ADC device server using epicsdev module."""
2
+ # pylint: disable=invalid-name
3
+ __version__= 'v0.0.2 26-01-23'# refactored
4
+
5
+ import sys
6
+ import time
7
+ from time import perf_counter as timer
8
+ from .epicsdev import Server, Context, init_epicsdev, serverState, publish
9
+ from .epicsdev import pvv, printi, printv, SPV, set_server
10
+
11
+ import numpy as np
12
+ import argparse
13
+
14
+ def myPVDefs():
15
+ """Example of PV definitions"""
16
+ SET,U,LL,LH = 'setter','units','limitLow','limitHigh'
17
+ alarm = {'valueAlarm':{'lowAlarmLimit':-9., 'highAlarmLimit':9.}}
18
+ pvDefs = [ # device-specific PVs
19
+ ['externalControl', 'Name of external PV, which controls the server',
20
+ SPV('Start Stop Clear Exit Started Stopped Exited'.split(), 'WE'), {}],
21
+ ['noiseLevel', 'Noise amplitude', SPV(1.E-4,'W'), {SET:set_noise, U:'V'}],
22
+ ['tAxis', 'Full scale of horizontal axis', SPV([0.]), {U:'S'}],
23
+ ['recordLength','Max number of points', SPV(100,'W','u32'),
24
+ {LL:4,LH:1000000, SET:set_recordLength}],
25
+ ['alarm', 'PV with alarm', SPV(0,'WA'), {U:'du',**alarm}],
26
+ ]
27
+
28
+ # Templates for channel-related PVs. Important: SPV cannot be used in this list!
29
+ ChannelTemplates = [
30
+ ['c0$VoltsPerDiv', 'Vertical scale', (1E-3,'W'), {U:'V/du'}],
31
+ #['c0$VoltOffset', 'Vertical offset', (1E-3,), {U:'V/du'}],
32
+ ['c0$Waveform', 'Waveform array', ([0.],), {U:'du'}],
33
+ ['c0$Mean', 'Mean of the waveform', (0.,'A'), {U:'du'}],
34
+ ['c0$Peak2Peak','Peak-to-peak amplitude', (0.,'A'), {U:'du',**alarm}],
35
+ ]
36
+ # extend PvDefs with channel-related PVs
37
+ for ch in range(pargs.channels):
38
+ for pvdef in ChannelTemplates:
39
+ newpvdef = pvdef.copy()
40
+ newpvdef[0] = pvdef[0].replace('0$',f'{ch+1:02}')
41
+ newpvdef[2] = SPV(*pvdef[2])
42
+ pvDefs.append(newpvdef)
43
+ return pvDefs
44
+
45
+ nPatterns = 100 # number of waveform patterns.
46
+ pargs = None
47
+ rng = np.random.default_rng(nPatterns)
48
+ nPoints = 100
49
+ verbose = 0
50
+
51
+ def set_recordLength(value):
52
+ """Record length have changed. The tAxis should be updated accordingly."""
53
+ printi(f'Setting tAxis to {value}')
54
+ publish('tAxis', np.arange(value)*1.E-6)
55
+ publish('recordLength', value)
56
+ set_noise(pvv('noiseLevel')) # Re-initialize noise array, because its size depends on recordLength
57
+
58
+ def set_noise(level):
59
+ """Noise level have changed. Update noise array."""
60
+ v = float(level)
61
+ recordLength = pvv('recordLength')
62
+ ts = timer()
63
+
64
+ pargs.noise = np.random.normal(scale=0.5*level, size=recordLength+nPatterns)# 45ms/1e6 points
65
+ printi(f'Noise array[{len(pargs.noise)}] updated with level {v:.4g} V. in {timer()-ts:.4g} S.')
66
+ publish('noiseLevel', level)
67
+
68
+ def set_externalControl(value):
69
+ """External control PV have changed. Control the server accordingly."""
70
+ pvname = str(value)
71
+ if pvname in (None,'0'):
72
+ print('External control is not activated.')
73
+ return
74
+ printi(f'External control PV: {pvname}')
75
+ ctxt = Context('pva')
76
+ try:
77
+ r = ctxt.get(pvname, timeout=0.5)
78
+ except TimeoutError:
79
+ printi(f'Cannot connect to external control PV {pvname}.')
80
+ sys.exit(1)
81
+
82
+ def init(recordLength):
83
+ """Testing function. Do not use in production code."""
84
+ set_recordLength(recordLength)
85
+ #set_externalControl(pargs.prefix + pargs.external)
86
+
87
+ def poll():
88
+ """Example of polling function"""
89
+ #pattern = C_.cycle % nPatterns# produces sliding
90
+ cycle = pvv('cycle')
91
+ printv(f'cycle {repr(cycle)}')
92
+ publish('cycle', cycle + 1)
93
+ for ch in range(pargs.channels):
94
+ pattern = rng.integers(0, nPatterns)
95
+ chstr = f'c{ch+1:02}'
96
+ wf = pargs.noise[pattern:pattern+pvv('recordLength')].copy()
97
+ #print(f'ch{ch}, {pattern}: {wf[0], wf.sum(), wf.mean(), np.mean(wf)}')
98
+ wf /= pvv(f'{chstr}VoltsPerDiv')
99
+ #wf += pvv(f'{chstr}Offset')
100
+ wf += ch
101
+ publish(f'{chstr}Waveform', list(wf))
102
+ publish(f'{chstr}Peak2Peak', np.ptp(wf))
103
+ publish(f'{chstr}Mean', np.mean(wf))
104
+
105
+ # Argument parsing
106
+ parser = argparse.ArgumentParser(description = __doc__,
107
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter,
108
+ epilog=f'{__version__}')
109
+ parser.add_argument('-c', '--channels', type=int, default=6, help=
110
+ 'Number of channels per device')
111
+ parser.add_argument('-e', '--external', help=
112
+ 'Name of external PV, which controls the server, if 0 then it will be <device>0:')
113
+ parser.add_argument('-l', '--list', default=None, nargs='?', help=
114
+ 'Directory to save list of all generated PVs, if None, then </tmp/pvlist/><prefix> is assumed.')
115
+ parser.add_argument('-d', '--device', default='multiadc', help=
116
+ 'Device name, the PV name will be <device><index>:')
117
+ parser.add_argument('-i', '--index', default='0', help=
118
+ 'Device index, the PV name will be <device><index>:')
119
+ # The rest of arguments are not essential, they can be changed at runtime using PVs.
120
+ parser.add_argument('-n', '--npoints', type=int, default=nPoints, help=
121
+ 'Number of points in the waveform')
122
+ parser.add_argument('-v', '--verbose', action='count', default=verbose, help=
123
+ 'Show more log messages (-vv: show even more)')
124
+ pargs = parser.parse_args()
125
+ print(f'pargs: {pargs}')
126
+
127
+ # Initialize epicsdev and PVs
128
+ pargs.prefix = f'{pargs.device}{pargs.index}:'
129
+ PVs = init_epicsdev(pargs.prefix, myPVDefs(), pargs.list, pargs.verbose)
130
+ # if pargs.list != '':
131
+ # print('List of PVs:')
132
+ # for _pvname in PVs:
133
+ # print(_pvname)
134
+ printi(f'Hosting {len(PVs)} PVs')
135
+
136
+ # Initialize the device, using pargs if needed. That can be used to set the number of points in the waveform, for example.
137
+ init(pargs.npoints)
138
+
139
+ # Start the Server. Use your set_server, if needed.
140
+ set_server('Start')
141
+
142
+ # Main loop
143
+ server = Server(providers=[PVs])
144
+ printi(f'Server started with polling interval {repr(pvv("polling"))} S.')
145
+ while True:
146
+ state = serverState()
147
+ if state.startswith('Exit'):
148
+ break
149
+ if not state.startswith('Stop'):
150
+ poll()
151
+ time.sleep(pvv("polling"))
152
+ printi('Server is exited')
@@ -4,22 +4,21 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "epicsdev"
7
- version = "3.1.4"
7
+ version = "3.3.1"
8
8
  authors = [
9
9
  { name="Andrey Sukhanov", email="sukhanov@bnl.gov" },
10
10
  ]
11
11
  description = "Helper module for creating EPICS PVAccess servers using p4p"
12
12
  readme = "README.md"
13
- requires-python = ">=3.7"
13
+ requires-python = ">=3.10"
14
14
  classifiers = [
15
15
  "Programming Language :: Python :: 3",
16
- "License :: OSI Approved :: MIT License",
16
+ "License :: OSI Approved :: BSD License",
17
17
  "Operating System :: OS Independent",
18
18
  ]
19
19
  dependencies = [
20
- "p4p>=4.2.2",
21
- "psutil",
20
+ "p4p>=4.2.2",
22
21
  ]
23
22
  [project.urls]
24
- "Homepage" = "https://github.com/ASukhanov/epicsdev"
25
- "Bug Tracker" = "https://github.com/ASukhanov/epicsdev"
23
+ "Homepage" = "https://github.com/eicorg/epicsdev"
24
+ "Bug Tracker" = "https://github.com/eicorg/epicsdev"