thzdaq-instruments 0.0.6b4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- thzdaq_instruments/__init__.py +33 -0
- thzdaq_instruments/actions.py +148 -0
- thzdaq_instruments/angle.py +80 -0
- thzdaq_instruments/capabilities.py +229 -0
- thzdaq_instruments/drivers/__init__.py +96 -0
- thzdaq_instruments/drivers/agilent.py +123 -0
- thzdaq_instruments/drivers/arduino.py +100 -0
- thzdaq_instruments/drivers/chopper.py +239 -0
- thzdaq_instruments/drivers/generic.py +19 -0
- thzdaq_instruments/drivers/keithley.py +46 -0
- thzdaq_instruments/drivers/lakeshore.py +143 -0
- thzdaq_instruments/drivers/national_instruments.py +98 -0
- thzdaq_instruments/drivers/pfeiffer.py +232 -0
- thzdaq_instruments/drivers/pfeiffer_parameters.py +127 -0
- thzdaq_instruments/drivers/power_supply.py +74 -0
- thzdaq_instruments/drivers/rigol.py +81 -0
- thzdaq_instruments/drivers/rohde_schwarz/__init__.py +11 -0
- thzdaq_instruments/drivers/rohde_schwarz/fsek.py +109 -0
- thzdaq_instruments/drivers/rohde_schwarz/hmp2030.py +73 -0
- thzdaq_instruments/drivers/rohde_schwarz/nrx.py +118 -0
- thzdaq_instruments/drivers/rohde_schwarz/zva.py +105 -0
- thzdaq_instruments/drivers/scontel.py +220 -0
- thzdaq_instruments/drivers/srs.py +91 -0
- thzdaq_instruments/drivers/sumitomo.py +203 -0
- thzdaq_instruments/errors.py +27 -0
- thzdaq_instruments/instrument.py +160 -0
- thzdaq_instruments/limits.py +25 -0
- thzdaq_instruments/quantities.py +376 -0
- thzdaq_instruments/readings.py +50 -0
- thzdaq_instruments/registry.py +124 -0
- thzdaq_instruments/sim/__init__.py +64 -0
- thzdaq_instruments/sim/analyzers.py +115 -0
- thzdaq_instruments/sim/base.py +27 -0
- thzdaq_instruments/sim/chopper.py +64 -0
- thzdaq_instruments/sim/generic.py +52 -0
- thzdaq_instruments/sim/lively.py +38 -0
- thzdaq_instruments/sim/power_meter.py +123 -0
- thzdaq_instruments/sim/power_supply.py +96 -0
- thzdaq_instruments/sim/rotator.py +23 -0
- thzdaq_instruments/sim/signal_generator.py +104 -0
- thzdaq_instruments/sim/sis_block.py +133 -0
- thzdaq_instruments/sim/temperature.py +37 -0
- thzdaq_instruments/sim/vacuum.py +53 -0
- thzdaq_instruments/sim/yig_filter.py +51 -0
- thzdaq_instruments/sis_block.py +16 -0
- thzdaq_instruments/state.py +46 -0
- thzdaq_instruments/transport/__init__.py +52 -0
- thzdaq_instruments/transport/base.py +391 -0
- thzdaq_instruments/transport/fake.py +76 -0
- thzdaq_instruments/transport/http.py +81 -0
- thzdaq_instruments/transport/links.py +286 -0
- thzdaq_instruments/transport/modbus.py +102 -0
- thzdaq_instruments/transport/pool.py +227 -0
- thzdaq_instruments/transport/prologix.py +78 -0
- thzdaq_instruments/units.py +121 -0
- thzdaq_instruments-0.0.6b4.dist-info/METADATA +62 -0
- thzdaq_instruments-0.0.6b4.dist-info/RECORD +59 -0
- thzdaq_instruments-0.0.6b4.dist-info/WHEEL +4 -0
- thzdaq_instruments-0.0.6b4.dist-info/licenses/LICENSE +21 -0
|
@@ -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
|
+
)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from thzdaq_instruments.drivers.agilent import AgilentE8247C
|
|
2
|
+
from thzdaq_instruments.drivers.arduino import ArduinoGrid
|
|
3
|
+
from thzdaq_instruments.drivers.chopper import ModbusChopper
|
|
4
|
+
from thzdaq_instruments.drivers.generic import GenericScpi
|
|
5
|
+
from thzdaq_instruments.drivers.keithley import Keithley2200
|
|
6
|
+
from thzdaq_instruments.drivers.lakeshore import (
|
|
7
|
+
HeaterOutput,
|
|
8
|
+
LakeShore336,
|
|
9
|
+
TemperatureInput,
|
|
10
|
+
)
|
|
11
|
+
from thzdaq_instruments.drivers.national_instruments import NiYigFilter, YigChannel
|
|
12
|
+
|
|
13
|
+
# Pfeiffer (drivers/pfeiffer.py) is disabled: not used on the bench, to be rewritten
|
|
14
|
+
from thzdaq_instruments.drivers.power_supply import ScpiPowerSupply, SupplyChannel
|
|
15
|
+
from thzdaq_instruments.drivers.rigol import RigolDP832A
|
|
16
|
+
from thzdaq_instruments.drivers.rohde_schwarz import (
|
|
17
|
+
RohdeSchwarzFSEK30,
|
|
18
|
+
RohdeSchwarzHMP2030,
|
|
19
|
+
RohdeSchwarzNRX,
|
|
20
|
+
RohdeSchwarzZVA67,
|
|
21
|
+
)
|
|
22
|
+
from thzdaq_instruments.drivers.scontel import (
|
|
23
|
+
ScontelSisBlock,
|
|
24
|
+
SisBiasChannel,
|
|
25
|
+
SisCtrlChannel,
|
|
26
|
+
)
|
|
27
|
+
from thzdaq_instruments.drivers.srs import StanfordSR830
|
|
28
|
+
from thzdaq_instruments.drivers.sumitomo import SumitomoF70, SumitomoF70Rest
|
|
29
|
+
from thzdaq_instruments.sim import (
|
|
30
|
+
SimChopper,
|
|
31
|
+
SimCompressor,
|
|
32
|
+
SimGenericScpi,
|
|
33
|
+
SimNetworkAnalyzer,
|
|
34
|
+
SimPowerMeter,
|
|
35
|
+
SimPowerSupply,
|
|
36
|
+
SimRotator,
|
|
37
|
+
SimSignalGenerator,
|
|
38
|
+
SimSisBlock,
|
|
39
|
+
SimSpectrumAnalyzer,
|
|
40
|
+
SimTemperatureController,
|
|
41
|
+
SimYigFilter,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
# Built-in drivers: class (with its driver_key), title, simulator
|
|
45
|
+
DRIVERS = (
|
|
46
|
+
(RigolDP832A, "Rigol DP832A power supply", SimPowerSupply),
|
|
47
|
+
(RohdeSchwarzHMP2030, "R&S HMP2030 power supply", SimPowerSupply),
|
|
48
|
+
(Keithley2200, "Keithley 2200 power supply", SimPowerSupply),
|
|
49
|
+
(AgilentE8247C, "Agilent E8247C signal generator", SimSignalGenerator),
|
|
50
|
+
(RohdeSchwarzNRX, "R&S NRX power meter", SimPowerMeter),
|
|
51
|
+
(ScontelSisBlock, "Scontel SIS bias block", SimSisBlock),
|
|
52
|
+
(NiYigFilter, "NI digital YIG filters", SimYigFilter),
|
|
53
|
+
(ModbusChopper, "Modbus chopper", SimChopper),
|
|
54
|
+
(RohdeSchwarzZVA67, "R&S ZVA67 network analyzer", SimNetworkAnalyzer),
|
|
55
|
+
(RohdeSchwarzFSEK30, "R&S FSEK30 spectrum analyzer", SimSpectrumAnalyzer),
|
|
56
|
+
(LakeShore336, "LakeShore 336 temperature controller", SimTemperatureController),
|
|
57
|
+
(StanfordSR830, "SRS SR830 lock-in amplifier", None),
|
|
58
|
+
(SumitomoF70, "Sumitomo F-70 compressor (RS-232)", SimCompressor),
|
|
59
|
+
(SumitomoF70Rest, "Sumitomo F-70 compressor (REST)", SimCompressor),
|
|
60
|
+
(ArduinoGrid, "Arduino wire grid rotator", SimRotator),
|
|
61
|
+
(GenericScpi, "Generic instrument: text commands (SCPI)", SimGenericScpi),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def register_drivers(registry) -> None:
|
|
66
|
+
for cls, title, sim in DRIVERS:
|
|
67
|
+
registry.register(cls.driver_key, cls, title=title, sim=sim)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
__all__ = [
|
|
71
|
+
"DRIVERS",
|
|
72
|
+
"AgilentE8247C",
|
|
73
|
+
"ArduinoGrid",
|
|
74
|
+
"GenericScpi",
|
|
75
|
+
"HeaterOutput",
|
|
76
|
+
"LakeShore336",
|
|
77
|
+
"RohdeSchwarzFSEK30",
|
|
78
|
+
"RohdeSchwarzZVA67",
|
|
79
|
+
"StanfordSR830",
|
|
80
|
+
"SumitomoF70",
|
|
81
|
+
"SumitomoF70Rest",
|
|
82
|
+
"TemperatureInput",
|
|
83
|
+
"Keithley2200",
|
|
84
|
+
"ModbusChopper",
|
|
85
|
+
"NiYigFilter",
|
|
86
|
+
"RigolDP832A",
|
|
87
|
+
"RohdeSchwarzHMP2030",
|
|
88
|
+
"RohdeSchwarzNRX",
|
|
89
|
+
"ScontelSisBlock",
|
|
90
|
+
"ScpiPowerSupply",
|
|
91
|
+
"SisBiasChannel",
|
|
92
|
+
"SisCtrlChannel",
|
|
93
|
+
"SupplyChannel",
|
|
94
|
+
"YigChannel",
|
|
95
|
+
"register_drivers",
|
|
96
|
+
]
|