scietex.hal.current-amplifier 0.3.0__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.
- scietex/hal/current_amplifier/__init__.py +10 -0
- scietex/hal/current_amplifier/base/__init__.py +71 -0
- scietex/hal/current_amplifier/base/capabilities.py +541 -0
- scietex/hal/current_amplifier/base/data.py +88 -0
- scietex/hal/current_amplifier/base/errors.py +47 -0
- scietex/hal/current_amplifier/base/protocol.py +411 -0
- scietex/hal/current_amplifier/py.typed +0 -0
- scietex/hal/current_amplifier/registry.py +66 -0
- scietex/hal/current_amplifier/scietex/__init__.py +5 -0
- scietex/hal/current_amplifier/scietex/ebic/__init__.py +5 -0
- scietex/hal/current_amplifier/scietex/ebic/modbus/__init__.py +5 -0
- scietex/hal/current_amplifier/scietex/ebic/modbus/v1/__init__.py +38 -0
- scietex/hal/current_amplifier/scietex/ebic/modbus/v1/client.py +497 -0
- scietex/hal/current_amplifier/scietex/ebic/modbus/v1/constants.py +108 -0
- scietex/hal/current_amplifier/scietex/ebic/modbus/v1/identity.py +80 -0
- scietex/hal/current_amplifier/scietex/ebic/modbus/v1/relaymap.py +347 -0
- scietex/hal/current_amplifier/scietex/ebic/modbus/v1/semantic.py +690 -0
- scietex/hal/current_amplifier/version.py +1 -0
- scietex_hal_current_amplifier-0.3.0.dist-info/METADATA +393 -0
- scietex_hal_current_amplifier-0.3.0.dist-info/RECORD +24 -0
- scietex_hal_current_amplifier-0.3.0.dist-info/WHEEL +5 -0
- scietex_hal_current_amplifier-0.3.0.dist-info/entry_points.txt +3 -0
- scietex_hal_current_amplifier-0.3.0.dist-info/licenses/LICENSE +21 -0
- scietex_hal_current_amplifier-0.3.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Current amplifier data structures.
|
|
2
|
+
|
|
3
|
+
:class:`AmplifierState` is a snapshot of what the device reports at one moment;
|
|
4
|
+
:class:`FilterSetting` is one entry of the filter list inside it.
|
|
5
|
+
|
|
6
|
+
``None`` means "this driver cannot report the field", not "zero" and not "off".
|
|
7
|
+
A field that is ``None`` has no known value at all, so a caller must check for
|
|
8
|
+
``None`` rather than treating a missing reading as an idle amplifier.
|
|
9
|
+
|
|
10
|
+
Filter fields are device-native engineering units. No unit or scale is invented
|
|
11
|
+
at this layer: a driver that speaks counts or register codes stores the value it
|
|
12
|
+
reads and documents the conversion in the driver.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import msgspec
|
|
16
|
+
|
|
17
|
+
from .capabilities import FilterType
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class FilterSetting(msgspec.Struct, frozen=True, kw_only=True):
|
|
21
|
+
"""One filter in the amplifier's signal path.
|
|
22
|
+
|
|
23
|
+
Attributes:
|
|
24
|
+
type: The filter response the entry configures.
|
|
25
|
+
enabled: Whether this filter is currently switched on. The field is a
|
|
26
|
+
plain ``bool``, not ``bool | None``: a driver either reports the
|
|
27
|
+
filter entry together with its on/off state or omits the entry.
|
|
28
|
+
low_cutoff_hz: Lower cutoff frequency in Hz, or ``None`` when the filter
|
|
29
|
+
has no lower corner or the driver does not report it. A high-pass
|
|
30
|
+
or band-pass filter may report only one corner.
|
|
31
|
+
high_cutoff_hz: Upper cutoff frequency in Hz, or ``None`` when the
|
|
32
|
+
filter has no upper corner or the driver does not report it.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
type: FilterType
|
|
36
|
+
enabled: bool = False
|
|
37
|
+
low_cutoff_hz: float | None = None
|
|
38
|
+
high_cutoff_hz: float | None = None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class AmplifierState(msgspec.Struct, frozen=True, kw_only=True):
|
|
42
|
+
"""A snapshot of the values an amplifier reports.
|
|
43
|
+
|
|
44
|
+
Each field is ``None`` when the driver cannot report it. ``None`` is not
|
|
45
|
+
``0.0`` and not ``False``: an unreported boost gain is unknown, not unity,
|
|
46
|
+
and an unreadable overload flag is unknown, not clear.
|
|
47
|
+
|
|
48
|
+
Attributes:
|
|
49
|
+
output_voltage_v: Output voltage in V, or ``None`` when unreadable.
|
|
50
|
+
output_current_a: Output current in A, or ``None`` when unreadable.
|
|
51
|
+
input_current_a: Input (source) current in A, or ``None`` when
|
|
52
|
+
unreadable.
|
|
53
|
+
boost_gain: Dimensionless boost stage setting, or ``None`` when the
|
|
54
|
+
driver does not report it. ``None`` is not ``1.0``: an unreported
|
|
55
|
+
gain may be anything, while unity is the value the device applies
|
|
56
|
+
at power-on.
|
|
57
|
+
feedback_resistor_ohm: Feedback resistor in ohm, or ``None`` when
|
|
58
|
+
unreadable.
|
|
59
|
+
dc_bias_enabled: Whether DC bias injection is on, or ``None`` when
|
|
60
|
+
unreadable.
|
|
61
|
+
dc_bias_level: DC bias level in device-native units, or ``None`` when
|
|
62
|
+
unreadable.
|
|
63
|
+
bandwidth_hz: Bandwidth in Hz, or ``None`` when unreadable.
|
|
64
|
+
filters: Configured filters, in the order the device reports them.
|
|
65
|
+
input_overcurrent: Input-overcurrent flag, or ``None`` when unreadable.
|
|
66
|
+
output_overload: Output-overload flag, or ``None`` when unreadable.
|
|
67
|
+
input_compensation_enabled: Whether input-capacitance compensation is
|
|
68
|
+
on, or ``None`` when unreadable.
|
|
69
|
+
input_compensation_level: Compensation level in device-native units, or
|
|
70
|
+
``None`` when unreadable.
|
|
71
|
+
inverted: Whether the output polarity is inverted, or ``None`` when
|
|
72
|
+
unreadable.
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
output_voltage_v: float | None = None
|
|
76
|
+
output_current_a: float | None = None
|
|
77
|
+
input_current_a: float | None = None
|
|
78
|
+
boost_gain: float | None = None
|
|
79
|
+
feedback_resistor_ohm: float | None = None
|
|
80
|
+
dc_bias_enabled: bool | None = None
|
|
81
|
+
dc_bias_level: float | None = None
|
|
82
|
+
bandwidth_hz: float | None = None
|
|
83
|
+
filters: tuple[FilterSetting, ...] = ()
|
|
84
|
+
input_overcurrent: bool | None = None
|
|
85
|
+
output_overload: bool | None = None
|
|
86
|
+
input_compensation_enabled: bool | None = None
|
|
87
|
+
input_compensation_level: float | None = None
|
|
88
|
+
inverted: bool | None = None
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Errors shared by current amplifier drivers.
|
|
2
|
+
|
|
3
|
+
These failures are transport-independent: they describe a driver that cannot
|
|
4
|
+
answer for a register or a response that cannot belong to its request, not a bus
|
|
5
|
+
that failed. Transport failures themselves are raised by
|
|
6
|
+
`scietex.hal.serial` and are allowed to propagate unchanged.
|
|
7
|
+
|
|
8
|
+
Classes:
|
|
9
|
+
RegisterMapIncomplete: A register needed by the operation is not mapped.
|
|
10
|
+
UnexpectedResponse: A response cannot belong to the register it answers.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class RegisterMapIncomplete(RuntimeError):
|
|
15
|
+
"""Raised when a register the operation needs has no map entry.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
register: The register the operation needs, by its map name.
|
|
19
|
+
detail: What the map lacks; defaults to the address and function code.
|
|
20
|
+
|
|
21
|
+
Attributes:
|
|
22
|
+
register (str): The register name the message names.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
register: str,
|
|
28
|
+
detail: str = "has no address and function code",
|
|
29
|
+
) -> None:
|
|
30
|
+
self.register = register
|
|
31
|
+
super().__init__(f"{register} {detail}")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class UnexpectedResponse(OSError):
|
|
35
|
+
"""Raised when a response cannot belong to the register it answers.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
register: The register name the response was read for.
|
|
39
|
+
detail: What is wrong with the response, such as its length or unit id.
|
|
40
|
+
|
|
41
|
+
Attributes:
|
|
42
|
+
register (str): The register name the message names.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
def __init__(self, register: str, detail: str) -> None:
|
|
46
|
+
self.register = register
|
|
47
|
+
super().__init__(f"Unexpected response for {register}: {detail}")
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Current amplifier protocol.
|
|
3
|
+
|
|
4
|
+
This module defines the transport-agnostic contract every current amplifier
|
|
5
|
+
driver implements, plus the capability conveniences that tell a caller which
|
|
6
|
+
optional control operations a given amplifier supports. The contract is
|
|
7
|
+
deliberately minimal: a driver must be able to connect, disconnect and read the
|
|
8
|
+
state snapshot. Every control operation beyond that is advertised through
|
|
9
|
+
:attr:`CurrentAmplifierProtocol.capabilities`, so a caller can reject an
|
|
10
|
+
unsupported command before dispatching it instead of catching an exception
|
|
11
|
+
after the fact.
|
|
12
|
+
|
|
13
|
+
Every driver I/O call is a coroutine, because the shared transport is
|
|
14
|
+
asynchronous: callers must ``await`` :meth:`connect`, :meth:`close`,
|
|
15
|
+
:meth:`read_data` and every optional accessor, and an unimplemented optional
|
|
16
|
+
accessor raises ``NotImplementedError`` when awaited. The ``supports_*`` and
|
|
17
|
+
``can_*`` properties are pure capability checks over :attr:`capabilities` and
|
|
18
|
+
stay synchronous.
|
|
19
|
+
|
|
20
|
+
Two failure signals carry different meanings and must not be confused. A
|
|
21
|
+
``NotImplementedError`` raised by an optional method means "this driver does not
|
|
22
|
+
implement that capability": the feature is absent, so the caller should consult
|
|
23
|
+
the capability set and take a different path. A ``None`` field in the snapshot
|
|
24
|
+
returned by :meth:`CurrentAmplifierProtocol.read_data` means "this driver cannot
|
|
25
|
+
report that value": the feature may well exist and be controllable, but the
|
|
26
|
+
current reading is unknown, so the caller must not substitute zero or ``False``.
|
|
27
|
+
|
|
28
|
+
Status indications are an exception to the method-based surface: input
|
|
29
|
+
overcurrent and output overload are read only through ``read_data()`` and have
|
|
30
|
+
no dedicated accessors. :class:`IndicationCapabilities` separates whether the
|
|
31
|
+
signal exists from whether the firmware can read it; ``supports_input_overcurrent``
|
|
32
|
+
and ``supports_output_overload`` answer observability, while the snapshot says
|
|
33
|
+
what the flag currently is.
|
|
34
|
+
|
|
35
|
+
Filter kinds are read from ``capabilities.filters.types``; there is no
|
|
36
|
+
per-kind ``supports_*`` property, so adding a :class:`FilterType` never changes
|
|
37
|
+
this class.
|
|
38
|
+
|
|
39
|
+
The output voltage range is static geometry rather than a controllable feature,
|
|
40
|
+
so it has no ``supports_*`` property either: a caller reads
|
|
41
|
+
``capabilities.output_voltage`` directly. The only adjustable gain in this
|
|
42
|
+
device is the boost stage; the preamp selects one feedback resistor, which fixes
|
|
43
|
+
the transimpedance; the input-current range is derived from that resistor, the
|
|
44
|
+
boost gain and the static clip limits.
|
|
45
|
+
|
|
46
|
+
A fixed, non-selectable bandwidth is read from
|
|
47
|
+
``capabilities.bandwidth.fixed_hz``. It has no ``supports_*`` truth because
|
|
48
|
+
there is nothing to select.
|
|
49
|
+
|
|
50
|
+
Classes:
|
|
51
|
+
CurrentAmplifierProtocol: The runtime-checkable protocol every current
|
|
52
|
+
amplifier driver satisfies.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
from typing import ClassVar, Protocol, runtime_checkable
|
|
56
|
+
|
|
57
|
+
from .capabilities import CurrentAmplifierCapabilities, FilterType
|
|
58
|
+
from .data import AmplifierState, FilterSetting
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@runtime_checkable
|
|
62
|
+
class CurrentAmplifierProtocol(Protocol):
|
|
63
|
+
"""
|
|
64
|
+
Contract implemented by every current amplifier driver.
|
|
65
|
+
|
|
66
|
+
The three core methods are mandatory. Every optional method raises
|
|
67
|
+
``NotImplementedError`` by default and is advertised through
|
|
68
|
+
:attr:`capabilities`; callers must consult the capability set before
|
|
69
|
+
invoking one. Every I/O method is a coroutine; the convenience properties
|
|
70
|
+
are synchronous.
|
|
71
|
+
|
|
72
|
+
Attributes:
|
|
73
|
+
capabilities: What this amplifier can do, grouped by function. A driver
|
|
74
|
+
declares it as a class attribute, so the whole capability set is
|
|
75
|
+
known before an instance connects to hardware.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
capabilities: ClassVar[CurrentAmplifierCapabilities]
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def supports_preamp(self) -> bool:
|
|
82
|
+
"""Whether the preamp exposes feedback-resistor selection."""
|
|
83
|
+
return bool(self.capabilities.preamp.feedback_resistor)
|
|
84
|
+
|
|
85
|
+
@property
|
|
86
|
+
def supports_boost(self) -> bool:
|
|
87
|
+
"""Whether the amplifier exposes boost stage gain selection."""
|
|
88
|
+
return bool(self.capabilities.boost.gain)
|
|
89
|
+
|
|
90
|
+
@property
|
|
91
|
+
def supports_dc_bias(self) -> bool:
|
|
92
|
+
"""Whether the amplifier exposes DC bias injection or its level."""
|
|
93
|
+
return bool(self.capabilities.dc_bias.enabled) or bool(
|
|
94
|
+
self.capabilities.dc_bias.level
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
@property
|
|
98
|
+
def supports_bandwidth(self) -> bool:
|
|
99
|
+
"""Whether the amplifier exposes selectable bandwidth."""
|
|
100
|
+
return bool(self.capabilities.bandwidth)
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def supports_filters(self) -> bool:
|
|
104
|
+
"""Whether the amplifier exposes any signal filter control."""
|
|
105
|
+
filters = self.capabilities.filters
|
|
106
|
+
return bool(filters.types) or bool(filters.enabled) or bool(filters.cutoff)
|
|
107
|
+
|
|
108
|
+
@property
|
|
109
|
+
def supports_input_overcurrent(self) -> bool:
|
|
110
|
+
"""Whether the driver can observe the input-overcurrent signal."""
|
|
111
|
+
return self.capabilities.input_overcurrent.read
|
|
112
|
+
|
|
113
|
+
@property
|
|
114
|
+
def supports_output_overload(self) -> bool:
|
|
115
|
+
"""Whether the driver can observe the output-overload signal."""
|
|
116
|
+
return self.capabilities.output_overload.read
|
|
117
|
+
|
|
118
|
+
@property
|
|
119
|
+
def supports_input_compensation(self) -> bool:
|
|
120
|
+
"""Whether the amplifier exposes input-capacitance compensation."""
|
|
121
|
+
compensation = self.capabilities.input_compensation
|
|
122
|
+
return bool(compensation.enabled) or bool(compensation.level)
|
|
123
|
+
|
|
124
|
+
@property
|
|
125
|
+
def supports_invert_output(self) -> bool:
|
|
126
|
+
"""Whether the amplifier exposes output-polarity inversion."""
|
|
127
|
+
return bool(self.capabilities.invert_output)
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def can_select_preamp(self) -> bool:
|
|
131
|
+
"""Whether the preamp feedback resistance can be written."""
|
|
132
|
+
return self.capabilities.preamp.feedback_resistor.access.write
|
|
133
|
+
|
|
134
|
+
@property
|
|
135
|
+
def can_set_boost(self) -> bool:
|
|
136
|
+
"""Whether the boost stage gain can be written."""
|
|
137
|
+
return self.capabilities.boost.gain.access.write
|
|
138
|
+
|
|
139
|
+
@property
|
|
140
|
+
def can_set_dc_bias(self) -> bool:
|
|
141
|
+
"""Whether DC bias injection or its level can be written."""
|
|
142
|
+
return (
|
|
143
|
+
self.capabilities.dc_bias.enabled.write
|
|
144
|
+
or self.capabilities.dc_bias.level.write
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
@property
|
|
148
|
+
def can_set_bandwidth(self) -> bool:
|
|
149
|
+
"""Whether selectable bandwidth can be written."""
|
|
150
|
+
return self.capabilities.bandwidth.access.write
|
|
151
|
+
|
|
152
|
+
@property
|
|
153
|
+
def can_set_filter(self) -> bool:
|
|
154
|
+
"""Whether a filter can be switched or its cutoff written."""
|
|
155
|
+
return (
|
|
156
|
+
self.capabilities.filters.enabled.write
|
|
157
|
+
or self.capabilities.filters.cutoff.write
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
@property
|
|
161
|
+
def can_set_input_compensation(self) -> bool:
|
|
162
|
+
"""Whether input compensation or its level can be written."""
|
|
163
|
+
return (
|
|
164
|
+
self.capabilities.input_compensation.enabled.write
|
|
165
|
+
or self.capabilities.input_compensation.level.write
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
@property
|
|
169
|
+
def can_set_invert_output(self) -> bool:
|
|
170
|
+
"""Whether output-polarity inversion can be written."""
|
|
171
|
+
return self.capabilities.invert_output.write
|
|
172
|
+
|
|
173
|
+
async def connect(self) -> None:
|
|
174
|
+
"""Open the transport to the amplifier."""
|
|
175
|
+
raise NotImplementedError(f"{type(self).__name__} must implement connect()")
|
|
176
|
+
|
|
177
|
+
async def close(self) -> None:
|
|
178
|
+
"""Close the transport to the amplifier."""
|
|
179
|
+
raise NotImplementedError(f"{type(self).__name__} must implement close()")
|
|
180
|
+
|
|
181
|
+
async def read_data(self) -> AmplifierState:
|
|
182
|
+
"""
|
|
183
|
+
Read a snapshot of the amplifier's current values.
|
|
184
|
+
|
|
185
|
+
Returns:
|
|
186
|
+
AmplifierState: The current snapshot. A field is ``None`` when the
|
|
187
|
+
driver cannot report it.
|
|
188
|
+
"""
|
|
189
|
+
raise NotImplementedError(f"{type(self).__name__} must implement read_data()")
|
|
190
|
+
|
|
191
|
+
async def get_boost_gain(self) -> float:
|
|
192
|
+
"""
|
|
193
|
+
Read the boost stage gain.
|
|
194
|
+
|
|
195
|
+
Returns:
|
|
196
|
+
float: The dimensionless boost gain.
|
|
197
|
+
"""
|
|
198
|
+
raise NotImplementedError(
|
|
199
|
+
f"{type(self).__name__} does not implement get_boost_gain(); "
|
|
200
|
+
"capability: boost.gain"
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
async def set_boost_gain(self, gain: float) -> None:
|
|
204
|
+
"""
|
|
205
|
+
Set the boost stage gain.
|
|
206
|
+
|
|
207
|
+
Args:
|
|
208
|
+
gain: The dimensionless boost gain, normally one of
|
|
209
|
+
``capabilities.boost.gain.options``.
|
|
210
|
+
"""
|
|
211
|
+
raise NotImplementedError(
|
|
212
|
+
f"{type(self).__name__} does not implement set_boost_gain(); "
|
|
213
|
+
"capability: boost.gain"
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
async def get_feedback_resistor(self) -> float:
|
|
217
|
+
"""
|
|
218
|
+
Read the feedback resistor.
|
|
219
|
+
|
|
220
|
+
Returns:
|
|
221
|
+
float: Resistance in ohm.
|
|
222
|
+
"""
|
|
223
|
+
raise NotImplementedError(
|
|
224
|
+
f"{type(self).__name__} does not implement get_feedback_resistor(); "
|
|
225
|
+
"capability: preamp.feedback_resistor"
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
async def select_feedback_resistor(self, resistance_ohm: float) -> None:
|
|
229
|
+
"""
|
|
230
|
+
Select the feedback resistor.
|
|
231
|
+
|
|
232
|
+
Args:
|
|
233
|
+
resistance_ohm: Resistance in ohm.
|
|
234
|
+
"""
|
|
235
|
+
raise NotImplementedError(
|
|
236
|
+
f"{type(self).__name__} does not implement select_feedback_resistor(); "
|
|
237
|
+
"capability: preamp.feedback_resistor"
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
async def get_dc_bias(self) -> bool:
|
|
241
|
+
"""
|
|
242
|
+
Read the DC bias injection state.
|
|
243
|
+
|
|
244
|
+
Returns:
|
|
245
|
+
bool: Whether bias injection is on.
|
|
246
|
+
"""
|
|
247
|
+
raise NotImplementedError(
|
|
248
|
+
f"{type(self).__name__} does not implement get_dc_bias(); "
|
|
249
|
+
"capability: dc_bias.enabled"
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
async def set_dc_bias(self, enabled: bool) -> None:
|
|
253
|
+
"""
|
|
254
|
+
Switch DC bias injection on or off.
|
|
255
|
+
|
|
256
|
+
Args:
|
|
257
|
+
enabled: Whether to turn bias injection on.
|
|
258
|
+
"""
|
|
259
|
+
raise NotImplementedError(
|
|
260
|
+
f"{type(self).__name__} does not implement set_dc_bias(); "
|
|
261
|
+
"capability: dc_bias.enabled"
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
async def get_dc_bias_level(self) -> float:
|
|
265
|
+
"""
|
|
266
|
+
Read the DC bias level.
|
|
267
|
+
|
|
268
|
+
Returns:
|
|
269
|
+
float: Bias level in device-native units.
|
|
270
|
+
"""
|
|
271
|
+
raise NotImplementedError(
|
|
272
|
+
f"{type(self).__name__} does not implement get_dc_bias_level(); "
|
|
273
|
+
"capability: dc_bias.level"
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
async def set_dc_bias_level(self, level: float) -> None:
|
|
277
|
+
"""
|
|
278
|
+
Set the DC bias level.
|
|
279
|
+
|
|
280
|
+
Args:
|
|
281
|
+
level: Bias level in device-native units.
|
|
282
|
+
"""
|
|
283
|
+
raise NotImplementedError(
|
|
284
|
+
f"{type(self).__name__} does not implement set_dc_bias_level(); "
|
|
285
|
+
"capability: dc_bias.level"
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
async def get_bandwidth(self) -> float:
|
|
289
|
+
"""
|
|
290
|
+
Read the bandwidth.
|
|
291
|
+
|
|
292
|
+
Returns:
|
|
293
|
+
float: Bandwidth in Hz.
|
|
294
|
+
"""
|
|
295
|
+
raise NotImplementedError(
|
|
296
|
+
f"{type(self).__name__} does not implement get_bandwidth(); "
|
|
297
|
+
"capability: bandwidth"
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
async def set_bandwidth(self, bandwidth_hz: float) -> None:
|
|
301
|
+
"""
|
|
302
|
+
Set the bandwidth.
|
|
303
|
+
|
|
304
|
+
Args:
|
|
305
|
+
bandwidth_hz: Bandwidth in Hz.
|
|
306
|
+
"""
|
|
307
|
+
raise NotImplementedError(
|
|
308
|
+
f"{type(self).__name__} does not implement set_bandwidth(); "
|
|
309
|
+
"capability: bandwidth"
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
async def get_filter(self, filter_type: FilterType) -> FilterSetting:
|
|
313
|
+
"""
|
|
314
|
+
Read one filter's settings.
|
|
315
|
+
|
|
316
|
+
Args:
|
|
317
|
+
filter_type: The filter response to read.
|
|
318
|
+
|
|
319
|
+
Returns:
|
|
320
|
+
FilterSetting: The filter entry, with its cutoff corners in Hz.
|
|
321
|
+
"""
|
|
322
|
+
raise NotImplementedError(
|
|
323
|
+
f"{type(self).__name__} does not implement get_filter(); "
|
|
324
|
+
"capability: filters"
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
async def set_filter(self, setting: FilterSetting) -> None:
|
|
328
|
+
"""
|
|
329
|
+
Write one filter's settings.
|
|
330
|
+
|
|
331
|
+
Args:
|
|
332
|
+
setting: The filter entry to apply. ``setting.type`` selects the
|
|
333
|
+
filter, ``enabled`` switches it and the cutoff corners set its
|
|
334
|
+
frequency.
|
|
335
|
+
"""
|
|
336
|
+
raise NotImplementedError(
|
|
337
|
+
f"{type(self).__name__} does not implement set_filter(); "
|
|
338
|
+
"capability: filters"
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
async def get_input_compensation(self) -> bool:
|
|
342
|
+
"""
|
|
343
|
+
Read the input-capacitance compensation state.
|
|
344
|
+
|
|
345
|
+
Returns:
|
|
346
|
+
bool: Whether compensation is on.
|
|
347
|
+
"""
|
|
348
|
+
raise NotImplementedError(
|
|
349
|
+
f"{type(self).__name__} does not implement get_input_compensation(); "
|
|
350
|
+
"capability: input_compensation.enabled"
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
async def set_input_compensation(self, enabled: bool) -> None:
|
|
354
|
+
"""
|
|
355
|
+
Switch input-capacitance compensation on or off.
|
|
356
|
+
|
|
357
|
+
Args:
|
|
358
|
+
enabled: Whether to turn compensation on.
|
|
359
|
+
"""
|
|
360
|
+
raise NotImplementedError(
|
|
361
|
+
f"{type(self).__name__} does not implement set_input_compensation(); "
|
|
362
|
+
"capability: input_compensation.enabled"
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
async def get_input_compensation_level(self) -> float:
|
|
366
|
+
"""
|
|
367
|
+
Read the input-compensation level.
|
|
368
|
+
|
|
369
|
+
Returns:
|
|
370
|
+
float: Compensation level in device-native units.
|
|
371
|
+
"""
|
|
372
|
+
raise NotImplementedError(
|
|
373
|
+
f"{type(self).__name__} does not implement "
|
|
374
|
+
"get_input_compensation_level(); capability: input_compensation.level"
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
async def set_input_compensation_level(self, level: float) -> None:
|
|
378
|
+
"""
|
|
379
|
+
Set the input-compensation level.
|
|
380
|
+
|
|
381
|
+
Args:
|
|
382
|
+
level: Compensation level in device-native units.
|
|
383
|
+
"""
|
|
384
|
+
raise NotImplementedError(
|
|
385
|
+
f"{type(self).__name__} does not implement "
|
|
386
|
+
"set_input_compensation_level(); capability: input_compensation.level"
|
|
387
|
+
)
|
|
388
|
+
|
|
389
|
+
async def get_inverted(self) -> bool:
|
|
390
|
+
"""
|
|
391
|
+
Read the output-polarity inversion state.
|
|
392
|
+
|
|
393
|
+
Returns:
|
|
394
|
+
bool: Whether the output is inverted.
|
|
395
|
+
"""
|
|
396
|
+
raise NotImplementedError(
|
|
397
|
+
f"{type(self).__name__} does not implement get_inverted(); "
|
|
398
|
+
"capability: invert_output"
|
|
399
|
+
)
|
|
400
|
+
|
|
401
|
+
async def set_inverted(self, inverted: bool) -> None:
|
|
402
|
+
"""
|
|
403
|
+
Set the output-polarity inversion state.
|
|
404
|
+
|
|
405
|
+
Args:
|
|
406
|
+
inverted: Whether to invert the output.
|
|
407
|
+
"""
|
|
408
|
+
raise NotImplementedError(
|
|
409
|
+
f"{type(self).__name__} does not implement set_inverted(); "
|
|
410
|
+
"capability: invert_output"
|
|
411
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Current amplifier driver registry.
|
|
3
|
+
|
|
4
|
+
Drivers are advertised through the ``scietex.hal.current_amplifier.drivers``
|
|
5
|
+
entry point group declared in this package's ``pyproject.toml``. Consumers
|
|
6
|
+
resolve a driver by its entry point name rather than by a dotted class path, so
|
|
7
|
+
the stored identifier stays stable when modules move.
|
|
8
|
+
|
|
9
|
+
Entry points are read from installed distribution metadata. A driver added to
|
|
10
|
+
the source tree only appears after the package is reinstalled.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from importlib.metadata import entry_points
|
|
14
|
+
from typing import cast
|
|
15
|
+
|
|
16
|
+
from .base.protocol import CurrentAmplifierProtocol
|
|
17
|
+
|
|
18
|
+
ENTRY_POINT_GROUP = "scietex.hal.current_amplifier.drivers"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def discover_drivers() -> dict[str, type[CurrentAmplifierProtocol]]:
|
|
22
|
+
"""
|
|
23
|
+
Map every advertised driver's entry point name to its class.
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
dict[str, type[CurrentAmplifierProtocol]]: Entry point name to driver
|
|
27
|
+
class, sorted by name.
|
|
28
|
+
|
|
29
|
+
Raises:
|
|
30
|
+
TypeError: If an entry point resolves to something that is not a class.
|
|
31
|
+
"""
|
|
32
|
+
discovered: dict[str, type[CurrentAmplifierProtocol]] = {}
|
|
33
|
+
for entry_point in entry_points(group=ENTRY_POINT_GROUP):
|
|
34
|
+
driver = entry_point.load()
|
|
35
|
+
if not isinstance(driver, type):
|
|
36
|
+
raise TypeError(
|
|
37
|
+
f"Entry point {entry_point.name!r} resolved to "
|
|
38
|
+
f"{type(driver).__name__}, not a class"
|
|
39
|
+
)
|
|
40
|
+
discovered[entry_point.name] = cast(type[CurrentAmplifierProtocol], driver)
|
|
41
|
+
return dict(sorted(discovered.items()))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def resolve_driver(name: str) -> type[CurrentAmplifierProtocol]:
|
|
45
|
+
"""
|
|
46
|
+
Resolve a single driver by entry point name.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
name: Entry point name, e.g. ``scietex_modbus_v1``.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
type[CurrentAmplifierProtocol]: The driver class.
|
|
53
|
+
|
|
54
|
+
Raises:
|
|
55
|
+
ValueError: If no advertised driver carries that name. The message
|
|
56
|
+
lists the names that are available.
|
|
57
|
+
"""
|
|
58
|
+
drivers = discover_drivers()
|
|
59
|
+
try:
|
|
60
|
+
return drivers[name]
|
|
61
|
+
except KeyError:
|
|
62
|
+
available = ", ".join(drivers) or "none"
|
|
63
|
+
raise ValueError(
|
|
64
|
+
f"Unknown current amplifier driver {name!r}: not advertised under "
|
|
65
|
+
f"{ENTRY_POINT_GROUP!r}; available: {available}"
|
|
66
|
+
) from None
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""EBIC v1.0 preamp Modbus RTU subpackage.
|
|
2
|
+
|
|
3
|
+
Modules:
|
|
4
|
+
client: Implements the `EBICModbusV1Preamp` relay driver.
|
|
5
|
+
constants: Wire register, coil and identity constants.
|
|
6
|
+
identity: Decodes the device identity from input registers.
|
|
7
|
+
relaymap: Maps relays to amplifier functions and decodes coil readbacks.
|
|
8
|
+
semantic: Implements the `EBICModbusV1Amplifier` contract over the relay map.
|
|
9
|
+
|
|
10
|
+
Exports:
|
|
11
|
+
EBICModbusV1Preamp: The EBIC v1.0 Modbus RTU driver.
|
|
12
|
+
EBICModbusV1Amplifier: The EBIC v1.0 current amplifier contract.
|
|
13
|
+
DeviceIdentity: The vendor, product, version and serial number.
|
|
14
|
+
BaudRate: Baud rates the firmware selects by index.
|
|
15
|
+
RelayAccess: The relay operations the semantic layer needs.
|
|
16
|
+
RelayTransitionError: A relay transition did not reach its target.
|
|
17
|
+
BOOSTER_COILS: Channel to the relay-3 coil that feeds it to the booster.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from .client import EBICModbusV1Preamp
|
|
21
|
+
from .constants import BaudRate
|
|
22
|
+
from .identity import DeviceIdentity
|
|
23
|
+
from .relaymap import BOOSTER_COILS
|
|
24
|
+
from .semantic import (
|
|
25
|
+
EBICModbusV1Amplifier,
|
|
26
|
+
RelayAccess,
|
|
27
|
+
RelayTransitionError,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
"BOOSTER_COILS",
|
|
32
|
+
"BaudRate",
|
|
33
|
+
"DeviceIdentity",
|
|
34
|
+
"EBICModbusV1Amplifier",
|
|
35
|
+
"EBICModbusV1Preamp",
|
|
36
|
+
"RelayAccess",
|
|
37
|
+
"RelayTransitionError",
|
|
38
|
+
]
|