Device API
spectrum_channel_to_energy
Convert spectrometer channel number to energy in keV using quadratic calibration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel_number
|
int
|
Channel number from the spectrometer (integer) |
required |
a0
|
float
|
Constant term coefficient (keV) |
required |
a1
|
float
|
Linear term coefficient (keV/channel) |
required |
a2
|
float
|
Quadratic term coefficient (keV/channel^2) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Energy value in keV corresponding to the channel number |
Source code in src/radiacode/radiacode.py
RadiaCode
RadiaCode(
bluetooth_mac: Optional[str] = None,
serial_number: Optional[str] = None,
ignore_firmware_compatibility_check: bool = False,
)
A synchronous connection to a RadiaCode device.
Constructing this class opens either a USB or Bluetooth connection and initializes the device. Use it as a context manager whenever possible so that transport resources are released promptly.
Only one transport is selected: supplying bluetooth_mac selects
Bluetooth; otherwise USB is used. serial_number only selects between USB
devices.
Initialize a RadiaCode device connection.
This constructor establishes a connection to a RadiaCode device either via Bluetooth or USB, initializes the device, and performs firmware compatibility checks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bluetooth_mac
|
Optional[str]
|
Optional Bluetooth device identifier. This is normally a MAC address on Linux and Windows, and a CoreBluetooth UUID on macOS. |
None
|
serial_number
|
Optional[str]
|
Optional USB serial number to connect to a specific device when multiple devices are connected. Used only for USB connections. |
None
|
ignore_firmware_compatibility_check
|
bool
|
If True, skips the firmware version compatibility check. Default is False. |
False
|
Raises:
| Type | Description |
|---|---|
Exception
|
If the device firmware version is incompatible (< 4.8) and ignore_firmware_compatibility_check is False. |
Note
- If both bluetooth_mac and serial_number are None, connects to the first available USB device
- The device is initialized with the current system time
Source code in src/radiacode/radiacode.py
close
base_time
status
Return the device status flags as a diagnostic string.
set_local_time
Set the device's local time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
datetime
|
datetime.datetime object containing the time to set on the device. The time components used are: year, month, day, hour, minute, second. Microseconds are ignored. |
required |
Source code in src/radiacode/radiacode.py
fw_signature
Return a formatted firmware signature and identity string.
Source code in src/radiacode/radiacode.py
fw_version
Get firmware version information.
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[tuple[int, int, str], tuple[int, int, str]]
|
A tuple containing two tuples: - Boot version: (major, minor, date string) - Target version: (major, minor, date string) |
Source code in src/radiacode/radiacode.py
hw_serial_number
Get hardware serial number.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Hardware serial number formatted as hyphen-separated hexadecimal groups (e.g. "12345678-9ABCDEF0") |
Source code in src/radiacode/radiacode.py
configuration
text_message
serial_number
Get the device serial number.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The device serial number as an ASCII string |
data_buf
data_buf() -> list[
DoseRateDB | RareData | RealTimeData | RawData | Event
]
Get buffered measurement data from the device.
spectrum
spectrum() -> Spectrum
Get current spectrum data from the device.
Returns:
| Name | Type | Description |
|---|---|---|
Spectrum |
Spectrum
|
Object containing the current spectrum data |
Source code in src/radiacode/radiacode.py
spectrum_accum
spectrum_accum() -> Spectrum
Get accumulated spectrum data from the device.
Returns:
| Name | Type | Description |
|---|---|---|
Spectrum |
Spectrum
|
Object containing the accumulated spectrum data |
Source code in src/radiacode/radiacode.py
dose_reset
Reset the accumulated dose measurements to zero.
This clears all accumulated dose rate history and statistics.
spectrum_reset
Reset the current spectrum data to zero.
This clears the current spectrum data buffer, effectively resetting the spectrum measurement to start fresh.
Source code in src/radiacode/radiacode.py
energy_calib
Get the energy calibration coefficients.
Returns:
| Type | Description |
|---|---|
list[float]
|
list[float]: List of 3 calibration coefficients [a0, a1, a2] where: - a0: Constant term coefficient (keV) - a1: Linear term coefficient (keV/channel) - a2: Quadratic term coefficient (keV/channel^2) |
Source code in src/radiacode/radiacode.py
set_energy_calib
Set the energy calibration coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coef
|
list[float]
|
List of 3 calibration coefficients [a0, a1, a2] where: - a0: Constant term coefficient (keV) - a1: Linear term coefficient (keV/channel) - a2: Quadratic term coefficient (keV/channel^2) |
required |
Source code in src/radiacode/radiacode.py
set_language
Set the device interface language.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lang
|
str
|
Language code string, either 'ru' for Russian or 'en' for English. Defaults to 'ru'. |
'ru'
|
Source code in src/radiacode/radiacode.py
set_device_on
Turn the device on or off.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on
|
bool
|
True to turn device on, False to turn it off |
required |
set_sound_on
Enable or disable device sounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on
|
bool
|
True to enable sounds, False to disable |
required |
set_vibro_on
Enable or disable device vibration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on
|
bool
|
True to enable vibration, False to disable |
required |
set_sound_ctrl
set_sound_ctrl(ctrls: list[CTRL]) -> None
Configure which events trigger device sounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctrls
|
list[CTRL]
|
List of CTRL enum values specifying which events should trigger sounds |
required |
Source code in src/radiacode/radiacode.py
set_display_off_time
Set the display auto-off timeout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
int
|
Time in seconds before display turns off automatically. Must be one of: 5, 10, 15, or 30 seconds. |
required |
Source code in src/radiacode/radiacode.py
set_display_brightness
Set the display brightness level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
brightness
|
int
|
Brightness level from 0 (minimum) to 9 (maximum) |
required |
Source code in src/radiacode/radiacode.py
set_display_direction
set_display_direction(direction: DisplayDirection) -> None
Set the display orientation direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
DisplayDirection
|
DisplayDirection enum value specifying the desired orientation |
required |
Source code in src/radiacode/radiacode.py
set_vibro_ctrl
set_vibro_ctrl(ctrls: list[CTRL]) -> None
Configure which events trigger device vibration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctrls
|
list[CTRL]
|
List of CTRL enum values specifying which events should trigger vibration. Note: CTRL.CLICKS is not supported for vibration control. |
required |
Source code in src/radiacode/radiacode.py
get_alarm_limits
get_alarm_limits() -> AlarmLimits
Return the device's current alarm thresholds and configured units.
Source code in src/radiacode/radiacode.py
set_alarm_limits
set_alarm_limits(
l1_count_rate: int | float | None = None,
l2_count_rate: int | float | None = None,
l1_dose_rate: int | float | None = None,
l2_dose_rate: int | float | None = None,
l1_dose: int | float | None = None,
l2_dose: int | float | None = None,
dose_unit_sv: bool | None = None,
count_unit_cpm: bool | None = None,
) -> bool
Set one or more alarm limits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
l1_count_rate
|
int | float | None
|
Count rate at which to raise a level-one alarm. |
None
|
l2_count_rate
|
int | float | None
|
Count rate at which to raise a level-two alarm. |
None
|
l1_dose_rate
|
int | float | None
|
Dose rate in micro-units per hour at which to raise a level-one alarm. |
None
|
l2_dose_rate
|
int | float | None
|
Dose rate in micro-units per hour at which to raise a level-two alarm. |
None
|
l1_dose
|
int | float | None
|
Accumulated dose in micro-units at which to raise a level-one alarm. |
None
|
l2_dose
|
int | float | None
|
Accumulated dose in micro-units at which to raise a level-two alarm. |
None
|
dose_unit_sv
|
bool | None
|
If true, interpret dose values as Sievert and set the display unit to Sievert. If false, use Roentgen. If omitted, do not update the display unit or scale values. |
None
|
count_unit_cpm
|
bool | None
|
If true, interpret count-rate values as counts per minute and set that display unit. If false, use counts per second. If omitted, do not update the display unit or scale values. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the device reports that every supplied value was written. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no limits are supplied or a supplied limit is negative. |
Internally, the device stores count rate in counts/10s and dose in uR. It appears that the device uses a fixed 100 Sv/R conversion.
If count_unit_cpm is not specified, the count rate register(s) will be set to the specified values without any conversion. If it is specified, count rate will be scaled, and the display units register will also be set.
If dose_unit_sv is not specified the dose argument is assumed to be in uR, and the dose alarm register will be set. If dose_unit_sv is true, the dose argument will be assumed to be in uSv, will be converted to uR and stored, and the display unit will be set to Sv. If dose_unit_sv is False, the dose argument will be assumed to be in uR, will be stored as such, and the display unit will be set to R.
Source code in src/radiacode/radiacode.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 | |