scietex.hal.current_amplifier
A Python library for current amplifiers: devices that convert a photodiode or ion-collector current into a voltage through a transimpedance preamp, an optional boost stage, DC bias injection, filtering and input-capacitance compensation.
The package is split in two layers. The capability model and the driver contract
in scietex.hal.current_amplifier.base are complete: they describe what an
amplifier can do, what it currently reads, and the asynchronous methods a driver
implements. Two drivers target the EBIC v1.0 preamp over Modbus RTU:
EBICModbusV1Preamp(entry pointebic_modbus_v1_preamp) is the raw relay driver: it exposes the seventeen relay coils and the communication settings, which is what the firmware implements. Its state snapshot is empty and it declares only the static analog geometry — the pre-amp +/-5 V clip point, the booster +/-10 V linear range, and the presence of the Overcurrent comparator.EBICModbusV1Amplifier(entry pointebic_modbus_v1) is the semantic layer built on those coils. It owns the relay-to-function map and implements the amplifier contract: feedback resistor, boost gain, DC bias enable and input compensation enable are selectable and readable, andread_data()decodes the coil pattern into anAmplifierState.
The relay-to-function map is documented in
docs/relay-function-map.md. The semantic layer still
cannot report or control what the board does not expose: bandwidth, filters,
output inversion, bias level, compensation level and every measurement stay
unsupported, with None fields in the state rather than invented values.
Status
| Layer | State |
|---|---|
Capability model (base.capabilities) |
Complete |
State snapshot (base.data) |
Complete |
Driver contract (base.protocol) |
Complete |
Driver registry (registry) |
Complete, two drivers advertised |
EBIC v1.0 preamp (scietex.ebic.modbus.v1) |
Complete: relay driver plus semantic amplifier |
Semantic amplifier (EBICModbusV1Amplifier) |
Complete: Rf, boost gain, bias and compensation enables, state decode |
Install
pip install scietex.hal.current_amplifier
The package is not on PyPI yet; install from a clone in the meantime:
git clone https://github.com/bond-anton/scietex.hal.current_amplifier.git
cd scietex.hal.current_amplifier
pip install .
Requirements:
- Python 3.10 or higher.
msgspec0.20 for the state snapshot.scietex.hal.serial2.5 or newer for the asynchronous RS485 transport.pymodbus3.15 for the Modbus request types.
Usage
Every driver satisfies CurrentAmplifierProtocol: connect, close and
read_data are mandatory coroutines, and every optional control method is a
coroutine too. The supports_* and can_* properties are synchronous and read
straight from capabilities, so a caller rejects an unsupported command before
dispatching it.
import asyncio
from scietex.hal.current_amplifier.base import CurrentAmplifierProtocol
async def main(amp: CurrentAmplifierProtocol) -> None:
"""Read one snapshot and normalise the boost stage."""
await amp.connect()
try:
state = await amp.read_data()
print(state.output_voltage_v, state.output_current_a, state.input_current_a)
if amp.can_set_boost:
await amp.set_boost_gain(amp.capabilities.boost.default_gain)
finally:
await amp.close()
asyncio.run(main(amplifier))
amplifier is a driver instance. With the raw EBICModbusV1Preamp,
read_data() returns an empty snapshot and commands go through its relay
methods; use the semantic EBICModbusV1Amplifier when you want the amplifier
contract. It drives the same coils through the function map:
from scietex.hal.current_amplifier.scietex.ebic.modbus.v1 import (
EBICModbusV1Amplifier,
)
from scietex.hal.serial import ModbusSerialConnectionConfig
amp = EBICModbusV1Amplifier(
ModbusSerialConnectionConfig(port="/dev/ttyUSB0", framer="RTU"),
relay_settle_s=0.008, # 8 ms engage barrier; 0 disables it
)
await amp.connect()
try:
await amp.select_feedback_resistor(1_000_000.0) # 1 MΩ, low-Z channel
await amp.set_boost_gain(10.0)
await amp.set_dc_bias(True)
state = await amp.read_data()
print(state.feedback_resistor_ohm, state.boost_gain, state.dc_bias_enabled)
finally:
await amp.close()
Relay 13 (bias/compensation source) and relay 3 (booster source) are not
contract members, so they are exposed as extension methods:
get_bias_compensation_source / set_bias_compensation_source and
get_booster_source / set_booster_source. The layer never writes relay 13
implicitly; it leaves the firmware's Manual source in place unless the caller
asks otherwise. Relay 3 is driven automatically to follow the selected channel
(low-Z and high-Z route to their own booster input); set_booster_source
overrides that tracking.
Where an operation is advertised, the capability set answers whether it is
writable; where a value is available, the snapshot carries it. The two are
separate questions: a feature that exists but is switched off is truthy in
capabilities and False in the state.
capabilities = amp.capabilities
limits = capabilities.output_voltage
print(limits.min_v, limits.max_v) # static swing limits, or None while unknown
state = await amp.read_data()
if state.feedback_resistor_ohm is not None:
boost_gain = state.boost_gain
if boost_gain is None:
boost_gain = capabilities.boost.default_gain
transconductance = capabilities.total_transconductance(
state.feedback_resistor_ohm, boost_gain
)
ceiling = capabilities.max_input_current_a(
state.feedback_resistor_ohm, boost_gain
)
print(transconductance, ceiling)
total_transconductance returns Rf * boost in V/A and raises ValueError for a
zero or negative resistor. max_input_current_a divides
min(preamp.max_output_v, amplifier_swing / boost_gain) by the feedback resistor,
so it accounts for both the pre-amp ceiling and the booster swing. It returns
None when either the pre-amp ceiling or the output limits are unknown.
Capabilities
CurrentAmplifierCapabilities groups the control surface by function, not by
method name, and every group defaults to "unsupported". A driver declares the
whole set as a class attribute, so it is known before the instance connects.
| Group | Capability fields | Snapshot fields | Support query | Write query |
|---|---|---|---|---|
| Preamp | preamp.feedback_resistor, preamp.max_output_v |
feedback_resistor_ohm |
supports_preamp |
can_select_preamp |
| Boost | boost.gain, boost.default_gain |
boost_gain |
supports_boost |
can_set_boost |
| DC bias | dc_bias.enabled, dc_bias.level |
dc_bias_enabled, dc_bias_level |
supports_dc_bias |
can_set_dc_bias |
| Bandwidth | bandwidth.access, bandwidth.options, bandwidth.fixed_hz |
bandwidth_hz |
supports_bandwidth |
can_set_bandwidth |
| Filters | filters.types, filters.enabled, filters.cutoff |
filters |
supports_filters |
can_set_filter |
| Input overcurrent | input_overcurrent.present, input_overcurrent.read |
input_overcurrent |
supports_input_overcurrent |
not writable |
| Output overload | output_overload.present, output_overload.read |
output_overload |
supports_output_overload |
not writable |
| Input compensation | input_compensation.enabled, input_compensation.level |
input_compensation_enabled, input_compensation_level |
supports_input_compensation |
can_set_input_compensation |
| Output inversion | invert_output |
inverted |
supports_invert_output |
can_set_invert_output |
The output voltage swing and the pre-amp clip point are static geometry rather
than controllable features, so they have no supports_* properties:
capabilities.output_voltage is read directly and holds the min_v and max_v
limits, and capabilities.preamp.max_output_v holds the pre-amp clip point. The
voltage the device currently reports is state.output_voltage_v.
The two status indications are read only through read_data(); there are no
dedicated accessors. output_voltage_v, output_current_a and input_current_a
are always present in the snapshot and are not gated by a capability.
Some rules the model enforces:
SelectableCapabilities.optionsis in device-native units and in the device's own order. An empty tuple means the device does not enumerate the domain, which is typical of a continuous setting such as a boost gain or a cutoff frequency; it does not mean no value is accepted.Access(read=..., write=...)separates reading from writing, andbool(access)is true when either direction is supported.- The input-current range is derived, not selected: given the feedback resistor,
the boost gain and the static clip limits,
max_input_current_areturnsmin(preamp.max_output_v, 10 V / G) / Rf.preamp.feedback_resistoris the physical resistance in ohm that anchors the calculation. BandwidthCapabilitiescovers four states: selectable-enumerated, selectable- continuous, fixed-known and fixed-unknown.fixed_hzisNonewhen the bandwidth is selectable or when a fixed value is unknown.IndicationCapabilitiesseparates presence from observability:read=Truerequirespresent=True, and a present-but-unobservable signal is truthy forbool()but falsy for the matchingsupports_*property.FilterTypecoversLOW_PASS,HIGH_PASSandBAND_PASS; a filter entry is aFilterSettingwithenabledand the cutoff corners in Hz that apply.boost.default_gainis the gain applied at power-on, which is unity for this device family. An unreportedstate.boost_gainis not unity: it is unknown.
Errors
NotImplementedErrorfrom an optional method means the driver does not implement that capability. Consultcapabilitiesand take another path; do not treat it as a transport failure.- A
Nonefield inAmplifierStatemeans the driver cannot report that value. It is not0.0and notFalse, so a caller must not substitute either. RegisterMapIncomplete(aRuntimeError) means the register an operation needs has no map entry. The message names the register and the missing detail.UnexpectedResponse(anOSError) means a response cannot belong to the register it answers, such as a wrong register count.ValueErrorcomes fromtotal_transconductanceandmax_input_current_afor a non-positive feedback resistor, and fromresolve_driverfor an unknown driver name; the message lists the available names.
EBIC v1.0 preamp
EBICModbusV1Preamp drives the EBIC_Preamp board (vendor SCIETEX.RU,
STM32F411) over Modbus RTU. The register map is transcribed from the firmware;
the device exposes seventeen relay outputs and the two settings that reach them,
and nothing else. There is no ADC, no DAC register, no measurement, status or
unlock register, so the driver does not invent one.
The analog architecture behind the relay bank is described in docs/amplifier-architecture.md, and the per-relay function and coil map in docs/relay-function-map.md.
| Item | Value |
|---|---|
| Identity | SCIETEX.RU / EBIC_Preamp, version 1.0.0, 32-bit serial number |
| Transport | Modbus RTU, 8N1, no flow control |
| Defaults | slave address 2, baud index 2 (19200 baud) |
| Holding registers | 0 = slave address, 1 = baud index, 10/11 = serial number (read only) |
| Input registers | 0-34 identity, 35 constant 7, 36-52 relay-level mirror |
| Coils | 0-16 relay levels |
read_identity(), read_firmware_version() and read_serial_number() read the
read-only input registers. The relay API is the working part of the driver:
from scietex.hal.current_amplifier.scietex.ebic.modbus.v1 import (
EBICModbusV1Preamp,
)
from scietex.hal.serial import ModbusSerialConnectionConfig
serial_config = ModbusSerialConnectionConfig(port="/dev/ttyUSB0", framer="RTU")
amp = EBICModbusV1Preamp(serial_config) # address 2, 19200 baud by default
await amp.connect()
try:
levels = await amp.read_relays() # FC01, coils 0-16
await amp.set_relay(0, True) # FC05, one coil
await amp.set_relays([False] * 17) # FC0F, all coils
finally:
await amp.close()
read_relays()reads FC01 coils 0-16. The same levels are mirrored in input registers 36-52, but reaching that mirror needs a 53-register FC04 read, so coils are the narrower path.read_relay(index)reads a single coil.set_relay(index, state)writes FC05;set_relays(states)writes FC0F with exactly seventeen levels. FC0F is not atomic: the firmware applies and persists each level in turn, so a failure can leave a partial group. Re-read after an error instead of assuming a state.- Every relay write is persisted to EEPROM. The interface is a state switch, not
a PWM output, and frequent switching consumes flash write cycles.
set_relayandset_relayswrite the coil level, which is the raw GPIO level: coil value 1 is de-energised for every relay, but it is the feature-off state for every relay except relay 12, where it connects the 1 kΩ resistor. See docs/relay-function-map.md. get_slave_address()/set_slave_address()andget_baud_index()/set_baud_rate()read and write holding registers 0 and 1. A write is acknowledged at the OLD address and baud rate, persisted to EEPROM, and followed by a firmware restart after about 500 ms. The device then answers only at the new setting, so construct a new instance after the restart. Writing the value already stored answers normally and causes no restart.set_baud_rateaccepts only 9600, 14400, 19200, 38400, 57600 or 115200 and writes the index, never the rate.
The raw EBICModbusV1Preamp declares only the static analog geometry:
preamp.max_output_v = 5.0, output_voltage over +/-10 V, and
input_overcurrent = IndicationCapabilities(present=True, read=False). Every
supports_*/can_* property stays False, and read_data() returns an
AmplifierState whose fields are all None with an empty filter tuple: the
firmware has no measurement or status register, so None is not zero.
The semantic EBICModbusV1Amplifier layers the relay map on those coils and
declares the selectable controls the map fixes:
preamp.feedback_resistorover the eightRfvalues, readable and writable.boost.gainover(1.0, 3.0, 10.0, 30.0), withdefault_gain = 1.0.dc_bias.enabled(relay 4) andinput_compensation.enabled(relay 17), readable and writable.
read_data() decodes the coil pattern into AmplifierState for those four
functions; every other field stays None. A pattern that selects no single
resistor of the active channel, or that does not hold the gain relays one-hot,
decodes to None there, and the matching strict getter raises
UnexpectedResponse. Writes validate before any bus traffic. Both selectors are
make-before-break, because both drive parallel networks: a same-bank Rf change
engages the target relay first — the transient is the defined parallel pair
R1*R2/(R1+R2) — and a gain change engages the target gain relay first — the gain
relays switch parallel Rg elements, so the transient is an upward overshoot to
G1 + G2 - 1 (about ×39 for ×10 ↔ ×30), not an intermediate gain; release-first
would instead give a unity-gain dip, and Rg open is unity gain, so the booster
cannot saturate either way. ×1 has no engage step: it only releases the engaged
gain relay, since it is the all-relays-open state. At rest the active channel has
exactly one engaged Rf and at most one gain relay engaged. The ordering is made
physical by a settle delay: after the engage write the driver awaits
relay_settle_s (default 8 ms, sized from the IM03 operate and bounce maxima)
before the dependent writes, so the overlap is deterministic; 0 disables it.
The delay is per-transition, so a plan with no engage step (×1) or no writes
adds none.
Still unsupported on this board, and therefore absent from both drivers:
bandwidth, filters, output inversion, bias level, compensation level and every
measurement. Relay 13 (bias/compensation source) and relay 3 (booster source) are
not contract members; the semantic layer exposes them only as the extension
methods described in Usage, and never writes relay 13 implicitly. Relay
3 is written on every channel select so the booster follows the selected channel;
set_booster_source overrides it.
Both drivers are advertised through the
scietex.hal.current_amplifier.drivers entry-point group: ebic_modbus_v1_preamp
for EBICModbusV1Preamp and ebic_modbus_v1 for EBICModbusV1Amplifier, so
registry.discover_drivers() returns both and registry.resolve_driver() loads
each by name.
Testing
pytest tests -q
The suite exercises the capability model and drives the EBIC driver through a stub transport that records requests and returns canned responses, so it checks request construction and response validation without opening a serial port or needing hardware.
Other checks:
tox -e format,lint,type
format and lint run ruff, type runs ty over src. Continuous
integration runs the same checks plus a distribution build; its test matrix
covers Python 3.10, 3.12 and 3.14.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for scietex.hal.current-amplifier 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| scietex_hal_current_amplifier-0.5.0.tar.gz | 76.2 kB | With provenance | Details for scietex_hal_current_amplifier-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scietex_hal_current_amplifier-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for scietex_hal_current_amplifier-0.5.0-py3-none-any.whl |
Total release size: 127.1 kB
Release files / scietex_hal_current_amplifier-0.5.0.tar.gz
| Download URL | scietex_hal_current_amplifier-0.5.0.tar.gz |
|---|---|
| Size | 76.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f41e365fbf04246a93da0ca3fab839524ccd61c4076bbaf55767a0c0ad3c420
|
|
BLAKE2b-256 checksum How to use checksums |
8e3410db1cadb5fd92a0ba6cad95ce581e8bbb5782a147fe23df77386ed8273e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logRelease files / scietex_hal_current_amplifier-0.5.0-py3-none-any.whl
| Download URL | scietex_hal_current_amplifier-0.5.0-py3-none-any.whl |
|---|---|
| Size | 50.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d12f8b160e3e7acc5c7430d7ac0359d9b474565ced381a614698b1864614915f
|
|
BLAKE2b-256 checksum How to use checksums |
8522bc74f3ee97c95585eefdeec3d495fa910e7a90201c2e2234282f9643a950
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logSecurity for scietex.hal.current-amplifier 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for scietex_hal_current_amplifier-0.5.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.