sartoriuslib.registry¶
Unit, Sign, the parameter table (index → ParameterSpec), and the
typed mode enums (FilterMode, AutoZeroMode, IsoCalMode, …) used by
the typed Balance.get_X() / set_X() accessors.
Units + sign¶
sartoriuslib.registry.units ¶
Unit enum + display-unit parameter mapping.
Two maps touch this file:
-
Measurement-frame wire bytes → :class:
Unit. Lives in :mod:sartoriuslib.protocol.xbpi.units(0x02 g/0x03 kg/0x0D mg/0x17 N). That map decodes what a balance reports in an 8-byte measurement body. -
Parameter-table index 7 (display unit) → :class:
Unit. Lives here as :data:DISPLAY_UNIT_CODE_TO_UNIT. That map decodes what a balance is configured to display; it is the full 24-entry table fromdocs/protocol.md§10.1 idx 7.
The two address spaces are different — the display-unit codes are a dense 1..24 enumeration, while the measurement-frame bytes are a sparse 6-bit ID space (0x02, 0x03, 0x0D, 0x17, …). Keeping the maps separate keeps each unit of code honest about what it actually knows.
Unknown codes decode to :attr:Unit.UNKNOWN rather than raising —
forward-compatibility for firmware we have not captured.
Sign ¶
Bases: StrEnum
Sign of a measurement as encoded on the wire.
Unit ¶
Bases: StrEnum
Physical unit of a measurement / display unit.
Values are the short symbol (or short tag for units without a
single canonical symbol) so str(Unit.G) == "g" for log lines
and CSV columns.
Membership covers the 24-entry p07 display-unit table plus
:attr:UNKNOWN for forward-compat on measurement-frame decoding.
CT_AU
class-attribute
instance-attribute
¶
Austrian carat — non-metric; used in p07 idx 17.
PARTS_PER_POUND
class-attribute
instance-attribute
¶
Parts per pound (p07 ptplb).
USERDEF
class-attribute
instance-attribute
¶
User-defined unit (p07 idx 1). A multiplier + label live in a separate register not yet located; the balance displays it scaled from grams.
unit_to_display_code ¶
Turn a :class:Unit into its p07 display-unit code.
Raises :class:ValueError for :attr:Unit.UNKNOWN and any
:class:Unit member not in the display-unit table (should be
unreachable today — every member is in the table — but stays
defensive for future additions).
Source code in src/sartoriuslib/registry/units.py
Parameter table¶
sartoriuslib.registry.parameters ¶
Parameter-table index → typed spec map.
Drives two things at the command layer:
- Typed accessors on :class:
~sartoriuslib.devices.balance.Balance(get_filter_mode(),set_filter_mode(...), etc.). The spec carries the enum class so the setter can validate + encode and the getter can decode to a typed value. - Cache invalidation on :class:
~sartoriuslib.devices.session.Session.bumps_config_countertells the session whether a write to this index will tick0xBA. Indices that don't (p13,p50) must still invalidate their cached entries on explicit write — the §6.3 caveat from design doc.
Only the [SURE] rows from docs/protocol.md §10.1 are modelled
here. [LIKELY] rows remain reachable via raw
read_parameter / write_parameter until they get promoted.
ParameterSpec
dataclass
¶
ParameterSpec(
index,
name,
enum,
writable=True,
bumps_config_counter=True,
families=(lambda: _ALL_FAMILIES)(),
unit_enum=False,
)
Typed description of one well-understood parameter-table index.
Attributes:
| Name | Type | Description |
|---|---|---|
index |
int
|
|
name |
str
|
Human-readable symbol matching the |
enum |
type[IntEnum] | None
|
The typed :class: |
writable |
bool
|
|
bumps_config_counter |
bool
|
|
families |
frozenset[BalanceFamily]
|
Families known to expose this index. Advisory only — the session's runtime availability cache is the source of truth. |
unit_enum |
bool
|
Optional :class: |
decode ¶
Turn a wire u8 into the typed value (enum member or :class:Unit).
Source code in src/sartoriuslib/registry/parameters.py
encode ¶
Turn a typed value back into the wire u8 for 0x56.
Raises :class:ValueError if value is not a member of the
spec's enum / unit set. Accepts a plain int as an escape
hatch for values outside the modelled range (but still runs
through the enum constructor so mid-table gaps stay rejected).
Source code in src/sartoriuslib/registry/parameters.py
get_parameter_spec ¶
Mode enums¶
sartoriuslib.registry.modes ¶
Typed enums for the well-understood parameter-table indices.
One :class:IntEnum per [SURE] row in docs/protocol.md §10.1.
Values match the wire u8 the balance accepts / returns, so encoding is
int(mode) and decoding is Mode(byte).
Each enum includes :attr:UNKNOWN (value 0) as the
forward-compatibility escape hatch — a byte the library does not yet
recognise decodes to UNKNOWN rather than raising, mirroring the
:class:Unit / :class:Sign policy in :mod:sartoriuslib.registry.units.
0 is safe because the p* indices documented here use 1-based
numbering on the wire.
AppFilter ¶
Bases: IntEnum
p02 — application filter. Orthogonal to :class:FilterMode.
AutoZeroMode ¶
Bases: IntEnum
p06 — auto-zero tracking on / off.
CalButtonAssignment ¶
Bases: IntEnum
p09 — calibration-button assignment.
MSE1203S live values only; gaps reserved.
CalibrationUnit ¶
Bases: IntEnum
p44 — calibration unit.
Note: wire encoding differs from opcode 0x79's args.
DisplayAccuracyMode ¶
Bases: IntEnum
p08 — display-accuracy mode.
Only the four MSE1203S-live values are named. Gaps in the sparse
max=18 range belong to other balances within the family and
decode to :attr:UNKNOWN on devices that do not expose them.
DIV1
class-attribute
instance-attribute
¶
div1 — increment divided by 1 (identity with DEFAULT on
MSE1203S; retained as a distinct menu entry).
LOW_POWER_ON_OFF
class-attribute
instance-attribute
¶
lponoff — power-save display toggle.
MINUS_1_DIGIT
class-attribute
instance-attribute
¶
-1 digit — drops the 0x0D increment by one decimal (10x).
ExternalCalLock ¶
Bases: IntEnum
p16 — external calibration lock.
FilterMode ¶
Bases: IntEnum
p01 — filter / ambient mode.
Equivalent to opcode 0x26 (read_weighing_mode). Fully
mapped.
IsoCalMode ¶
Bases: IntEnum
p15 — persistent isoCAL mode.
Status-byte bit 0x10 is the attention flag, not the enable
flag — see docs/protocol.md §10.1 p15.
MenuAccessMode ¶
Bases: IntEnum
p40 — front-panel menu access.
OutputMode ¶
Bases: IntEnum
p36 — SBI output mode (trigger × stability-filter matrix).
AUTOPRINT_STABLE
class-attribute
instance-attribute
¶
auto_w — autoprint only stable cycles.
AUTOPRINT_UNFILTERED
class-attribute
instance-attribute
¶
auto_wo — autoprint each cycle regardless of stability.
MANUAL_AFTER_STABILITY
class-attribute
instance-attribute
¶
ind_after — manual trigger, send after next stability.
MANUAL_AT_STABILITY
class-attribute
instance-attribute
¶
ind_at — manual trigger, send only when already stable.
MANUAL_IMMEDIATE
class-attribute
instance-attribute
¶
ind_no — manual trigger, send current value.
ParityMode ¶
Bases: IntEnum
p32 / p64 — UART parity.
Shared encoding between the peripheral port (p32) and the PC-USB port (p64). Gaps 1/2 are reserved (mark/space).
StabilityDelay ¶
Bases: IntEnum
p04 — stability delay (how long above-threshold must persist).
StabilityRange ¶
Bases: IntEnum
p03 — stability detection band width.
StopBitsMode ¶
Bases: IntEnum
p33 / p65 — UART stop bits.
TareBehavior ¶
Bases: IntEnum
p05 — tare-on-stability behaviour.
TareOnPowerOn ¶
Bases: IntEnum
p13 — tare on power-on.
Bit: this is a boot-time flag. Writing it does not bump the
0xBA config counter — see docs/protocol.md §10.1 persistence
note and design doc §6.3 caveat.
ZeroRange ¶
Bases: IntEnum
p11 — runtime auto-zero range.
decode_mode ¶
Turn a wire u8 into a member of enum_cls.
Unrecognised codes collapse to the UNKNOWN member (value 0)
so new firmware reveals stay non-crashing. Every enum in this
module is guaranteed to carry an UNKNOWN = 0 member.
Source code in src/sartoriuslib/registry/modes.py
Aliases — value normalisers¶
sartoriuslib.registry.aliases ¶
Fuzzy string → typed-value resolvers.
Scripts, REPL use, and the sarto-* CLI all want to accept
"Stable" / "stable" / "STABLE" / "very stable" /
"very_stable" as the same :class:FilterMode. Resolvers here do
one pass of normalisation (lowercase, collapse whitespace / hyphens to
underscores, strip punctuation) then look the canonical form up.
Design §16 Q4 leans toward inline tables for v1; if the alias maps grow past what is readable here, promote them to a build-time artefact then.
normalise ¶
Canonicalise raw to lower_snake_case_ish.
"Very Stable" / "very-stable" / "very.stable" all
collapse to "very_stable". Unicode is lowercased but not
folded — "µg" stays "µg".
Source code in src/sartoriuslib/registry/aliases.py
resolve_auto_zero ¶
resolve_display_accuracy ¶
Fuzzy-match to a :class:DisplayAccuracyMode.
resolve_filter_mode ¶
Fuzzy-match to a :class:FilterMode. Raises on unknown input.
resolve_isocal_mode ¶
resolve_menu_access ¶
resolve_output_mode ¶
resolve_tare_behavior ¶
resolve_unit ¶
Fuzzy-match raw to a :class:Unit member.
Raises :class:UnknownUnitError if no alias matches.