Skip to main content

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 point ebic_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 point ebic_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, and read_data() decodes the coil pattern into an AmplifierState.

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.
  • msgspec 0.20 for the state snapshot.
  • scietex.hal.serial 2.5 or newer for the asynchronous RS485 transport.
  • pymodbus 3.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.options is 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, and bool(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_a returns min(preamp.max_output_v, 10 V / G) / Rf. preamp.feedback_resistor is the physical resistance in ohm that anchors the calculation.
  • BandwidthCapabilities covers four states: selectable-enumerated, selectable- continuous, fixed-known and fixed-unknown. fixed_hz is None when the bandwidth is selectable or when a fixed value is unknown.
  • IndicationCapabilities separates presence from observability: read=True requires present=True, and a present-but-unobservable signal is truthy for bool() but falsy for the matching supports_* property.
  • FilterType covers LOW_PASS, HIGH_PASS and BAND_PASS; a filter entry is a FilterSetting with enabled and the cutoff corners in Hz that apply.
  • boost.default_gain is the gain applied at power-on, which is unity for this device family. An unreported state.boost_gain is not unity: it is unknown.

Errors

  • NotImplementedError from an optional method means the driver does not implement that capability. Consult capabilities and take another path; do not treat it as a transport failure.
  • A None field in AmplifierState means the driver cannot report that value. It is not 0.0 and not False, so a caller must not substitute either.
  • RegisterMapIncomplete (a RuntimeError) means the register an operation needs has no map entry. The message names the register and the missing detail.
  • UnexpectedResponse (an OSError) means a response cannot belong to the register it answers, such as a wrong register count.
  • ValueError comes from total_transconductance and max_input_current_a for a non-positive feedback resistor, and from resolve_driver for 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_relay and set_relays write 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() and get_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_rate accepts 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_resistor over the eight Rf values, readable and writable.
  • boost.gain over (1.0, 3.0, 10.0, 30.0), with default_gain = 1.0.
  • dc_bias.enabled (relay 4) and input_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.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scietex.hal.current-amplifier 0.4.0
File Size Uploaded Provenance Actions
scietex_hal_current_amplifier-0.4.0.tar.gz 75.1 kB With provenance Details for scietex_hal_current_amplifier-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for scietex.hal.current-amplifier 0.4.0
File Interpreter ABI Platform Actions
scietex_hal_current_amplifier-0.4.0-py3-none-any.whl Python 3 none any Details for scietex_hal_current_amplifier-0.4.0-py3-none-any.whl

Total release size: 125.5 kB

Release files / scietex_hal_current_amplifier-0.4.0.tar.gz

Download URL scietex_hal_current_amplifier-0.4.0.tar.gz
Size 75.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c49f50a23a78cebd2a379b6e9b8c62211a7fe2eaa23d11f11e78943363dce88e
BLAKE2b-256 checksum
How to use checksums
05d69f20e09ca9b11d9c2719388489bfd298d21ba191649ac871e00c21d45814
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 25, 2026.

Transparency log

Release files / scietex_hal_current_amplifier-0.4.0-py3-none-any.whl

Download URL scietex_hal_current_amplifier-0.4.0-py3-none-any.whl
Size 50.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d881e76d7b94696078074912a53efa5285c791dee10e16418543e8ea3f2cb93
BLAKE2b-256 checksum
How to use checksums
934a61de0f4b429df9d967a6152037965c77c43257a87aca7919932bd684c88c
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 25, 2026.

Transparency log

Security for scietex.hal.current-amplifier 0.4.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.

Select from 2 files

Attestation for scietex_hal_current_amplifier-0.4.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 25, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page