scietex.hal.current-amplifier 0.3.0__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.
- scietex_hal_current_amplifier-0.3.0/LICENSE +21 -0
- scietex_hal_current_amplifier-0.3.0/MANIFEST.in +5 -0
- scietex_hal_current_amplifier-0.3.0/PKG-INFO +393 -0
- scietex_hal_current_amplifier-0.3.0/README.md +359 -0
- scietex_hal_current_amplifier-0.3.0/pyproject.toml +68 -0
- scietex_hal_current_amplifier-0.3.0/setup.cfg +4 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/__init__.py +10 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/base/__init__.py +71 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/base/capabilities.py +541 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/base/data.py +88 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/base/errors.py +47 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/base/protocol.py +411 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/py.typed +0 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/registry.py +66 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/scietex/__init__.py +5 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/scietex/ebic/__init__.py +5 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/scietex/ebic/modbus/__init__.py +5 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/scietex/ebic/modbus/v1/__init__.py +38 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/scietex/ebic/modbus/v1/client.py +497 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/scietex/ebic/modbus/v1/constants.py +108 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/scietex/ebic/modbus/v1/identity.py +80 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/scietex/ebic/modbus/v1/relaymap.py +347 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/scietex/ebic/modbus/v1/semantic.py +690 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex/hal/current_amplifier/version.py +1 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex.hal.current_amplifier.egg-info/PKG-INFO +393 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex.hal.current_amplifier.egg-info/SOURCES.txt +39 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex.hal.current_amplifier.egg-info/dependency_links.txt +1 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex.hal.current_amplifier.egg-info/entry_points.txt +3 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex.hal.current_amplifier.egg-info/requires.txt +14 -0
- scietex_hal_current_amplifier-0.3.0/src/scietex.hal.current_amplifier.egg-info/top_level.txt +1 -0
- scietex_hal_current_amplifier-0.3.0/tests/base/test_capabilities.py +402 -0
- scietex_hal_current_amplifier-0.3.0/tests/base/test_data.py +126 -0
- scietex_hal_current_amplifier-0.3.0/tests/base/test_protocol.py +372 -0
- scietex_hal_current_amplifier-0.3.0/tests/conftest.py +6 -0
- scietex_hal_current_amplifier-0.3.0/tests/fakes.py +269 -0
- scietex_hal_current_amplifier-0.3.0/tests/scietex/ebic/modbus/v1/test_client.py +663 -0
- scietex_hal_current_amplifier-0.3.0/tests/scietex/ebic/modbus/v1/test_constants.py +116 -0
- scietex_hal_current_amplifier-0.3.0/tests/scietex/ebic/modbus/v1/test_identity.py +102 -0
- scietex_hal_current_amplifier-0.3.0/tests/scietex/ebic/modbus/v1/test_relaymap.py +241 -0
- scietex_hal_current_amplifier-0.3.0/tests/scietex/ebic/modbus/v1/test_semantic.py +921 -0
- scietex_hal_current_amplifier-0.3.0/tests/test_registry.py +65 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Anton Bondarenko
|
|
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,393 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: scietex.hal.current_amplifier
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Scietex current amplifier HAL package
|
|
5
|
+
Author-email: Anton Bondarenko <bond.anton@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/bond-anton/scietex.hal.current_amplifier
|
|
8
|
+
Project-URL: Repository, https://github.com/bond-anton/scietex.hal.current_amplifier
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/bond-anton/scietex.hal.current_amplifier/issues
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: msgspec~=0.20.0
|
|
23
|
+
Requires-Dist: scietex.hal.serial<3.0.0,>=2.5.0
|
|
24
|
+
Requires-Dist: pymodbus<3.16,>=3.15
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: tox>=4.46.0; extra == "dev"
|
|
27
|
+
Provides-Extra: test
|
|
28
|
+
Requires-Dist: pytest; extra == "test"
|
|
29
|
+
Requires-Dist: pytest-asyncio; extra == "test"
|
|
30
|
+
Provides-Extra: lint
|
|
31
|
+
Requires-Dist: ruff; extra == "lint"
|
|
32
|
+
Requires-Dist: ty; extra == "lint"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# scietex.hal.current_amplifier
|
|
36
|
+
|
|
37
|
+
A Python library for current amplifiers: devices that convert a photodiode or
|
|
38
|
+
ion-collector current into a voltage through a transimpedance preamp, an optional
|
|
39
|
+
boost stage, DC bias injection, filtering and input-capacitance compensation.
|
|
40
|
+
|
|
41
|
+
The package is split in two layers. The capability model and the driver contract
|
|
42
|
+
in `scietex.hal.current_amplifier.base` are complete: they describe what an
|
|
43
|
+
amplifier can do, what it currently reads, and the asynchronous methods a driver
|
|
44
|
+
implements. Two drivers target the EBIC v1.0 preamp over Modbus RTU:
|
|
45
|
+
|
|
46
|
+
- `EBICModbusV1Preamp` (entry point `ebic_modbus_v1_preamp`) is the raw relay
|
|
47
|
+
driver: it exposes the seventeen relay coils and the communication settings,
|
|
48
|
+
which is what the firmware implements. Its state snapshot is empty and it
|
|
49
|
+
declares only the static analog geometry — the pre-amp +/-5 V clip point, the
|
|
50
|
+
booster +/-10 V linear range, and the presence of the Overcurrent comparator.
|
|
51
|
+
- `EBICModbusV1Amplifier` (entry point `ebic_modbus_v1`) is the semantic layer
|
|
52
|
+
built on those coils. It owns the relay-to-function map and implements the
|
|
53
|
+
amplifier contract: feedback resistor, boost gain, DC bias enable and input
|
|
54
|
+
compensation enable are selectable and readable, and `read_data()` decodes the
|
|
55
|
+
coil pattern into an `AmplifierState`.
|
|
56
|
+
|
|
57
|
+
The relay-to-function map is documented in
|
|
58
|
+
[docs/relay-function-map.md](docs/relay-function-map.md). The semantic layer still
|
|
59
|
+
cannot report or control what the board does not expose: bandwidth, filters,
|
|
60
|
+
output inversion, bias level, compensation level and every measurement stay
|
|
61
|
+
unsupported, with `None` fields in the state rather than invented values.
|
|
62
|
+
|
|
63
|
+
## Status
|
|
64
|
+
|
|
65
|
+
| Layer | State |
|
|
66
|
+
| --- | --- |
|
|
67
|
+
| Capability model (`base.capabilities`) | Complete |
|
|
68
|
+
| State snapshot (`base.data`) | Complete |
|
|
69
|
+
| Driver contract (`base.protocol`) | Complete |
|
|
70
|
+
| Driver registry (`registry`) | Complete, two drivers advertised |
|
|
71
|
+
| EBIC v1.0 preamp (`scietex.ebic.modbus.v1`) | Complete: relay driver plus semantic amplifier |
|
|
72
|
+
| Semantic amplifier (`EBICModbusV1Amplifier`) | Complete: Rf, boost gain, bias and compensation enables, state decode |
|
|
73
|
+
|
|
74
|
+
## Install
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install scietex.hal.current_amplifier
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The package is not on PyPI yet; install from a clone in the meantime:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
git clone https://github.com/bond-anton/scietex.hal.current_amplifier.git
|
|
84
|
+
cd scietex.hal.current_amplifier
|
|
85
|
+
pip install .
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Requirements:
|
|
89
|
+
|
|
90
|
+
- Python 3.10 or higher.
|
|
91
|
+
- `msgspec` 0.20 for the state snapshot.
|
|
92
|
+
- `scietex.hal.serial` 2.5 or newer for the asynchronous RS485 transport.
|
|
93
|
+
- `pymodbus` 3.15 for the Modbus request types.
|
|
94
|
+
|
|
95
|
+
## Usage
|
|
96
|
+
|
|
97
|
+
Every driver satisfies `CurrentAmplifierProtocol`: `connect`, `close` and
|
|
98
|
+
`read_data` are mandatory coroutines, and every optional control method is a
|
|
99
|
+
coroutine too. The `supports_*` and `can_*` properties are synchronous and read
|
|
100
|
+
straight from `capabilities`, so a caller rejects an unsupported command before
|
|
101
|
+
dispatching it.
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
import asyncio
|
|
105
|
+
|
|
106
|
+
from scietex.hal.current_amplifier.base import CurrentAmplifierProtocol
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
async def main(amp: CurrentAmplifierProtocol) -> None:
|
|
110
|
+
"""Read one snapshot and normalise the boost stage."""
|
|
111
|
+
await amp.connect()
|
|
112
|
+
try:
|
|
113
|
+
state = await amp.read_data()
|
|
114
|
+
print(state.output_voltage_v, state.output_current_a, state.input_current_a)
|
|
115
|
+
|
|
116
|
+
if amp.can_set_boost:
|
|
117
|
+
await amp.set_boost_gain(amp.capabilities.boost.default_gain)
|
|
118
|
+
finally:
|
|
119
|
+
await amp.close()
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
asyncio.run(main(amplifier))
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`amplifier` is a driver instance. With the raw `EBICModbusV1Preamp`,
|
|
126
|
+
`read_data()` returns an empty snapshot and commands go through its relay
|
|
127
|
+
methods; use the semantic `EBICModbusV1Amplifier` when you want the amplifier
|
|
128
|
+
contract. It drives the same coils through the function map:
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from scietex.hal.current_amplifier.scietex.ebic.modbus.v1 import (
|
|
132
|
+
EBICModbusV1Amplifier,
|
|
133
|
+
)
|
|
134
|
+
from scietex.hal.serial import ModbusSerialConnectionConfig
|
|
135
|
+
|
|
136
|
+
amp = EBICModbusV1Amplifier(
|
|
137
|
+
ModbusSerialConnectionConfig(port="/dev/ttyUSB0", framer="RTU"),
|
|
138
|
+
relay_settle_s=0.008, # 8 ms engage barrier; 0 disables it
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
await amp.connect()
|
|
142
|
+
try:
|
|
143
|
+
await amp.select_feedback_resistor(1_000_000.0) # 1 MΩ, low-Z channel
|
|
144
|
+
await amp.set_boost_gain(10.0)
|
|
145
|
+
await amp.set_dc_bias(True)
|
|
146
|
+
state = await amp.read_data()
|
|
147
|
+
print(state.feedback_resistor_ohm, state.boost_gain, state.dc_bias_enabled)
|
|
148
|
+
finally:
|
|
149
|
+
await amp.close()
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Relay 13 (bias/compensation source) and relay 3 (booster source) are not
|
|
153
|
+
contract members, so they are exposed as extension methods:
|
|
154
|
+
`get_bias_compensation_source` / `set_bias_compensation_source` and
|
|
155
|
+
`get_booster_source` / `set_booster_source`. The layer never writes relay 13
|
|
156
|
+
implicitly; it leaves the firmware's Manual source in place unless the caller
|
|
157
|
+
asks otherwise. Relay 3 is driven automatically to follow the selected channel
|
|
158
|
+
(low-Z and high-Z route to their own booster input); `set_booster_source`
|
|
159
|
+
overrides that tracking.
|
|
160
|
+
|
|
161
|
+
Where an operation is advertised, the capability set answers whether it is
|
|
162
|
+
writable; where a value is available, the snapshot carries it. The two are
|
|
163
|
+
separate questions: a feature that exists but is switched off is truthy in
|
|
164
|
+
`capabilities` and `False` in the state.
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
capabilities = amp.capabilities
|
|
168
|
+
limits = capabilities.output_voltage
|
|
169
|
+
print(limits.min_v, limits.max_v) # static swing limits, or None while unknown
|
|
170
|
+
|
|
171
|
+
state = await amp.read_data()
|
|
172
|
+
if state.feedback_resistor_ohm is not None:
|
|
173
|
+
boost_gain = state.boost_gain
|
|
174
|
+
if boost_gain is None:
|
|
175
|
+
boost_gain = capabilities.boost.default_gain
|
|
176
|
+
|
|
177
|
+
transconductance = capabilities.total_transconductance(
|
|
178
|
+
state.feedback_resistor_ohm, boost_gain
|
|
179
|
+
)
|
|
180
|
+
ceiling = capabilities.max_input_current_a(
|
|
181
|
+
state.feedback_resistor_ohm, boost_gain
|
|
182
|
+
)
|
|
183
|
+
print(transconductance, ceiling)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
`total_transconductance` returns `Rf * boost` in V/A and raises `ValueError` for a
|
|
187
|
+
zero or negative resistor. `max_input_current_a` divides
|
|
188
|
+
`min(preamp.max_output_v, amplifier_swing / boost_gain)` by the feedback resistor,
|
|
189
|
+
so it accounts for both the pre-amp ceiling and the booster swing. It returns
|
|
190
|
+
`None` when either the pre-amp ceiling or the output limits are unknown.
|
|
191
|
+
|
|
192
|
+
## Capabilities
|
|
193
|
+
|
|
194
|
+
`CurrentAmplifierCapabilities` groups the control surface by function, not by
|
|
195
|
+
method name, and every group defaults to "unsupported". A driver declares the
|
|
196
|
+
whole set as a class attribute, so it is known before the instance connects.
|
|
197
|
+
|
|
198
|
+
| Group | Capability fields | Snapshot fields | Support query | Write query |
|
|
199
|
+
| --- | --- | --- | --- | --- |
|
|
200
|
+
| Preamp | `preamp.feedback_resistor`, `preamp.max_output_v` | `feedback_resistor_ohm` | `supports_preamp` | `can_select_preamp` |
|
|
201
|
+
| Boost | `boost.gain`, `boost.default_gain` | `boost_gain` | `supports_boost` | `can_set_boost` |
|
|
202
|
+
| DC bias | `dc_bias.enabled`, `dc_bias.level` | `dc_bias_enabled`, `dc_bias_level` | `supports_dc_bias` | `can_set_dc_bias` |
|
|
203
|
+
| Bandwidth | `bandwidth.access`, `bandwidth.options`, `bandwidth.fixed_hz` | `bandwidth_hz` | `supports_bandwidth` | `can_set_bandwidth` |
|
|
204
|
+
| Filters | `filters.types`, `filters.enabled`, `filters.cutoff` | `filters` | `supports_filters` | `can_set_filter` |
|
|
205
|
+
| Input overcurrent | `input_overcurrent.present`, `input_overcurrent.read` | `input_overcurrent` | `supports_input_overcurrent` | not writable |
|
|
206
|
+
| Output overload | `output_overload.present`, `output_overload.read` | `output_overload` | `supports_output_overload` | not writable |
|
|
207
|
+
| Input compensation | `input_compensation.enabled`, `input_compensation.level` | `input_compensation_enabled`, `input_compensation_level` | `supports_input_compensation` | `can_set_input_compensation` |
|
|
208
|
+
| Output inversion | `invert_output` | `inverted` | `supports_invert_output` | `can_set_invert_output` |
|
|
209
|
+
|
|
210
|
+
The output voltage swing and the pre-amp clip point are static geometry rather
|
|
211
|
+
than controllable features, so they have no `supports_*` properties:
|
|
212
|
+
`capabilities.output_voltage` is read directly and holds the `min_v` and `max_v`
|
|
213
|
+
limits, and `capabilities.preamp.max_output_v` holds the pre-amp clip point. The
|
|
214
|
+
voltage the device currently reports is `state.output_voltage_v`.
|
|
215
|
+
|
|
216
|
+
The two status indications are read only through `read_data()`; there are no
|
|
217
|
+
dedicated accessors. `output_voltage_v`, `output_current_a` and `input_current_a`
|
|
218
|
+
are always present in the snapshot and are not gated by a capability.
|
|
219
|
+
|
|
220
|
+
Some rules the model enforces:
|
|
221
|
+
|
|
222
|
+
- `SelectableCapabilities.options` is in device-native units and in the device's
|
|
223
|
+
own order. An empty tuple means the device does not enumerate the domain, which
|
|
224
|
+
is typical of a continuous setting such as a boost gain or a cutoff frequency;
|
|
225
|
+
it does not mean no value is accepted.
|
|
226
|
+
- `Access(read=..., write=...)` separates reading from writing, and
|
|
227
|
+
`bool(access)` is true when either direction is supported.
|
|
228
|
+
- The input-current range is derived, not selected: given the feedback resistor,
|
|
229
|
+
the boost gain and the static clip limits, `max_input_current_a` returns
|
|
230
|
+
`min(preamp.max_output_v, 10 V / G) / Rf`. `preamp.feedback_resistor` is the
|
|
231
|
+
physical resistance in ohm that anchors the calculation.
|
|
232
|
+
- `BandwidthCapabilities` covers four states: selectable-enumerated, selectable-
|
|
233
|
+
continuous, fixed-known and fixed-unknown. `fixed_hz` is `None` when the
|
|
234
|
+
bandwidth is selectable or when a fixed value is unknown.
|
|
235
|
+
- `IndicationCapabilities` separates presence from observability: `read=True`
|
|
236
|
+
requires `present=True`, and a present-but-unobservable signal is truthy for
|
|
237
|
+
`bool()` but falsy for the matching `supports_*` property.
|
|
238
|
+
- `FilterType` covers `LOW_PASS`, `HIGH_PASS` and `BAND_PASS`; a filter entry is a
|
|
239
|
+
`FilterSetting` with `enabled` and the cutoff corners in Hz that apply.
|
|
240
|
+
- `boost.default_gain` is the gain applied at power-on, which is unity for this
|
|
241
|
+
device family. An unreported `state.boost_gain` is not unity: it is unknown.
|
|
242
|
+
|
|
243
|
+
## Errors
|
|
244
|
+
|
|
245
|
+
- `NotImplementedError` from an optional method means the driver does not
|
|
246
|
+
implement that capability. Consult `capabilities` and take another path; do not
|
|
247
|
+
treat it as a transport failure.
|
|
248
|
+
- A `None` field in `AmplifierState` means the driver cannot report that value.
|
|
249
|
+
It is not `0.0` and not `False`, so a caller must not substitute either.
|
|
250
|
+
- `RegisterMapIncomplete` (a `RuntimeError`) means the register an operation needs
|
|
251
|
+
has no map entry. The message names the register and the missing detail.
|
|
252
|
+
- `UnexpectedResponse` (an `OSError`) means a response cannot belong to the
|
|
253
|
+
register it answers, such as a wrong register count.
|
|
254
|
+
- `ValueError` comes from `total_transconductance` and `max_input_current_a` for a
|
|
255
|
+
non-positive feedback resistor, and from `resolve_driver` for an unknown driver
|
|
256
|
+
name; the message lists the available names.
|
|
257
|
+
|
|
258
|
+
## EBIC v1.0 preamp
|
|
259
|
+
|
|
260
|
+
`EBICModbusV1Preamp` drives the `EBIC_Preamp` board (vendor `SCIETEX.RU`,
|
|
261
|
+
STM32F411) over Modbus RTU. The register map is transcribed from the firmware;
|
|
262
|
+
the device exposes seventeen relay outputs and the two settings that reach them,
|
|
263
|
+
and nothing else. There is no ADC, no DAC register, no measurement, status or
|
|
264
|
+
unlock register, so the driver does not invent one.
|
|
265
|
+
|
|
266
|
+
The analog architecture behind the relay bank is described in [docs/amplifier-architecture.md](docs/amplifier-architecture.md), and the per-relay function and coil map in [docs/relay-function-map.md](docs/relay-function-map.md).
|
|
267
|
+
|
|
268
|
+
| Item | Value |
|
|
269
|
+
| --- | --- |
|
|
270
|
+
| Identity | `SCIETEX.RU` / `EBIC_Preamp`, version 1.0.0, 32-bit serial number |
|
|
271
|
+
| Transport | Modbus RTU, 8N1, no flow control |
|
|
272
|
+
| Defaults | slave address 2, baud index 2 (19200 baud) |
|
|
273
|
+
| Holding registers | 0 = slave address, 1 = baud index, 10/11 = serial number (read only) |
|
|
274
|
+
| Input registers | 0-34 identity, 35 constant 7, 36-52 relay-level mirror |
|
|
275
|
+
| Coils | 0-16 relay levels |
|
|
276
|
+
|
|
277
|
+
`read_identity()`, `read_firmware_version()` and `read_serial_number()` read the
|
|
278
|
+
read-only input registers. The relay API is the working part of the driver:
|
|
279
|
+
|
|
280
|
+
```python
|
|
281
|
+
from scietex.hal.current_amplifier.scietex.ebic.modbus.v1 import (
|
|
282
|
+
EBICModbusV1Preamp,
|
|
283
|
+
)
|
|
284
|
+
from scietex.hal.serial import ModbusSerialConnectionConfig
|
|
285
|
+
|
|
286
|
+
serial_config = ModbusSerialConnectionConfig(port="/dev/ttyUSB0", framer="RTU")
|
|
287
|
+
amp = EBICModbusV1Preamp(serial_config) # address 2, 19200 baud by default
|
|
288
|
+
|
|
289
|
+
await amp.connect()
|
|
290
|
+
try:
|
|
291
|
+
levels = await amp.read_relays() # FC01, coils 0-16
|
|
292
|
+
await amp.set_relay(0, True) # FC05, one coil
|
|
293
|
+
await amp.set_relays([False] * 17) # FC0F, all coils
|
|
294
|
+
finally:
|
|
295
|
+
await amp.close()
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
- `read_relays()` reads FC01 coils 0-16. The same levels are mirrored in input
|
|
299
|
+
registers 36-52, but reaching that mirror needs a 53-register FC04 read, so
|
|
300
|
+
coils are the narrower path. `read_relay(index)` reads a single coil.
|
|
301
|
+
- `set_relay(index, state)` writes FC05; `set_relays(states)` writes FC0F with
|
|
302
|
+
exactly seventeen levels. FC0F is not atomic: the firmware applies and
|
|
303
|
+
persists each level in turn, so a failure can leave a partial group. Re-read
|
|
304
|
+
after an error instead of assuming a state.
|
|
305
|
+
- Every relay write is persisted to EEPROM. The interface is a state switch, not
|
|
306
|
+
a PWM output, and frequent switching consumes flash write cycles. `set_relay`
|
|
307
|
+
and `set_relays` write the coil level, which is the raw GPIO level: coil value
|
|
308
|
+
1 is de-energised for every relay, but it is the feature-off state for every
|
|
309
|
+
relay except relay 12, where it connects the 1 kΩ resistor. See
|
|
310
|
+
[docs/relay-function-map.md](docs/relay-function-map.md).
|
|
311
|
+
- `get_slave_address()` / `set_slave_address()` and `get_baud_index()` /
|
|
312
|
+
`set_baud_rate()` read and write holding registers 0 and 1. A write is
|
|
313
|
+
acknowledged at the OLD address and baud rate, persisted to EEPROM, and
|
|
314
|
+
followed by a firmware restart after about 500 ms. The device then answers
|
|
315
|
+
only at the new setting, so construct a new instance after the restart. Writing
|
|
316
|
+
the value already stored answers normally and causes no restart. `set_baud_rate`
|
|
317
|
+
accepts only 9600, 14400, 19200, 38400, 57600 or 115200 and writes the index,
|
|
318
|
+
never the rate.
|
|
319
|
+
|
|
320
|
+
The raw `EBICModbusV1Preamp` declares only the static analog geometry:
|
|
321
|
+
`preamp.max_output_v = 5.0`, `output_voltage` over +/-10 V, and
|
|
322
|
+
`input_overcurrent = IndicationCapabilities(present=True, read=False)`. Every
|
|
323
|
+
`supports_*`/`can_*` property stays `False`, and `read_data()` returns an
|
|
324
|
+
`AmplifierState` whose fields are all `None` with an empty filter tuple: the
|
|
325
|
+
firmware has no measurement or status register, so `None` is not zero.
|
|
326
|
+
|
|
327
|
+
The semantic `EBICModbusV1Amplifier` layers the relay map on those coils and
|
|
328
|
+
declares the selectable controls the map fixes:
|
|
329
|
+
|
|
330
|
+
- `preamp.feedback_resistor` over the eight `Rf` values, readable and writable.
|
|
331
|
+
- `boost.gain` over `(1.0, 3.0, 10.0, 30.0)`, with `default_gain = 1.0`.
|
|
332
|
+
- `dc_bias.enabled` (relay 4) and `input_compensation.enabled` (relay 17),
|
|
333
|
+
readable and writable.
|
|
334
|
+
|
|
335
|
+
`read_data()` decodes the coil pattern into `AmplifierState` for those four
|
|
336
|
+
functions; every other field stays `None`. A pattern that selects no single
|
|
337
|
+
resistor of the active channel, or that does not hold the gain relays one-hot,
|
|
338
|
+
decodes to `None` there, and the matching strict getter raises
|
|
339
|
+
`UnexpectedResponse`. Writes validate before any bus traffic. Both selectors are
|
|
340
|
+
make-before-break, because both drive parallel networks: a same-bank `Rf` change
|
|
341
|
+
engages the target relay first — the transient is the defined parallel pair
|
|
342
|
+
`R1*R2/(R1+R2)` — and a gain change engages the target gain relay first — the gain
|
|
343
|
+
relays switch parallel `Rg` elements, so the transient is an upward overshoot to
|
|
344
|
+
`G1 + G2 - 1` (about ×39 for ×10 ↔ ×30), not an intermediate gain; release-first
|
|
345
|
+
would instead give a unity-gain dip, and `Rg` open is unity gain, so the booster
|
|
346
|
+
cannot saturate either way. ×1 has no engage step: it only releases the engaged
|
|
347
|
+
gain relay, since it is the all-relays-open state. At rest the active channel has
|
|
348
|
+
exactly one engaged `Rf` and at most one gain relay engaged. The ordering is made
|
|
349
|
+
physical by a settle delay: after the engage write the driver awaits
|
|
350
|
+
`relay_settle_s` (default 8 ms, sized from the IM03 operate and bounce maxima)
|
|
351
|
+
before the dependent writes, so the overlap is deterministic; `0` disables it.
|
|
352
|
+
The delay is per-transition, so a plan with no engage step (`×1`) or no writes
|
|
353
|
+
adds none.
|
|
354
|
+
|
|
355
|
+
Still unsupported on this board, and therefore absent from both drivers:
|
|
356
|
+
bandwidth, filters, output inversion, bias level, compensation level and every
|
|
357
|
+
measurement. Relay 13 (bias/compensation source) and relay 3 (booster source) are
|
|
358
|
+
not contract members; the semantic layer exposes them only as the extension
|
|
359
|
+
methods described in [Usage](#usage), and never writes relay 13 implicitly. Relay
|
|
360
|
+
3 is written on every channel select so the booster follows the selected channel;
|
|
361
|
+
`set_booster_source` overrides it.
|
|
362
|
+
|
|
363
|
+
Both drivers are advertised through the
|
|
364
|
+
`scietex.hal.current_amplifier.drivers` entry-point group: `ebic_modbus_v1_preamp`
|
|
365
|
+
for `EBICModbusV1Preamp` and `ebic_modbus_v1` for `EBICModbusV1Amplifier`, so
|
|
366
|
+
`registry.discover_drivers()` returns both and `registry.resolve_driver()` loads
|
|
367
|
+
each by name.
|
|
368
|
+
|
|
369
|
+
## Testing
|
|
370
|
+
|
|
371
|
+
```bash
|
|
372
|
+
pytest tests -q
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
The suite exercises the capability model and drives the EBIC driver through a
|
|
376
|
+
stub transport that records requests and returns canned responses, so it checks
|
|
377
|
+
request construction and response validation without opening a serial port or
|
|
378
|
+
needing hardware.
|
|
379
|
+
|
|
380
|
+
Other checks:
|
|
381
|
+
|
|
382
|
+
```bash
|
|
383
|
+
tox -e format,lint,type
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
`format` and `lint` run `ruff`, `type` runs `ty` over `src`. Continuous
|
|
387
|
+
integration runs the same checks plus a distribution build; its test matrix
|
|
388
|
+
covers Python 3.10, 3.12 and 3.14.
|
|
389
|
+
|
|
390
|
+
## License
|
|
391
|
+
|
|
392
|
+
This project is licensed under the **MIT License** - see the LICENSE file for
|
|
393
|
+
details.
|