thzdaq-instruments 0.0.6b4__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.
- thzdaq_instruments-0.0.6b4/.gitignore +25 -0
- thzdaq_instruments-0.0.6b4/LICENSE +21 -0
- thzdaq_instruments-0.0.6b4/PKG-INFO +62 -0
- thzdaq_instruments-0.0.6b4/README.md +36 -0
- thzdaq_instruments-0.0.6b4/pyproject.toml +47 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/__init__.py +33 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/actions.py +148 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/angle.py +80 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/capabilities.py +229 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/__init__.py +96 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/agilent.py +123 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/arduino.py +100 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/chopper.py +239 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/generic.py +19 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/keithley.py +46 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/lakeshore.py +143 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/national_instruments.py +98 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/pfeiffer.py +232 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/pfeiffer_parameters.py +127 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/power_supply.py +74 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/rigol.py +81 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/rohde_schwarz/__init__.py +11 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/rohde_schwarz/fsek.py +109 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/rohde_schwarz/hmp2030.py +73 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/rohde_schwarz/nrx.py +118 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/rohde_schwarz/zva.py +105 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/scontel.py +220 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/srs.py +91 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/drivers/sumitomo.py +203 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/errors.py +27 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/instrument.py +160 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/limits.py +25 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/quantities.py +376 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/readings.py +50 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/registry.py +124 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/sim/__init__.py +64 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/sim/analyzers.py +115 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/sim/base.py +27 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/sim/chopper.py +64 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/sim/generic.py +52 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/sim/lively.py +38 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/sim/power_meter.py +123 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/sim/power_supply.py +96 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/sim/rotator.py +23 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/sim/signal_generator.py +104 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/sim/sis_block.py +133 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/sim/temperature.py +37 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/sim/vacuum.py +53 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/sim/yig_filter.py +51 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/sis_block.py +16 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/state.py +46 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/transport/__init__.py +52 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/transport/base.py +391 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/transport/fake.py +76 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/transport/http.py +81 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/transport/links.py +286 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/transport/modbus.py +102 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/transport/pool.py +227 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/transport/prologix.py +78 -0
- thzdaq_instruments-0.0.6b4/src/thzdaq_instruments/units.py +121 -0
- thzdaq_instruments-0.0.6b4/tests/conftest.py +5 -0
- thzdaq_instruments-0.0.6b4/tests/contracts.py +448 -0
- thzdaq_instruments-0.0.6b4/tests/emulators.py +579 -0
- thzdaq_instruments-0.0.6b4/tests/test_actions.py +68 -0
- thzdaq_instruments-0.0.6b4/tests/test_contracts.py +21 -0
- thzdaq_instruments-0.0.6b4/tests/test_drivers.py +626 -0
- thzdaq_instruments-0.0.6b4/tests/test_drivers_extra.py +474 -0
- thzdaq_instruments-0.0.6b4/tests/test_generic.py +95 -0
- thzdaq_instruments-0.0.6b4/tests/test_instrument_registry.py +192 -0
- thzdaq_instruments-0.0.6b4/tests/test_limits.py +79 -0
- thzdaq_instruments-0.0.6b4/tests/test_quantities.py +118 -0
- thzdaq_instruments-0.0.6b4/tests/test_recovery.py +258 -0
- thzdaq_instruments-0.0.6b4/tests/test_sim_lively.py +43 -0
- thzdaq_instruments-0.0.6b4/tests/test_simulators_units.py +91 -0
- thzdaq_instruments-0.0.6b4/tests/test_transport.py +286 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.idea
|
|
2
|
+
venv
|
|
3
|
+
.venv
|
|
4
|
+
.uv-cache
|
|
5
|
+
build
|
|
6
|
+
dist
|
|
7
|
+
*__pycache__
|
|
8
|
+
*.log
|
|
9
|
+
*.DS_Store
|
|
10
|
+
*.spec
|
|
11
|
+
!ThzDAQ.spec
|
|
12
|
+
*.ipynb
|
|
13
|
+
.env
|
|
14
|
+
/data/
|
|
15
|
+
# What a daemon run from sources keeps between runs
|
|
16
|
+
/daemon.json
|
|
17
|
+
/daemon-sim.json
|
|
18
|
+
# Window layout and perspectives of a local run
|
|
19
|
+
/settings.ini
|
|
20
|
+
# What a daemon run from sources keeps of instruments (a grid's angle)
|
|
21
|
+
/state.json
|
|
22
|
+
/state-sim.json
|
|
23
|
+
# The program's own measurements and the profiles' previous versions
|
|
24
|
+
/measurements/
|
|
25
|
+
stations/.history/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 yarvod
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: thzdaq-instruments
|
|
3
|
+
Version: 0.0.6b4
|
|
4
|
+
Summary: Laboratory instrument drivers, transports and simulators for ThzDAQ
|
|
5
|
+
Project-URL: Homepage, https://github.com/yarvod/ThzDAQ
|
|
6
|
+
Project-URL: Documentation, https://github.com/yarvod/ThzDAQ/blob/master/docs/daemon.md
|
|
7
|
+
Project-URL: Issues, https://github.com/yarvod/ThzDAQ/issues
|
|
8
|
+
Project-URL: Releases, https://github.com/yarvod/ThzDAQ/releases
|
|
9
|
+
Author: yarvod
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Requires-Dist: pymodbus<3.9,>=3.8
|
|
21
|
+
Requires-Dist: pyserial>=3.5
|
|
22
|
+
Requires-Dist: requests>=2.31
|
|
23
|
+
Provides-Extra: visa
|
|
24
|
+
Requires-Dist: pyvisa>=1.13; extra == 'visa'
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# thzdaq-instruments
|
|
28
|
+
|
|
29
|
+
Instrument layer of ThzDAQ without any GUI dependency:
|
|
30
|
+
|
|
31
|
+
- `capabilities` — small interfaces by instrument ability (`Switchable`, `VoltageSource`,
|
|
32
|
+
`FrequencySource`, `PowerDetector`, ...). Measurements depend on these, not on vendors.
|
|
33
|
+
- `transport` — message links (TCP socket, serial), Prologix GPIB addressing, a pool that shares
|
|
34
|
+
one physical connection between instruments and serializes access with a lock.
|
|
35
|
+
- `instrument` — `Instrument`, `ScpiInstrument` and `Channel` base classes.
|
|
36
|
+
- `registry` — driver catalog: key → class, capabilities are derived from the class.
|
|
37
|
+
- `drivers` — Rigol DP832A, R&S HMP2030 / NRX / ZVA67 / FSEK30, Keithley 2200,
|
|
38
|
+
Agilent E8247C, Scontel SIS block, NI YIG (HTTP), Modbus chopper, LakeShore 336,
|
|
39
|
+
SRS SR830, Sumitomo F-70 (RS-232 and REST), Pfeiffer TC 110 and gauges (RS-485),
|
|
40
|
+
Arduino wire grid.
|
|
41
|
+
- GPIB through Prologix Ethernet/USB, or any VISA resource with the `visa` extra
|
|
42
|
+
(`pip install thzdaq-instruments[visa]`).
|
|
43
|
+
- `sim` — simulators for every capability, used for tests and running without hardware.
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from thzdaq_instruments import default_registry
|
|
47
|
+
from thzdaq_instruments.drivers import RigolDP832A
|
|
48
|
+
|
|
49
|
+
registry = default_registry()
|
|
50
|
+
supply = registry.open("rigol.dp832a", RigolDP832A.connection("169.254.0.14"))
|
|
51
|
+
if_switch = supply.channel(2) # Switchable + VoltageSource + ...
|
|
52
|
+
if_switch.set_output(True)
|
|
53
|
+
supply.close()
|
|
54
|
+
|
|
55
|
+
sim = registry.open("rigol.dp832a", simulate=True) # same shape, no hardware
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Units: SI everywhere (Hz, V, A, K, s), power in dBm.
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
uv run --package thzdaq-instruments pytest packages/thzdaq-instruments
|
|
62
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# thzdaq-instruments
|
|
2
|
+
|
|
3
|
+
Instrument layer of ThzDAQ without any GUI dependency:
|
|
4
|
+
|
|
5
|
+
- `capabilities` — small interfaces by instrument ability (`Switchable`, `VoltageSource`,
|
|
6
|
+
`FrequencySource`, `PowerDetector`, ...). Measurements depend on these, not on vendors.
|
|
7
|
+
- `transport` — message links (TCP socket, serial), Prologix GPIB addressing, a pool that shares
|
|
8
|
+
one physical connection between instruments and serializes access with a lock.
|
|
9
|
+
- `instrument` — `Instrument`, `ScpiInstrument` and `Channel` base classes.
|
|
10
|
+
- `registry` — driver catalog: key → class, capabilities are derived from the class.
|
|
11
|
+
- `drivers` — Rigol DP832A, R&S HMP2030 / NRX / ZVA67 / FSEK30, Keithley 2200,
|
|
12
|
+
Agilent E8247C, Scontel SIS block, NI YIG (HTTP), Modbus chopper, LakeShore 336,
|
|
13
|
+
SRS SR830, Sumitomo F-70 (RS-232 and REST), Pfeiffer TC 110 and gauges (RS-485),
|
|
14
|
+
Arduino wire grid.
|
|
15
|
+
- GPIB through Prologix Ethernet/USB, or any VISA resource with the `visa` extra
|
|
16
|
+
(`pip install thzdaq-instruments[visa]`).
|
|
17
|
+
- `sim` — simulators for every capability, used for tests and running without hardware.
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from thzdaq_instruments import default_registry
|
|
21
|
+
from thzdaq_instruments.drivers import RigolDP832A
|
|
22
|
+
|
|
23
|
+
registry = default_registry()
|
|
24
|
+
supply = registry.open("rigol.dp832a", RigolDP832A.connection("169.254.0.14"))
|
|
25
|
+
if_switch = supply.channel(2) # Switchable + VoltageSource + ...
|
|
26
|
+
if_switch.set_output(True)
|
|
27
|
+
supply.close()
|
|
28
|
+
|
|
29
|
+
sim = registry.open("rigol.dp832a", simulate=True) # same shape, no hardware
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Units: SI everywhere (Hz, V, A, K, s), power in dBm.
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
uv run --package thzdaq-instruments pytest packages/thzdaq-instruments
|
|
36
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "thzdaq-instruments"
|
|
3
|
+
version = "0.0.6b4"
|
|
4
|
+
description = "Laboratory instrument drivers, transports and simulators for ThzDAQ"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [{ name = "yarvod" }]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 3 - Alpha",
|
|
12
|
+
"Intended Audience :: Science/Research",
|
|
13
|
+
"Operating System :: OS Independent",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Topic :: Scientific/Engineering :: Physics",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"pymodbus>=3.8,<3.9",
|
|
21
|
+
"pyserial>=3.5",
|
|
22
|
+
"requests>=2.31",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.urls]
|
|
26
|
+
Homepage = "https://github.com/yarvod/ThzDAQ"
|
|
27
|
+
Documentation = "https://github.com/yarvod/ThzDAQ/blob/master/docs/daemon.md"
|
|
28
|
+
Issues = "https://github.com/yarvod/ThzDAQ/issues"
|
|
29
|
+
Releases = "https://github.com/yarvod/ThzDAQ/releases"
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
visa = ["pyvisa>=1.13"]
|
|
33
|
+
|
|
34
|
+
[dependency-groups]
|
|
35
|
+
dev = [
|
|
36
|
+
"pytest>=8.2",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[build-system]
|
|
40
|
+
requires = ["hatchling>=1.27"]
|
|
41
|
+
build-backend = "hatchling.build"
|
|
42
|
+
|
|
43
|
+
[tool.hatch.build.targets.wheel]
|
|
44
|
+
packages = ["src/thzdaq_instruments"]
|
|
45
|
+
|
|
46
|
+
[tool.pytest.ini_options]
|
|
47
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""ThzDAQ instrument layer: capabilities, transports, drivers and simulators."""
|
|
2
|
+
|
|
3
|
+
from thzdaq_instruments.errors import (
|
|
4
|
+
ConfigurationError,
|
|
5
|
+
InstrumentConnectionError,
|
|
6
|
+
InstrumentError,
|
|
7
|
+
InstrumentResponseError,
|
|
8
|
+
InstrumentTimeoutError,
|
|
9
|
+
UnknownDriverError,
|
|
10
|
+
)
|
|
11
|
+
from thzdaq_instruments.instrument import Channel, Instrument, ScpiInstrument
|
|
12
|
+
from thzdaq_instruments.readings import ChannelReading
|
|
13
|
+
from thzdaq_instruments.registry import DriverInfo, DriverRegistry, default_registry
|
|
14
|
+
from thzdaq_instruments.transport import ConnectionSpec, TransportPool, default_pool
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"Channel",
|
|
18
|
+
"ChannelReading",
|
|
19
|
+
"ConfigurationError",
|
|
20
|
+
"ConnectionSpec",
|
|
21
|
+
"DriverInfo",
|
|
22
|
+
"DriverRegistry",
|
|
23
|
+
"Instrument",
|
|
24
|
+
"InstrumentConnectionError",
|
|
25
|
+
"InstrumentError",
|
|
26
|
+
"InstrumentResponseError",
|
|
27
|
+
"InstrumentTimeoutError",
|
|
28
|
+
"ScpiInstrument",
|
|
29
|
+
"TransportPool",
|
|
30
|
+
"UnknownDriverError",
|
|
31
|
+
"default_pool",
|
|
32
|
+
"default_registry",
|
|
33
|
+
]
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"""Actions: what a device does on request, beyond setting a quantity.
|
|
2
|
+
|
|
3
|
+
Like quantities, actions come from capabilities (a load switch turns to the
|
|
4
|
+
hot or the cold load, an analyzer reads a trace) and drivers add their own
|
|
5
|
+
(the chopper's continuous rotation) with the ``actions`` class attribute. An
|
|
6
|
+
action takes arguments with units and may return a result (a trace). One that
|
|
7
|
+
can harm the bench carries a warning, shown before it runs.
|
|
8
|
+
|
|
9
|
+
A rotator's angle is a settable quantity; one that counts its angle (no
|
|
10
|
+
readback) also sets its zero where it stands.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from dataclasses import dataclass
|
|
14
|
+
from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Tuple
|
|
15
|
+
|
|
16
|
+
from thzdaq_instruments import capabilities as caps
|
|
17
|
+
from thzdaq_instruments.quantities import Kind, by_key, declared, parse_as
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class Argument:
|
|
22
|
+
key: str
|
|
23
|
+
title: str
|
|
24
|
+
unit: str = "" # SI symbol, as quantities
|
|
25
|
+
kind: Kind = "float"
|
|
26
|
+
default: Any = None # None: the argument is required
|
|
27
|
+
minimum: Optional[float] = None
|
|
28
|
+
maximum: Optional[float] = None
|
|
29
|
+
choices: Tuple[Any, ...] = ()
|
|
30
|
+
|
|
31
|
+
def parse(self, value: Any) -> Any:
|
|
32
|
+
return parse_as(self, value)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True)
|
|
36
|
+
class Action:
|
|
37
|
+
key: str
|
|
38
|
+
title: str
|
|
39
|
+
call: Callable[..., Any] # call(target, **arguments)
|
|
40
|
+
arguments: Tuple[Argument, ...] = ()
|
|
41
|
+
danger: str = "" # what may go wrong, shown before it runs; empty when safe
|
|
42
|
+
# A read changes nothing on the device: a measurement sweeping it is not disturbed
|
|
43
|
+
changes: bool = True
|
|
44
|
+
help: str = ""
|
|
45
|
+
|
|
46
|
+
def bind(self, given: Mapping[str, Any]) -> Dict[str, Any]:
|
|
47
|
+
"""The arguments as given (a text may carry its unit), parsed, with the
|
|
48
|
+
defaults filled in; ValueError names what is wrong."""
|
|
49
|
+
known = {argument.key for argument in self.arguments}
|
|
50
|
+
unknown = sorted(set(given) - known)
|
|
51
|
+
if unknown:
|
|
52
|
+
raise ValueError(f"{self.key}: unknown arguments {unknown}")
|
|
53
|
+
values = {}
|
|
54
|
+
for argument in self.arguments:
|
|
55
|
+
if argument.key in given:
|
|
56
|
+
values[argument.key] = argument.parse(given[argument.key])
|
|
57
|
+
elif argument.default is not None:
|
|
58
|
+
values[argument.key] = argument.default
|
|
59
|
+
else:
|
|
60
|
+
raise ValueError(f"{self.key}: {argument.key} is required")
|
|
61
|
+
return values
|
|
62
|
+
|
|
63
|
+
def run(self, target: Any, arguments: Mapping[str, Any]) -> Any:
|
|
64
|
+
return self.call(target, **self.bind(arguments))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _configure_spectrum(target, center: float, span: float) -> None:
|
|
68
|
+
target.set_center_frequency(center)
|
|
69
|
+
target.set_span(span)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _configure_network(
|
|
73
|
+
target, start: float, stop: float, points: int, parameter: str
|
|
74
|
+
) -> None:
|
|
75
|
+
target.set_frequency_range(start, stop)
|
|
76
|
+
target.set_points(points)
|
|
77
|
+
target.select_parameter(parameter)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
TO_HOT = Action("to_hot", "Hot", lambda t: t.to_hot(), help="Turn to the hot load")
|
|
81
|
+
TO_COLD = Action("to_cold", "Cold", lambda t: t.to_cold(), help="Turn to the cold load")
|
|
82
|
+
|
|
83
|
+
TURN_ON = Action(
|
|
84
|
+
"turn_on", "Turn on", lambda t: t.turn_on(),
|
|
85
|
+
danger="Starts the compressor: the cold head runs",
|
|
86
|
+
) # fmt: skip
|
|
87
|
+
TURN_OFF = Action(
|
|
88
|
+
"turn_off", "Turn off", lambda t: t.turn_off(),
|
|
89
|
+
danger="Stops the compressor: the cryostat warms up",
|
|
90
|
+
) # fmt: skip
|
|
91
|
+
|
|
92
|
+
READ_TRACE = Action("read_trace", "Read trace", lambda t: t.read_trace(), changes=False)
|
|
93
|
+
|
|
94
|
+
CONFIGURE_SPECTRUM = Action(
|
|
95
|
+
"configure", "Apply", _configure_spectrum,
|
|
96
|
+
arguments=(
|
|
97
|
+
Argument("center", "Center", "Hz", minimum=0),
|
|
98
|
+
Argument("span", "Span", "Hz", minimum=0),
|
|
99
|
+
),
|
|
100
|
+
help="Center frequency and span of the sweep",
|
|
101
|
+
) # fmt: skip
|
|
102
|
+
|
|
103
|
+
CONFIGURE_NETWORK = Action(
|
|
104
|
+
"configure", "Apply", _configure_network,
|
|
105
|
+
arguments=(
|
|
106
|
+
Argument("start", "Start", "Hz", minimum=0),
|
|
107
|
+
Argument("stop", "Stop", "Hz", minimum=0),
|
|
108
|
+
Argument("points", "Points", kind="int", minimum=2, maximum=100001),
|
|
109
|
+
Argument("parameter", "S-parameter", kind="text", default="S11"),
|
|
110
|
+
),
|
|
111
|
+
help="Frequency range, points and the S-parameter of the sweep",
|
|
112
|
+
) # fmt: skip
|
|
113
|
+
|
|
114
|
+
CAPABILITY_ACTIONS: Dict[type, Tuple[Action, ...]] = {
|
|
115
|
+
caps.LoadSwitch: (TO_HOT, TO_COLD),
|
|
116
|
+
caps.Compressor: (TURN_ON, TURN_OFF),
|
|
117
|
+
caps.SpectrumAnalyzer: (CONFIGURE_SPECTRUM, READ_TRACE),
|
|
118
|
+
caps.NetworkAnalyzer: (CONFIGURE_NETWORK, READ_TRACE),
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
# Chopper (driver and simulator): continuous rotation, the load stays undefined
|
|
122
|
+
START_ROTATION = Action(
|
|
123
|
+
"start_rotation", "Continuous rotation",
|
|
124
|
+
lambda t, frequency: t.start_rotation(frequency),
|
|
125
|
+
arguments=(
|
|
126
|
+
Argument("frequency", "Frequency", "Hz", default=10.0, minimum=0.1, maximum=20.0),
|
|
127
|
+
),
|
|
128
|
+
) # fmt: skip
|
|
129
|
+
STOP_ROTATION = Action("stop", "Stop", lambda t: t.stop(), help="Stop the rotation")
|
|
130
|
+
CHOPPER_ACTIONS = (START_ROTATION, STOP_ROTATION)
|
|
131
|
+
|
|
132
|
+
# A rotator that counts its angle (thzdaq_instruments.angle): a program zero
|
|
133
|
+
ZERO_ANGLE = Action(
|
|
134
|
+
"zero", "Set zero", lambda t: t.zero(),
|
|
135
|
+
help="Where it stands becomes 0°; nothing moves",
|
|
136
|
+
) # fmt: skip
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def actions_for(
|
|
140
|
+
capabilities: Iterable[type], extra: Iterable[Action] = ()
|
|
141
|
+
) -> List[Action]:
|
|
142
|
+
"""Actions of the given capabilities, then the extra (driver) ones."""
|
|
143
|
+
return by_key(CAPABILITY_ACTIONS, capabilities, extra)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def actions_of(target: Any) -> List[Action]:
|
|
147
|
+
"""Actions of a device part: from its capabilities, then its own ones."""
|
|
148
|
+
return actions_for(*declared(target, "actions"))
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""A rotator that knows its angle only by counting its moves (no position
|
|
2
|
+
readback): the wire grid (ArduinoGrid) and its simulator.
|
|
3
|
+
|
|
4
|
+
The count is its kept state (thzdaq_instruments.state): before a move it tells
|
|
5
|
+
where it goes, after it that it stands there. A move that did not end (the
|
|
6
|
+
program stopped, the link broke) leaves the angle unknown: it is not read, and
|
|
7
|
+
a grid that moves by differences does not move, until zero() makes where it
|
|
8
|
+
stands 0°. A move the rotator refused (it answered so) leaves it where it was.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from typing import Any, Mapping, Optional
|
|
12
|
+
|
|
13
|
+
from thzdaq_instruments.actions import ZERO_ANGLE
|
|
14
|
+
from thzdaq_instruments.errors import InstrumentResponseError
|
|
15
|
+
from thzdaq_instruments.state import KeepsState, State
|
|
16
|
+
|
|
17
|
+
ANGLE = "angle" # where it stands, deg; None: unknown
|
|
18
|
+
MOVING_TO = "moving_to" # where a move that has not ended goes
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class AngleUnknown(InstrumentResponseError):
|
|
22
|
+
"""The rotator's angle is not known: a move did not end."""
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class CountedAngle(KeepsState):
|
|
26
|
+
"""Rotator (rotate_to, get_angle) and KeptState of an instrument class;
|
|
27
|
+
the class moves the rotator in _move()."""
|
|
28
|
+
|
|
29
|
+
actions = (ZERO_ANGLE,)
|
|
30
|
+
name: str
|
|
31
|
+
_angle: Optional[float] = 0.0
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def unknown(self) -> str:
|
|
35
|
+
"""Why the angle cannot be read, and what helps."""
|
|
36
|
+
return "angle unknown, a move did not end: set its zero where it stands"
|
|
37
|
+
|
|
38
|
+
def get_angle(self) -> float:
|
|
39
|
+
"""deg; AngleUnknown when a move did not end."""
|
|
40
|
+
if self._angle is None:
|
|
41
|
+
raise AngleUnknown(f"{self.name}: {self.unknown}")
|
|
42
|
+
return self._angle
|
|
43
|
+
|
|
44
|
+
def zero(self) -> None:
|
|
45
|
+
"""Where it stands is 0° from now on; nothing moves."""
|
|
46
|
+
self.set_angle_reference(0.0)
|
|
47
|
+
|
|
48
|
+
def set_angle_reference(self, angle: float) -> None:
|
|
49
|
+
"""Tell where it stands without moving it."""
|
|
50
|
+
self._angle = float(angle)
|
|
51
|
+
self.keep()
|
|
52
|
+
|
|
53
|
+
def rotate_to(self, angle: float) -> float:
|
|
54
|
+
angle = float(angle)
|
|
55
|
+
self.keep({**self.kept_state(), MOVING_TO: angle})
|
|
56
|
+
try:
|
|
57
|
+
self._move(angle)
|
|
58
|
+
except InstrumentResponseError:
|
|
59
|
+
self.keep() # it answered: it has not moved
|
|
60
|
+
raise
|
|
61
|
+
except BaseException:
|
|
62
|
+
self._angle = None # it may have moved part of the way
|
|
63
|
+
self.keep()
|
|
64
|
+
raise
|
|
65
|
+
self._angle = angle
|
|
66
|
+
self.keep()
|
|
67
|
+
return angle
|
|
68
|
+
|
|
69
|
+
def _move(self, angle: float) -> None:
|
|
70
|
+
"""Rotate to angle from where it stands (get_angle(), when it moves by
|
|
71
|
+
differences); InstrumentResponseError when it refused and did not move."""
|
|
72
|
+
raise NotImplementedError
|
|
73
|
+
|
|
74
|
+
def kept_state(self) -> State:
|
|
75
|
+
return {ANGLE: self._angle}
|
|
76
|
+
|
|
77
|
+
def restore_state(self, state: Mapping[str, Any]) -> None:
|
|
78
|
+
stands = state.get(ANGLE)
|
|
79
|
+
moved = MOVING_TO in state or stands is None
|
|
80
|
+
self._angle = None if moved else float(stands)
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"""Instrument abilities as small interfaces.
|
|
2
|
+
|
|
3
|
+
An instrument or a channel implements several of them, consumers depend only on the ones they
|
|
4
|
+
use. Capabilities contain methods only, so ``issubclass(SomeDriver, Switchable)`` works and the
|
|
5
|
+
registry derives a driver's capabilities from its class.
|
|
6
|
+
|
|
7
|
+
Examples:
|
|
8
|
+
power supply channel -> Switchable, VoltageSource, CurrentSource, VoltageCurrentMeter
|
|
9
|
+
SIS bias channel -> VoltageSource, VoltageCurrentMeter
|
|
10
|
+
signal generator -> FrequencySource, PowerLevel, Switchable
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from typing import List, Optional, Protocol, Tuple, runtime_checkable
|
|
14
|
+
|
|
15
|
+
from thzdaq_instruments.readings import ChannelReading, ComplexTrace, Trace
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@runtime_checkable
|
|
19
|
+
class Identifiable(Protocol):
|
|
20
|
+
def identify(self) -> str:
|
|
21
|
+
"""Instrument identification, e.g. the *IDN? answer."""
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@runtime_checkable
|
|
25
|
+
class Switchable(Protocol):
|
|
26
|
+
def set_output(self, value: bool) -> None:
|
|
27
|
+
...
|
|
28
|
+
|
|
29
|
+
def get_output(self) -> bool:
|
|
30
|
+
...
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@runtime_checkable
|
|
34
|
+
class VoltageSource(Protocol):
|
|
35
|
+
def set_voltage(self, voltage: float) -> None:
|
|
36
|
+
"""V"""
|
|
37
|
+
|
|
38
|
+
def get_voltage(self) -> float:
|
|
39
|
+
"""Programmed voltage, V. Use VoltageCurrentMeter.measure() for the actual one."""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@runtime_checkable
|
|
43
|
+
class CurrentSource(Protocol):
|
|
44
|
+
def set_current(self, current: float) -> None:
|
|
45
|
+
"""A, setpoint or limit"""
|
|
46
|
+
|
|
47
|
+
def get_current(self) -> float:
|
|
48
|
+
"""Programmed current, A"""
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@runtime_checkable
|
|
52
|
+
class OutputProtection(Protocol):
|
|
53
|
+
"""A supply output that switches itself off above a voltage or a current
|
|
54
|
+
(OVP, OCP), whatever the program does."""
|
|
55
|
+
|
|
56
|
+
def set_protection(
|
|
57
|
+
self, voltage: Optional[float], current: Optional[float]
|
|
58
|
+
) -> None:
|
|
59
|
+
"""V, A; None leaves that protection as it is."""
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@runtime_checkable
|
|
63
|
+
class VoltageCurrentMeter(Protocol):
|
|
64
|
+
def measure(self) -> ChannelReading:
|
|
65
|
+
...
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@runtime_checkable
|
|
69
|
+
class FrequencySource(Protocol):
|
|
70
|
+
def set_frequency(self, frequency: float) -> None:
|
|
71
|
+
"""Hz"""
|
|
72
|
+
|
|
73
|
+
def get_frequency(self) -> float:
|
|
74
|
+
"""Hz"""
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@runtime_checkable
|
|
78
|
+
class PowerLevel(Protocol):
|
|
79
|
+
def set_power(self, power: float) -> None:
|
|
80
|
+
"""dBm"""
|
|
81
|
+
|
|
82
|
+
def get_power(self) -> float:
|
|
83
|
+
"""dBm"""
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@runtime_checkable
|
|
87
|
+
class PowerDetector(Protocol):
|
|
88
|
+
def read_power(self) -> float:
|
|
89
|
+
"""dBm, raises InstrumentError instead of returning None"""
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@runtime_checkable
|
|
93
|
+
class TunableFilter(Protocol):
|
|
94
|
+
def tune(self, frequency: float) -> float:
|
|
95
|
+
"""Tune to a frequency, Hz. Returns the frequency actually set."""
|
|
96
|
+
|
|
97
|
+
def get_frequency(self) -> Optional[float]:
|
|
98
|
+
"""Hz, the one tuned last (no readback); None before the first tune."""
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@runtime_checkable
|
|
102
|
+
class LoadSwitch(Protocol):
|
|
103
|
+
"""Hot/cold calibration load switch, e.g. a chopper."""
|
|
104
|
+
|
|
105
|
+
def to_hot(self) -> None:
|
|
106
|
+
...
|
|
107
|
+
|
|
108
|
+
def to_cold(self) -> None:
|
|
109
|
+
...
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@runtime_checkable
|
|
113
|
+
class Thermometer(Protocol):
|
|
114
|
+
def read_temperature(self) -> float:
|
|
115
|
+
"""K"""
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@runtime_checkable
|
|
119
|
+
class SpectrumAnalyzer(Protocol):
|
|
120
|
+
def set_center_frequency(self, frequency: float) -> None:
|
|
121
|
+
"""Hz"""
|
|
122
|
+
|
|
123
|
+
def set_span(self, span: float) -> None:
|
|
124
|
+
"""Hz"""
|
|
125
|
+
|
|
126
|
+
def set_resolution_bandwidth(self, bandwidth: float) -> None:
|
|
127
|
+
"""Hz, the nearest supported value is used"""
|
|
128
|
+
|
|
129
|
+
def set_video_bandwidth(self, bandwidth: float) -> None:
|
|
130
|
+
"""Hz, the nearest supported value is used"""
|
|
131
|
+
|
|
132
|
+
def read_peak(self) -> Tuple[float, float]:
|
|
133
|
+
"""(frequency Hz, power dBm) of the highest peak"""
|
|
134
|
+
|
|
135
|
+
def read_trace(self) -> Trace:
|
|
136
|
+
...
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
@runtime_checkable
|
|
140
|
+
class NetworkAnalyzer(Protocol):
|
|
141
|
+
def set_frequency_range(self, start: float, stop: float) -> None:
|
|
142
|
+
"""Hz"""
|
|
143
|
+
|
|
144
|
+
def set_points(self, points: int) -> None:
|
|
145
|
+
...
|
|
146
|
+
|
|
147
|
+
def select_parameter(self, parameter: str) -> None:
|
|
148
|
+
"""Measure this S-parameter ("S11", "S21", ...) as complex data."""
|
|
149
|
+
|
|
150
|
+
def set_averaging(self, count: int) -> None:
|
|
151
|
+
"""Sweep averaging, count <= 1 switches it off."""
|
|
152
|
+
|
|
153
|
+
def read_trace(self) -> ComplexTrace:
|
|
154
|
+
...
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
@runtime_checkable
|
|
158
|
+
class VacuumGauge(Protocol):
|
|
159
|
+
def read_pressure(self) -> float:
|
|
160
|
+
"""Pa"""
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
@runtime_checkable
|
|
164
|
+
class Rotator(Protocol):
|
|
165
|
+
"""Angles in degrees (the one non-SI unit, as on every lab drawing)."""
|
|
166
|
+
|
|
167
|
+
def rotate_to(self, angle: float) -> float:
|
|
168
|
+
"""Rotate to an absolute angle, returns the angle reached."""
|
|
169
|
+
|
|
170
|
+
def get_angle(self) -> float:
|
|
171
|
+
...
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
@runtime_checkable
|
|
175
|
+
class Compressor(Protocol):
|
|
176
|
+
def turn_on(self) -> None:
|
|
177
|
+
...
|
|
178
|
+
|
|
179
|
+
def turn_off(self) -> None:
|
|
180
|
+
...
|
|
181
|
+
|
|
182
|
+
def read_temperatures(self) -> List[float]:
|
|
183
|
+
"""K"""
|
|
184
|
+
|
|
185
|
+
def read_pressures(self) -> List[float]:
|
|
186
|
+
"""Pa, gauge pressure"""
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
@runtime_checkable
|
|
190
|
+
class RawCommands(Protocol):
|
|
191
|
+
"""An instrument that takes commands as text: what its driver does not wrap
|
|
192
|
+
yet is sent as typed, over its link, with nothing checked."""
|
|
193
|
+
|
|
194
|
+
def send_raw(self, command: str, answer: bool) -> Optional[str]:
|
|
195
|
+
"""Send the command; with answer, read and return the answer."""
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
ALL_CAPABILITIES: tuple[type, ...] = (
|
|
199
|
+
Identifiable,
|
|
200
|
+
RawCommands,
|
|
201
|
+
Switchable,
|
|
202
|
+
VoltageSource,
|
|
203
|
+
CurrentSource,
|
|
204
|
+
OutputProtection,
|
|
205
|
+
VoltageCurrentMeter,
|
|
206
|
+
FrequencySource,
|
|
207
|
+
PowerLevel,
|
|
208
|
+
PowerDetector,
|
|
209
|
+
TunableFilter,
|
|
210
|
+
LoadSwitch,
|
|
211
|
+
Thermometer,
|
|
212
|
+
SpectrumAnalyzer,
|
|
213
|
+
NetworkAnalyzer,
|
|
214
|
+
VacuumGauge,
|
|
215
|
+
Rotator,
|
|
216
|
+
Compressor,
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
# How an instrument is reached rather than what it does
|
|
221
|
+
ACCESS: tuple[type, ...] = (Identifiable, RawCommands)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def capabilities_of(cls: type | None) -> tuple[type, ...]:
|
|
225
|
+
if cls is None:
|
|
226
|
+
return ()
|
|
227
|
+
return tuple(
|
|
228
|
+
capability for capability in ALL_CAPABILITIES if issubclass(cls, capability)
|
|
229
|
+
)
|