epicsdev 3.3.1__tar.gz → 3.3.3__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.
- epicsdev-3.3.3/PKG-INFO +87 -0
- epicsdev-3.3.3/README.md +71 -0
- epicsdev-3.3.3/docs/generate_opi.md +15 -0
- epicsdev-3.3.3/docs/generate_opi.py +76 -0
- epicsdev-3.3.3/docs/generate_server.md +43 -0
- epicsdev-3.3.3/docs/template.py +117 -0
- {epicsdev-3.3.1 → epicsdev-3.3.3}/epicsdev/epicsdev.py +12 -9
- {epicsdev-3.3.1 → epicsdev-3.3.3}/epicsdev/imagegen.py +4 -3
- epicsdev-3.3.3/epicsdev/multiadc.py +177 -0
- {epicsdev-3.3.1 → epicsdev-3.3.3}/pyproject.toml +2 -1
- epicsdev-3.3.1/PKG-INFO +0 -58
- epicsdev-3.3.1/README.md +0 -43
- epicsdev-3.3.1/epicsdev/multiadc.py +0 -152
- {epicsdev-3.3.1 → epicsdev-3.3.3}/LICENSE +0 -0
- {epicsdev-3.3.1 → epicsdev-3.3.3}/config/epicsdev_pp.py +0 -0
- {epicsdev-3.3.1 → epicsdev-3.3.3}/config/multiadc_pp.py +0 -0
- {epicsdev-3.3.1 → epicsdev-3.3.3}/epicsdev/README.md +0 -0
- {epicsdev-3.3.1 → epicsdev-3.3.3}/epicsdev/__init__.py +0 -0
- {epicsdev-3.3.1 → epicsdev-3.3.3}/epicsdev/putlog.py +0 -0
epicsdev-3.3.3/PKG-INFO
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: epicsdev
|
|
3
|
+
Version: 3.3.3
|
|
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
|
+
Requires-Dist: psutil
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# epicsdev
|
|
18
|
+
|
|
19
|
+
`epicsdev` is a Python framework designed for rapidly developing EPICS PVAccess servers utilizing the [p4p](https://github.com/epics-base/p4p) library.
|
|
20
|
+
|
|
21
|
+
Device Process Variables (PVs) are defined using a highly compact format:
|
|
22
|
+
```python
|
|
23
|
+
[name, description, initial_value, attributes]
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Device-specific logic resides within a small, well-structured Python file following a predictable pattern. Given an instrument programming manual, an LLM assistant (such as GitHub Copilot) can easily leverage this pattern to spin up initial support for new hardware in under an hour.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Key Features
|
|
31
|
+
|
|
32
|
+
* **Built-in Services:** Out-of-the-box support for autosave/restore, IocStats, heartbeat monitoring, and PV-put logging.
|
|
33
|
+
* **Rapid Prototyping:** Simple, declarative tuple structure for PV definitions.
|
|
34
|
+
* **LLM-Friendly:** Highly predictable boilerplate that allows AI code assistants to write drivers effortlessly.
|
|
35
|
+
* **OPI Integration:** Automated operator interface generation for Phoebus.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Getting Started
|
|
40
|
+
|
|
41
|
+
### 1. Generate a PVAccess Server
|
|
42
|
+
Follow the [Detailed Server Generation Guide](docs/generate_server.md) to bootstrap a functional PVAccess server supporting your instrument's core functions.
|
|
43
|
+
|
|
44
|
+
### 2. Generate an OPI Display
|
|
45
|
+
You can automatically create an Operator Interface (OPI) layout using [phoebusgen](https://als-epics.github.io/phoebusgen/). See the [OPI Generation Instructions](docs/generate_opi.md) for details.
|
|
46
|
+
|
|
47
|
+
### 3. Quick Test (Simulation Mode)
|
|
48
|
+
To see the framework in action without physical hardware, you can launch a simulated multi-channel waveform generator, which can be useful for stress-testing of EPICS installations. The following command generates 100 noisy waveforms (1,000 points each) alongside 300 scalar parameters:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
python -m epicsdev.multiadc -C 100 -n 1000
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Other examples to run: single waveform generator and multi-peak image generator
|
|
55
|
+
```bash
|
|
56
|
+
python -m epicsdev.epicsdev
|
|
57
|
+
python -m epicsdev.imagegen
|
|
58
|
+
```
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## List of fully functional PVAccess servers, developed using epicsdev
|
|
62
|
+
|
|
63
|
+
Power Supplies
|
|
64
|
+
* [CAEN FAST-PS](https://github.com/eicorg/epicsdev_ps_caen_fastps)
|
|
65
|
+
* [CAEN EASY-DRIVER](https://github.com/eicorg/epicsdev_ps_caen_easydriver)
|
|
66
|
+
|
|
67
|
+
Oscilloscopes
|
|
68
|
+
* [Keysight (Agilent) DSO-X series](https://github.com/eicorg/epicsdev_osc_keysight_dsox)
|
|
69
|
+
* [Rigol DHO series](https://github.com/eicorg/epicsdev_osc_rigol)
|
|
70
|
+
* [Tektronix MSO and DPO series](https://github.com/eicorg/epicsdev_osc_tektronix_mso)
|
|
71
|
+
* [LeCroy WaveRunner series](https://github.com/eicorg/epicsdev_osc_lecroy_waverunner)
|
|
72
|
+
|
|
73
|
+
Signal Generators
|
|
74
|
+
* [Siglent SDG series](https://github.com/eicorg/epicsdev_siggen_siglent_sdg)
|
|
75
|
+
* [Keysight 33000 series](https://github.com/eicorg/epicsdev_siggen_keysight_33000)
|
|
76
|
+
|
|
77
|
+
Data Acquisition instruments
|
|
78
|
+
* [CAEN DT5202](https://github.com/eicorg/epicsdev_daq_caen_dt5202)
|
|
79
|
+
* [LabJack U3](https://github.com/eicorg/epicsdev_daq_labjack_u3)
|
|
80
|
+
|
|
81
|
+
Magnetometers
|
|
82
|
+
* [Lake Shore Model 421](https://github.com/eicorg/epicsdev_magn_lakeshore)
|
|
83
|
+
* [Caylar NMR20](https://github.com/eicorg/epicsdev_magn_caylar_nmr)
|
|
84
|
+
|
|
85
|
+
Simulation Utilities
|
|
86
|
+
* [Multi-channel Waveform Generator](https://github.com/eicorg/epicsdev/blob/main/epicsdev/multiadc.py)
|
|
87
|
+
* [Multi-peak Image Generator](https://github.com/eicorg/epicsdev/blob/main/epicsdev/imagegen.py)
|
epicsdev-3.3.3/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# epicsdev
|
|
2
|
+
|
|
3
|
+
`epicsdev` is a Python framework designed for rapidly developing EPICS PVAccess servers utilizing the [p4p](https://github.com/epics-base/p4p) library.
|
|
4
|
+
|
|
5
|
+
Device Process Variables (PVs) are defined using a highly compact format:
|
|
6
|
+
```python
|
|
7
|
+
[name, description, initial_value, attributes]
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Device-specific logic resides within a small, well-structured Python file following a predictable pattern. Given an instrument programming manual, an LLM assistant (such as GitHub Copilot) can easily leverage this pattern to spin up initial support for new hardware in under an hour.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Key Features
|
|
15
|
+
|
|
16
|
+
* **Built-in Services:** Out-of-the-box support for autosave/restore, IocStats, heartbeat monitoring, and PV-put logging.
|
|
17
|
+
* **Rapid Prototyping:** Simple, declarative tuple structure for PV definitions.
|
|
18
|
+
* **LLM-Friendly:** Highly predictable boilerplate that allows AI code assistants to write drivers effortlessly.
|
|
19
|
+
* **OPI Integration:** Automated operator interface generation for Phoebus.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Getting Started
|
|
24
|
+
|
|
25
|
+
### 1. Generate a PVAccess Server
|
|
26
|
+
Follow the [Detailed Server Generation Guide](docs/generate_server.md) to bootstrap a functional PVAccess server supporting your instrument's core functions.
|
|
27
|
+
|
|
28
|
+
### 2. Generate an OPI Display
|
|
29
|
+
You can automatically create an Operator Interface (OPI) layout using [phoebusgen](https://als-epics.github.io/phoebusgen/). See the [OPI Generation Instructions](docs/generate_opi.md) for details.
|
|
30
|
+
|
|
31
|
+
### 3. Quick Test (Simulation Mode)
|
|
32
|
+
To see the framework in action without physical hardware, you can launch a simulated multi-channel waveform generator, which can be useful for stress-testing of EPICS installations. The following command generates 100 noisy waveforms (1,000 points each) alongside 300 scalar parameters:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
python -m epicsdev.multiadc -C 100 -n 1000
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Other examples to run: single waveform generator and multi-peak image generator
|
|
39
|
+
```bash
|
|
40
|
+
python -m epicsdev.epicsdev
|
|
41
|
+
python -m epicsdev.imagegen
|
|
42
|
+
```
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## List of fully functional PVAccess servers, developed using epicsdev
|
|
46
|
+
|
|
47
|
+
Power Supplies
|
|
48
|
+
* [CAEN FAST-PS](https://github.com/eicorg/epicsdev_ps_caen_fastps)
|
|
49
|
+
* [CAEN EASY-DRIVER](https://github.com/eicorg/epicsdev_ps_caen_easydriver)
|
|
50
|
+
|
|
51
|
+
Oscilloscopes
|
|
52
|
+
* [Keysight (Agilent) DSO-X series](https://github.com/eicorg/epicsdev_osc_keysight_dsox)
|
|
53
|
+
* [Rigol DHO series](https://github.com/eicorg/epicsdev_osc_rigol)
|
|
54
|
+
* [Tektronix MSO and DPO series](https://github.com/eicorg/epicsdev_osc_tektronix_mso)
|
|
55
|
+
* [LeCroy WaveRunner series](https://github.com/eicorg/epicsdev_osc_lecroy_waverunner)
|
|
56
|
+
|
|
57
|
+
Signal Generators
|
|
58
|
+
* [Siglent SDG series](https://github.com/eicorg/epicsdev_siggen_siglent_sdg)
|
|
59
|
+
* [Keysight 33000 series](https://github.com/eicorg/epicsdev_siggen_keysight_33000)
|
|
60
|
+
|
|
61
|
+
Data Acquisition instruments
|
|
62
|
+
* [CAEN DT5202](https://github.com/eicorg/epicsdev_daq_caen_dt5202)
|
|
63
|
+
* [LabJack U3](https://github.com/eicorg/epicsdev_daq_labjack_u3)
|
|
64
|
+
|
|
65
|
+
Magnetometers
|
|
66
|
+
* [Lake Shore Model 421](https://github.com/eicorg/epicsdev_magn_lakeshore)
|
|
67
|
+
* [Caylar NMR20](https://github.com/eicorg/epicsdev_magn_caylar_nmr)
|
|
68
|
+
|
|
69
|
+
Simulation Utilities
|
|
70
|
+
* [Multi-channel Waveform Generator](https://github.com/eicorg/epicsdev/blob/main/epicsdev/multiadc.py)
|
|
71
|
+
* [Multi-peak Image Generator](https://github.com/eicorg/epicsdev/blob/main/epicsdev/imagegen.py)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
## Generate the Operator Interface (OPI)
|
|
2
|
+
|
|
3
|
+
Copy this [OPI generator template](https://github.com/eicorg/epicsdev/blob/main/docs/generate_opi.py) to:
|
|
4
|
+
|
|
5
|
+
```text
|
|
6
|
+
opi/generate_opi.py
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Then prompt an AI agent such as GitHub Copilot:
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
Modify opi/generate_opi.py to generate an OPI for the PVs defined in my_server/__main__.py.
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Include any display-specific requirements in the prompt, such as the desired layout, grouping of controls and readbacks, plots, alarms, or status indicators.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Operator interface generator for template"""
|
|
2
|
+
__version__ = 'v0.0.1 2026-10-01'
|
|
3
|
+
# pylint: disable=invalid-name,broad-exception-caught
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
import phoebusgen.screen
|
|
9
|
+
import phoebusgen.widget
|
|
10
|
+
|
|
11
|
+
DEVICE = "template"
|
|
12
|
+
INSTANCE = "0"
|
|
13
|
+
TITLE = DEVICE+INSTANCE
|
|
14
|
+
PREFIX = f'pva://{DEVICE}:{INSTANCE}:'
|
|
15
|
+
|
|
16
|
+
def _parse_args() -> argparse.Namespace:
|
|
17
|
+
parser = argparse.ArgumentParser(
|
|
18
|
+
description=__doc__,
|
|
19
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
20
|
+
epilog=__version__,
|
|
21
|
+
)
|
|
22
|
+
parser.add_argument("-t", "--title", default=TITLE, help="Screen title")
|
|
23
|
+
parser.add_argument("prefix", nargs="?", default=PREFIX,
|
|
24
|
+
help=(
|
|
25
|
+
"PV prefix used for all widget PV names. "
|
|
26
|
+
),
|
|
27
|
+
)
|
|
28
|
+
return parser.parse_args()
|
|
29
|
+
|
|
30
|
+
def _add_items(widget, values: str) -> None:
|
|
31
|
+
for item in values.split(", "):
|
|
32
|
+
widget.item(item)
|
|
33
|
+
|
|
34
|
+
def main() -> None:
|
|
35
|
+
pargs = _parse_args()
|
|
36
|
+
prefix = pargs.prefix
|
|
37
|
+
|
|
38
|
+
screen = phoebusgen.screen.Screen(pargs.title, f"{TITLE}.bob")
|
|
39
|
+
screen.width(1080)
|
|
40
|
+
screen.height(660)
|
|
41
|
+
|
|
42
|
+
w = phoebusgen.widget
|
|
43
|
+
widgets = {
|
|
44
|
+
"title": w.Label("title", TITLE, 20, 10, 170, 30),
|
|
45
|
+
"Model_lbl": w.Label("Model_lbl", "Model:", 200, 14, 40, 20),
|
|
46
|
+
"Model": w.TextUpdate("Model", f"{prefix}Model", 245, 14, 80, 20),
|
|
47
|
+
"Version_lbl": w.Label("Version_lbl", "FW:", 340, 14, 25, 20),
|
|
48
|
+
"Version": w.TextUpdate("Version", f"{prefix}Version", 365, 14, 40, 20),
|
|
49
|
+
"dateTime": w.TextUpdate("dateTime", f"{prefix}dateTime", 420, 14, 70, 20),
|
|
50
|
+
}
|
|
51
|
+
y = 45
|
|
52
|
+
widgets.update({
|
|
53
|
+
"srvStatus_lbl": w.Label("srvStatus_lbl", "Server:", 20, y, 100, 20),
|
|
54
|
+
"srvStatus": w.TextUpdate("srvStatus", f"{prefix}status", 70, y, 790, 20),
|
|
55
|
+
})
|
|
56
|
+
y += 40
|
|
57
|
+
widgets.update({
|
|
58
|
+
"state_lbl": w.Label("state_lbl", "Run/Stop:", 20, y, 65, 20),
|
|
59
|
+
"server": w.ComboBox("server", f"{prefix}server", 90, y, 110, 20),
|
|
60
|
+
"sleep_lbl": w.Label("sleep_lbl", "Sleep:", 410, y, 40, 20),
|
|
61
|
+
"sleep": w.TextEntry("sleep", f"{prefix}sleep", 450, y, 50, 20),
|
|
62
|
+
"cycleTime_lbl": w.Label("cycleTime_lbl", "Period:", 510, y, 50, 20),
|
|
63
|
+
"cycleTime": w.TextUpdate("cycleTime", f"{prefix}cycleTime", 560, y, 60, 20),
|
|
64
|
+
"hb_lbl": w.Label("hb_lbl", "HB:", 640, y, 30, 20),
|
|
65
|
+
"HEARTBEAT": w.TextUpdate("HEARTBEAT", f"{prefix}HEARTBEAT", 670, y, 70, 20),
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
# TODO: add device widgets
|
|
69
|
+
|
|
70
|
+
screen.add_widget(list(widgets.values()))
|
|
71
|
+
|
|
72
|
+
out = Path(__file__).with_name(f"{TITLE}.bob")
|
|
73
|
+
screen.write_screen(str(out))
|
|
74
|
+
|
|
75
|
+
if __name__ == "__main__":
|
|
76
|
+
main()
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
## Automatically generate a PVAccess server for an instrument
|
|
2
|
+
|
|
3
|
+
### Initialize the project
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
mkdir my_server
|
|
7
|
+
cd my_server
|
|
8
|
+
|
|
9
|
+
mkdir my_server opi docs misc
|
|
10
|
+
touch my_server/__init__.py
|
|
11
|
+
|
|
12
|
+
uv init
|
|
13
|
+
uv add epicsdev
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Copy the instrument programming manual to: ```misc/programming_manual.pdf```
|
|
17
|
+
|
|
18
|
+
Copy the [server template](https://github.com/eicorg/epicsdev/blob/main/docs/template.py) to: ```my_server/__main__.py ```
|
|
19
|
+
|
|
20
|
+
### Use an AI agent
|
|
21
|
+
|
|
22
|
+
From the project directory, prompt an AI agent such as GitHub Copilot:
|
|
23
|
+
|
|
24
|
+
```text
|
|
25
|
+
Modify my_server/__main__.py to provide EPICS PVAccess support for <instrument name and model>.
|
|
26
|
+
Use the programming manual in misc/programming_manual.pdf as the primary reference.
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Add relevant details to the prompt to obtain a better targeted result, for example:
|
|
30
|
+
|
|
31
|
+
- Connection type and address: TCP/IP, USB, serial, or GPIB
|
|
32
|
+
- Required instrument functions and parameters
|
|
33
|
+
- Preferred EPICS PV naming convention
|
|
34
|
+
- Polling rate and performance requirements
|
|
35
|
+
- Required OPI screens or example configuration
|
|
36
|
+
|
|
37
|
+
Review the agent’s recommendations, test the server with the real instrument, and refine error handling and recovery behavior as needed.
|
|
38
|
+
|
|
39
|
+
### Test run
|
|
40
|
+
```
|
|
41
|
+
uv run python -m my_server
|
|
42
|
+
```
|
|
43
|
+
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""EPICS PVAccess server for template."""
|
|
2
|
+
# pylint: disable=invalid-name,broad-exception-caught
|
|
3
|
+
__version__ = 'v0.0.2 2026-10-01'# --index replaced with --instance. This is more generic.
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
|
|
8
|
+
from epicsdev import epicsdev as edev
|
|
9
|
+
|
|
10
|
+
DEVICE = 'template:'
|
|
11
|
+
|
|
12
|
+
#````````````````````````````````````````````````````````````````````````````
|
|
13
|
+
# Definitions of PVs, their types, units, limits, and setter functions are
|
|
14
|
+
# defined in the myPVDefs() function below.
|
|
15
|
+
def myPVDefs():
|
|
16
|
+
"""Return list of PV definitions"""
|
|
17
|
+
# abbreviations for PV definition dictionary keys
|
|
18
|
+
F, T, U, LL, LH = 'features', 'type', 'units', 'limitLow', 'limitHigh'
|
|
19
|
+
SET = 'setter'
|
|
20
|
+
|
|
21
|
+
pv_defs = [
|
|
22
|
+
['dateTime', 'Server local date/time', 'N/A'],
|
|
23
|
+
# TODO: add your PV definitions here
|
|
24
|
+
]
|
|
25
|
+
return pv_defs
|
|
26
|
+
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
|
27
|
+
|
|
28
|
+
@dataclass(slots=True)
|
|
29
|
+
class C_:
|
|
30
|
+
"""Container for module state variables."""
|
|
31
|
+
pargs = None #
|
|
32
|
+
|
|
33
|
+
def poll():
|
|
34
|
+
"""Poll for updates from the hardware or other sources."""
|
|
35
|
+
# TODO: implement polling logic
|
|
36
|
+
|
|
37
|
+
def periodic_update():
|
|
38
|
+
"""Perform periodic updates."""
|
|
39
|
+
# TODO: implement periodic update logic
|
|
40
|
+
|
|
41
|
+
def serverStateChanged(newState: str):
|
|
42
|
+
"""Callback for server state transitions."""
|
|
43
|
+
if newState == 'Start':
|
|
44
|
+
edev.printi('Start requested')
|
|
45
|
+
elif newState == 'Stop':
|
|
46
|
+
edev.printi('Stop requested')
|
|
47
|
+
elif newState == 'Exit':
|
|
48
|
+
edev.printi('Exit requested')
|
|
49
|
+
|
|
50
|
+
if __name__ == '__main__':
|
|
51
|
+
parser = argparse.ArgumentParser(
|
|
52
|
+
description=__doc__,
|
|
53
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
54
|
+
epilog=f'{__version__}, epicsdev:{edev.__version__}',
|
|
55
|
+
)
|
|
56
|
+
# commonly used options
|
|
57
|
+
parser.add_argument('-a', '--autosave', nargs='?', default='', help=
|
|
58
|
+
'Autosave control. If omitted, autosave is enabled with default directory.')
|
|
59
|
+
parser.add_argument('-c', '--recall', action='store_false', help=
|
|
60
|
+
'If given: do not restore initial PV values from autosave cache.')
|
|
61
|
+
parser.add_argument('-i', '--instance', default='0', help=
|
|
62
|
+
'Device instance.')
|
|
63
|
+
parser.add_argument('-p', '--putlogPV', nargs='?', default='', help=
|
|
64
|
+
'PV name for logging put operations. Empty means default putlog:dump.')
|
|
65
|
+
parser.add_argument('-v', '--verbose', action='count', default=0, help=
|
|
66
|
+
'Increase verbosity (-vv for more).')
|
|
67
|
+
parser.add_argument('device', nargs='?', default=DEVICE, help=
|
|
68
|
+
'Device name, the prefix for all generated PVs <prefix><instance>:')
|
|
69
|
+
|
|
70
|
+
# TODO: add your options here
|
|
71
|
+
|
|
72
|
+
# Parse command-line arguments and store them in the module state container.
|
|
73
|
+
C_.pargs = parser.parse_args()
|
|
74
|
+
if C_.pargs.putlogPV == '':
|
|
75
|
+
C_.pargs.putlogPV = 'putlog:dump'
|
|
76
|
+
C_.pargs.prefix = f'{C_.pargs.device}{C_.pargs.instance}:'
|
|
77
|
+
|
|
78
|
+
# Initialize PV definitions.
|
|
79
|
+
C_.PvDefs = myPVDefs()
|
|
80
|
+
|
|
81
|
+
# Initialize the EPICS PVAccess server with the defined PVs.
|
|
82
|
+
PVs = edev.init_epicsdev(
|
|
83
|
+
C_.pargs.prefix,
|
|
84
|
+
C_.PvDefs,
|
|
85
|
+
C_.pargs.verbose,
|
|
86
|
+
serverStateChanged,
|
|
87
|
+
'',
|
|
88
|
+
C_.pargs.autosave,
|
|
89
|
+
C_.pargs.recall,
|
|
90
|
+
C_.pargs.putlogPV,
|
|
91
|
+
)
|
|
92
|
+
print(f'Using PV prefix: {C_.pargs.prefix}')
|
|
93
|
+
|
|
94
|
+
# Start the server and print initial status.
|
|
95
|
+
edev.publish('VERSION', __version__)
|
|
96
|
+
edev.set_server('Start')
|
|
97
|
+
server = edev.Server(providers=[PVs])
|
|
98
|
+
edev.printi((f'Server for {C_.pargs.prefix} started. Sleeping per cycle: '
|
|
99
|
+
f'{repr(edev.pvv("sleep"))} S.'))
|
|
100
|
+
|
|
101
|
+
# Main server loop. Polls for updates and handles server state transitions.
|
|
102
|
+
try:
|
|
103
|
+
while True:
|
|
104
|
+
state = edev.serverState()
|
|
105
|
+
if state.startswith('Exit'):
|
|
106
|
+
break
|
|
107
|
+
if not state.startswith('Stop'):
|
|
108
|
+
poll()
|
|
109
|
+
if not edev.sleep():
|
|
110
|
+
periodic_update()
|
|
111
|
+
except KeyboardInterrupt:
|
|
112
|
+
edev.printi('Keyboard interrupt received, exiting main loop...')
|
|
113
|
+
edev.set_server('Exit')
|
|
114
|
+
except OSError:
|
|
115
|
+
pass
|
|
116
|
+
|
|
117
|
+
edev.printi('Server is exited')
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Helper functions for creating EPICS PVAccess server"""
|
|
2
2
|
# pylint: disable=invalid-name
|
|
3
|
-
__version__= 'v3.3.
|
|
3
|
+
__version__= 'v3.3.3 26-10-02'# extra error handling for write_cache and putLog
|
|
4
4
|
#TODO: publish with ifChanged=True, does not work for arrays
|
|
5
5
|
#TODO: ifChanged does not work for enums
|
|
6
6
|
|
|
@@ -132,9 +132,11 @@ def write_cache():
|
|
|
132
132
|
pyval = value
|
|
133
133
|
#print(f'Caching {pvName} = {value} of type {type(value)}, python value: {pyval} of type {type(pyval)}')
|
|
134
134
|
pvcacheMap[pvName[len(C_.prefix):]] = {'value': pyval, 'time': time.time()}
|
|
135
|
-
#print(f'pvCache: {pvcacheMap}')
|
|
136
135
|
C_.cachefd.seek(0)
|
|
137
|
-
|
|
136
|
+
try:
|
|
137
|
+
json.dump(pvcacheMap, C_.cachefd)
|
|
138
|
+
except TypeError:
|
|
139
|
+
printe('in write_cache: could not write cacheMap, one of PVs is not Json-compatible')
|
|
138
140
|
C_.cachefd.truncate()
|
|
139
141
|
C_.cachefd.flush()
|
|
140
142
|
|
|
@@ -462,7 +464,7 @@ def init_epicsdev(prefix:str, pvDefs:list, verbose=0, serverStateChanged=None,
|
|
|
462
464
|
|
|
463
465
|
# Set up putlogPV if requested. That will log put operations to a PV, which can be useful for auditing and debugging.
|
|
464
466
|
C_.putlogPV = putlogPV
|
|
465
|
-
if C_.putlogPV
|
|
467
|
+
if C_.putlogPV not in (None,'',):
|
|
466
468
|
try:
|
|
467
469
|
_ = IFace.get(putlogPV, timeout=0.5)
|
|
468
470
|
printi(f'PutLog enabled. Logging put operations to {putlogPV}')
|
|
@@ -576,18 +578,19 @@ if __name__ == "__main__":
|
|
|
576
578
|
wf = rng.random(pvv('recordLength'))*pvv('noiseLevel')# it takes 5ms for 1M points
|
|
577
579
|
wf /= pvv('c01VoltsPerDiv')
|
|
578
580
|
wf += pvv('c01Offset')
|
|
581
|
+
tstamp = time.time()
|
|
579
582
|
ts = timer()
|
|
580
|
-
publish('c01Waveform', wf)
|
|
581
|
-
publish('waveform', wf*10)
|
|
583
|
+
publish('c01Waveform', wf, t=tstamp)
|
|
584
|
+
publish('waveform', wf*10, t=tstamp)
|
|
582
585
|
_sum['time'] += timer() - ts
|
|
583
586
|
_sum['points'] += len(wf)
|
|
584
|
-
publish('c01Peak2Peak', np.ptp(wf))
|
|
585
|
-
publish('c01Mean', np.mean(wf))
|
|
587
|
+
publish('c01Peak2Peak', np.ptp(wf), t=tstamp)
|
|
588
|
+
publish('c01Mean', np.mean(wf), t=tstamp)
|
|
586
589
|
|
|
587
590
|
# For demo purposes, we also publish the waveform as an image. That is not a typical use case, but it shows how to publish 2D arrays.
|
|
588
591
|
dim = int(np.sqrt(len(wf)))
|
|
589
592
|
array2d = (wf*10.)[:dim*dim].reshape([dim, dim])
|
|
590
|
-
publish('image', array2d.astype('int16'))
|
|
593
|
+
publish('image', array2d.astype('int16'), t=tstamp)
|
|
591
594
|
|
|
592
595
|
def periodic_update():
|
|
593
596
|
"""Perform periodic update"""
|
|
@@ -159,19 +159,20 @@ parser = argparse.ArgumentParser(
|
|
|
159
159
|
)
|
|
160
160
|
parser.add_argument("-a", "--autosave", nargs="?", default="")
|
|
161
161
|
parser.add_argument("-c", "--recall", action="store_false")
|
|
162
|
-
parser.add_argument("-d", "--device", default="image")
|
|
163
162
|
parser.add_argument("-g", "--generate", nargs="?", default="", help=
|
|
164
163
|
"Generate array PVs on startup: 'r' for row, 's' for statistics'" )
|
|
165
|
-
parser.add_argument("-i", "--
|
|
164
|
+
parser.add_argument("-i", "--instance", default="0")
|
|
166
165
|
parser.add_argument("-s", "--shape", default="120,120", help=
|
|
167
166
|
"Initial number of rows and columns in the image." )
|
|
168
167
|
parser.add_argument("-p", "--putlogPV", default="putlog:dump")
|
|
169
168
|
parser.add_argument("-v", "--verbose", action="count", default=0)
|
|
169
|
+
parser.add_argument('device', nargs='?', default='image:', help=
|
|
170
|
+
'Device name, the prefix for all generated PVs <prefix><instance>:')
|
|
170
171
|
pargs = parser.parse_args()
|
|
171
172
|
pargs.nrows, pargs.ncols = [int(s) for s in pargs.shape.split(',')]
|
|
172
173
|
printi(f"Parsed arguments: {pargs}")
|
|
173
174
|
|
|
174
|
-
prefix = f"{pargs.device}{pargs.
|
|
175
|
+
prefix = f"{pargs.device}{pargs.instance}:"
|
|
175
176
|
pvs = init_epicsdev(
|
|
176
177
|
prefix,
|
|
177
178
|
my_pv_defs(),
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"""Simulated multi-channel ADC device server using epicsdev module."""
|
|
2
|
+
# pylint: disable=invalid-name
|
|
3
|
+
__version__= 'v0.1.0 26-10-02'# Conform to epicsdev 3.3.3+
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
import time
|
|
7
|
+
from time import perf_counter as timer
|
|
8
|
+
import numpy as np
|
|
9
|
+
import argparse
|
|
10
|
+
|
|
11
|
+
#from .epicsdev import Server, Context, init_epicsdev, serverState, publish
|
|
12
|
+
#from .epicsdev import pvv, printi, printv, set_server,
|
|
13
|
+
from epicsdev import epicsdev as edev
|
|
14
|
+
|
|
15
|
+
def myPVDefs():
|
|
16
|
+
"""Return list of PV definitions"""
|
|
17
|
+
# abbreviations for PV definition dictionary keys
|
|
18
|
+
F, T, U, LL, LH = 'features', 'type', 'units', 'limitLow', 'limitHigh'
|
|
19
|
+
SET = 'setter'
|
|
20
|
+
alarm = {'valueAlarm':{'lowAlarmLimit':-9., 'highAlarmLimit':9.}}
|
|
21
|
+
|
|
22
|
+
# Define PVs for the multi-channel ADC server.
|
|
23
|
+
pvDefs = [
|
|
24
|
+
#['externalControl', 'Name of external PV, which controls the server',
|
|
25
|
+
# 'Start Stop Clear Exit Started Stopped Exited'.split(), {F:'W'}],
|
|
26
|
+
['noiseLevel', 'Noise amplitude', 1.E-4, {SET:set_noise, U:'V'}],
|
|
27
|
+
['tAxis', 'Full scale of horizontal axis', [0.], {U:'S'}],
|
|
28
|
+
['recordLength','Max number of points', 100,
|
|
29
|
+
{F:'W', T:'u32', LL:4, LH:1000000, SET:set_recordLength}],
|
|
30
|
+
['alarm', 'PV with alarm', 0, {F:'WA', U:'du',**alarm}],
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
# Templates for channel-related PVs. Important: SPV cannot be used in this list!
|
|
34
|
+
ChannelTemplates = [
|
|
35
|
+
['c0$VoltsPerDiv', 'Vertical scale', 1E-3, {F:'W'}, {U:'V/du'}],
|
|
36
|
+
#['c0$VoltOffset', 'Vertical offset', (1E-3,), {U:'V/du'}],
|
|
37
|
+
['c0$Waveform', 'Waveform array', [0.], {U:'du'}],
|
|
38
|
+
['c0$Mean', 'Mean of the waveform', 0., {F:'A', U:'du'}],
|
|
39
|
+
['c0$Peak2Peak','Peak-to-peak amplitude', 0., {F:'A', U:'du', **alarm}],
|
|
40
|
+
]
|
|
41
|
+
# extend PvDefs with channel-related PVs
|
|
42
|
+
for ch in range(pargs.channels):
|
|
43
|
+
for pvdef in ChannelTemplates:
|
|
44
|
+
newpvdef = pvdef.copy()
|
|
45
|
+
newpvdef[0] = pvdef[0].replace('0$',f'{ch+1:02}')
|
|
46
|
+
newpvdef[2] = pvdef[2]
|
|
47
|
+
pvDefs.append(newpvdef)
|
|
48
|
+
return pvDefs
|
|
49
|
+
|
|
50
|
+
nPatterns = 100 # number of waveform patterns.
|
|
51
|
+
pargs = None
|
|
52
|
+
rng = np.random.default_rng(nPatterns)
|
|
53
|
+
nPoints = 100
|
|
54
|
+
verbose = 0
|
|
55
|
+
|
|
56
|
+
def set_recordLength(value):
|
|
57
|
+
"""Record length have changed. The tAxis should be updated accordingly."""
|
|
58
|
+
edev.printi(f'Setting tAxis to {value}')
|
|
59
|
+
edev.publish('tAxis', np.arange(value)*1.E-6)
|
|
60
|
+
edev.publish('recordLength', value)
|
|
61
|
+
set_noise(edev.pvv('noiseLevel')) # Re-initialize noise array, because its size depends on recordLength
|
|
62
|
+
|
|
63
|
+
def set_noise(level):
|
|
64
|
+
"""Noise level have changed. Update noise array."""
|
|
65
|
+
v = float(level)
|
|
66
|
+
recordLength = edev.pvv('recordLength')
|
|
67
|
+
ts = timer()
|
|
68
|
+
|
|
69
|
+
pargs.noise = np.random.normal(scale=0.5*level, size=recordLength+nPatterns)# 45ms/1e6 points
|
|
70
|
+
edev.printi(f'Noise array[{len(pargs.noise)}] updated with level {v:.4g} V. in {timer()-ts:.4g} S.')
|
|
71
|
+
edev.publish('noiseLevel', level)
|
|
72
|
+
|
|
73
|
+
# def set_externalControl(value):
|
|
74
|
+
# """External control PV have changed. Control the server accordingly."""
|
|
75
|
+
# pvname = str(value)
|
|
76
|
+
# if pvname in (None,'0'):
|
|
77
|
+
# edev.printi('External control is not activated.')
|
|
78
|
+
# return
|
|
79
|
+
# edev.printi(f'External control PV: {pvname}')
|
|
80
|
+
# ctxt = edev.Context('pva')
|
|
81
|
+
# try:
|
|
82
|
+
# r = ctxt.get(pvname, timeout=0.5)
|
|
83
|
+
# except TimeoutError:
|
|
84
|
+
# edev.printi(f'Cannot connect to external control PV {pvname}.')
|
|
85
|
+
# sys.exit(1)
|
|
86
|
+
|
|
87
|
+
def init(recordLength):
|
|
88
|
+
"""Testing function. Do not use in production code."""
|
|
89
|
+
set_recordLength(recordLength)
|
|
90
|
+
#set_externalControl(pargs.prefix + pargs.external)
|
|
91
|
+
|
|
92
|
+
def poll():
|
|
93
|
+
"""Example of polling function"""
|
|
94
|
+
#pattern = C_.cycle % nPatterns# produces sliding
|
|
95
|
+
cycle = edev.pvv('cycle')
|
|
96
|
+
edev.printv(f'cycle {repr(cycle)}')
|
|
97
|
+
edev.publish('cycle', cycle + 1)
|
|
98
|
+
for ch in range(pargs.channels):
|
|
99
|
+
pattern = rng.integers(0, nPatterns)
|
|
100
|
+
chstr = f'c{ch+1:02}'
|
|
101
|
+
wf = pargs.noise[pattern:pattern+edev.pvv('recordLength')].copy()
|
|
102
|
+
#print(f'ch{ch}, {pattern}: {wf[0], wf.sum(), wf.mean(), np.mean(wf)}')
|
|
103
|
+
wf /= edev.pvv(f'{chstr}VoltsPerDiv')
|
|
104
|
+
#wf += edev.pvv(f'{chstr}Offset')
|
|
105
|
+
wf += ch
|
|
106
|
+
edev.publish(f'{chstr}Waveform', list(wf))
|
|
107
|
+
edev.publish(f'{chstr}Peak2Peak', np.ptp(wf))
|
|
108
|
+
edev.publish(f'{chstr}Mean', np.mean(wf))
|
|
109
|
+
|
|
110
|
+
def periodic_update():
|
|
111
|
+
"""Function called periodically in the main server loop."""
|
|
112
|
+
edev.printv('Periodic update called.')
|
|
113
|
+
|
|
114
|
+
# Argument parsing
|
|
115
|
+
parser = argparse.ArgumentParser(description = __doc__,
|
|
116
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
117
|
+
epilog=f'{__version__}, epicsdev:{edev.__version__}')
|
|
118
|
+
parser.add_argument('-a', '--autosave', nargs='?', default='', help=
|
|
119
|
+
'Autosave control. If omitted, autosave is enabled with default directory.')
|
|
120
|
+
parser.add_argument('-c', '--recall', action='store_false', help=
|
|
121
|
+
'If given: do not restore initial PV values from autosave cache.')
|
|
122
|
+
parser.add_argument('-C', '--channels', type=int, default=6, help=
|
|
123
|
+
'Number of channels per device')
|
|
124
|
+
parser.add_argument('-e', '--external', help=
|
|
125
|
+
'Name of external PV, which controls the server, if 0 then it will be <device>0:')
|
|
126
|
+
parser.add_argument('-l', '--list', default=None, nargs='?', help=
|
|
127
|
+
'Directory to save list of all generated PVs, if None, then </tmp/pvlist/><prefix> is assumed.')
|
|
128
|
+
parser.add_argument('-i', '--instance', default='0', help=
|
|
129
|
+
'Device index, the PV name will be <device><index>:')
|
|
130
|
+
# The rest of arguments are not essential, they can be changed at runtime using PVs.
|
|
131
|
+
parser.add_argument('-n', '--npoints', type=int, default=nPoints, help=
|
|
132
|
+
'Number of points in the waveform')
|
|
133
|
+
parser.add_argument('-p', '--putlogPV', nargs='?', default='', help=
|
|
134
|
+
'PV name for logging put operations. Empty means default putlog:dump.')
|
|
135
|
+
parser.add_argument('-v', '--verbose', action='count', default=verbose, help=
|
|
136
|
+
'Show more log messages (-vv: show even more)')
|
|
137
|
+
parser.add_argument('device', nargs='?', default='multiadc:', help=
|
|
138
|
+
'Device name, the prefix for all generated PVs <prefix><instance>:')
|
|
139
|
+
pargs = parser.parse_args()
|
|
140
|
+
print(f'pargs: {pargs}')
|
|
141
|
+
|
|
142
|
+
# Initialize epicsdev and PVs
|
|
143
|
+
pargs.prefix = f'{pargs.device}{pargs.instance}:'
|
|
144
|
+
PVs = edev.init_epicsdev(pargs.prefix, myPVDefs(), pargs.verbose,
|
|
145
|
+
serverStateChanged=None,
|
|
146
|
+
listDir=pargs.list,
|
|
147
|
+
autosaveDir=pargs.autosave,
|
|
148
|
+
recall=pargs.recall,
|
|
149
|
+
putlogPV=pargs.putlogPV)
|
|
150
|
+
|
|
151
|
+
# Initialize the device, using pargs if needed. That can be used to set the number of points in the waveform, for example.
|
|
152
|
+
init(pargs.npoints)
|
|
153
|
+
|
|
154
|
+
# Start the server and print initial status.
|
|
155
|
+
edev.publish('VERSION', __version__)
|
|
156
|
+
edev.set_server('Start')
|
|
157
|
+
server = edev.Server(providers=[PVs])
|
|
158
|
+
edev.printi((f'Server for {pargs.prefix} started. Sleeping per cycle: '
|
|
159
|
+
f'{repr(edev.pvv("sleep"))} S.'))
|
|
160
|
+
|
|
161
|
+
# Main server loop. Polls for updates and handles server state transitions.
|
|
162
|
+
try:
|
|
163
|
+
while True:
|
|
164
|
+
state = edev.serverState()
|
|
165
|
+
if state.startswith('Exit'):
|
|
166
|
+
break
|
|
167
|
+
if not state.startswith('Stop'):
|
|
168
|
+
poll()
|
|
169
|
+
if not edev.sleep():
|
|
170
|
+
periodic_update()
|
|
171
|
+
except KeyboardInterrupt:
|
|
172
|
+
edev.printi('Keyboard interrupt received, exiting main loop...')
|
|
173
|
+
edev.set_server('Exit')
|
|
174
|
+
except OSError:
|
|
175
|
+
pass
|
|
176
|
+
|
|
177
|
+
edev.printi('Server is exited')
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "epicsdev"
|
|
7
|
-
version = "3.3.
|
|
7
|
+
version = "3.3.3"
|
|
8
8
|
authors = [
|
|
9
9
|
{ name="Andrey Sukhanov", email="sukhanov@bnl.gov" },
|
|
10
10
|
]
|
|
@@ -18,6 +18,7 @@ classifiers = [
|
|
|
18
18
|
]
|
|
19
19
|
dependencies = [
|
|
20
20
|
"p4p>=4.2.2",
|
|
21
|
+
"psutil",
|
|
21
22
|
]
|
|
22
23
|
[project.urls]
|
|
23
24
|
"Homepage" = "https://github.com/eicorg/epicsdev"
|
epicsdev-3.3.1/PKG-INFO
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
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
|
-
|
epicsdev-3.3.1/README.md
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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,152 +0,0 @@
|
|
|
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')
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|