bhpy Package
Top-level
Top-level package exports for bhpy.
This package provides thin, Pythonic wrappers around Becker & Hickl DLLs and remote-control components. The public classes are re-exported here for convenient imports, for example:
from bhpy import BHConnect, SpcQcX04
Only import from the top-level when you need the common entry-points. If you are extending the library, prefer importing from the concrete modules.
Modules
SPCConnect client wrapper.
This module provides a small, typed client (BHConnect) to discover and talk to an SPCConnect instance over TCP. It handles the session key exchange, message encryption, and convenience helpers to fetch images and traces.
The lower-level TCP server handlers in this module are implementation details used to receive large payloads (images, traces) over a temporary local port.
- class bhpy.bh_connect.BHConnect(host=None, port=None)[source]
Bases:
objectClient for discovering and controlling SPCConnect.
Typical usage:
Discover instance via mDNS and connect:
connect_spcm_instance()Send simple commands:
command("Version:number")Receive data:
get_image(...)/get_trace(...)
Encryption is handled transparently. The client writes the temporary key files under the per-user data directory for debugging purposes.
- IMAGE_TYPES
alias of
Literal[‘1stMoment’, ‘Fit’, ‘Fitted’, ‘TauChannel’]
- command(command) str[source]
Send a plain SPCConnect command and return its response.
- Parameters:
command – The command string without surrounding
$markers.- Returns:
Either
Truefor bareOK, the parsed float when possible, or the raw string payload returned by SPCConnect.- Raises:
ValueError – If SPCConnect responds with an error (non-OK).
- connect_spcm_instance(host: str = None, port: int = None, service_id: int = None)[source]
Connect to SPCConnect and perform key exchange.
Either provide both
hostandport, or let the client discover the instance viaservice_id. On success, the SPCConnect protocol version is validated.- Parameters:
host – Hostname or IP of SPCConnect.
port – TCP port of SPCConnect.
service_id – Optional mDNS service id to auto-discover.
- Returns:
The protocol version string (e.g.
"OK: 2.0.0").- Raises:
ValueError – If only one of
hostorportis provided.RuntimeError – If the protocol version is unsupported.
- find_spcm_instance(service_id: int = 1)[source]
Discover an SPCConnect instance via mDNS.
- Parameters:
service_id – The SPCConnect mDNS service suffix (default 1).
- Returns:
Trueif a reachable instance was found andhost/portare set accordingly, otherwiseFalse.
- get_image(window=1, cycle=1, image_type: Literal['1stMoment', 'Fit', 'Fitted', 'TauChannel'] = '1stMoment', fit_config: tuple[str, int] = None, tau_channel: str = None)[source]
Request image data and receive it as local temp files.
Depending on the requested
image_typeand arguments, the method spins up a local TCP server for the duration of the transfer, and returns a list of file paths to the received TIFF images.- Parameters:
window – Window index (use
-1for all windows).cycle – Cycle index for the selected window.
image_type – One of
"1stMoment","Fit","Fitted", or"TauChannel".fit_config – Optional tuple of (config_name, int_value) for fit images.
tau_channel – Optional tau channel when
image_typeisTauChannel.
- Returns:
List of absolute file paths to the received images.
- get_trace(trace_type=11, trace_number=1)[source]
Request a trace and return the values as a list of ints.
- Parameters:
trace_type – Trace type (currently unused; reserved for extension).
trace_number – One-based trace index.
- Returns:
List of unsigned 32-bit values representing the trace.
- class bhpy.bh_connect.CustomTCPServer(server_address, request_handler_class, request_handler_queue, done_queue=None, bind_and_activate=True, all_windows=False, file_name=None)[source]
Bases:
TCPServerTiny TCP server used to receive streamed data.
This server is spun up on a random local port to receive images/traces that SPCConnect sends back after a request. Do not use this class directly; it is an internal helper for BHConnect.get_image/get_trace.
Hardware device discovery wrapper.
This module wraps the bh_device_scan.dll to enumerate connected Becker & Hickl hardware modules and their firmware versions.
- class bhpy.bh_device_scan_wrapper.BHDeviceScan(dll_path=None)[source]
Bases:
objectThin wrapper around
bh_device_scan.dll.Instantiate once, then call
bh_scan_hardware()to list connected modules. Raises on incompatible DLL version.- bh_scan_hardware() list[source]
Scan for connected devices.
- Returns:
List of tuples
(friendly_name, serial_number, firmware_version)for each detected device. Returns an empty list if none found.
- version_str = ''
- version_str_buf = <ctypes.c_char_Array_128 object>
- class bhpy.bh_device_scan_wrapper.HardwareScanResult[source]
Bases:
Structurectypes structure used by the DLL to report scan results.
Fields map to fixed-size C strings returned by the scan function.
- firmwareVersion
Structure/Union member
- friendlyName
Structure/Union member
- serialNumber
Structure/Union member
LabVIEW connector wrappers for QC008 and BDU.
This module wraps two DLLs used to control external LabVIEW applications:
ControlQC008.dllviaLVConnectQC008ControlBDU.dllviaLVConnectBDU
Both classes provide a high-level command method alongside a set of
properties and helpers for common operations.
- class bhpy.bh_lv_wrapper.LVConnectBDU(dll_path: Path | str | None = None, machine_name: str | None = None, default_timeout_s: int = 3, error_string_buffer_len: int = 512, result_string_buffer_len: int = 512)[source]
Bases:
objectWrapper class for interfacing with a BDU laser via the BDU application.
- - command(command
INSTRUCTIONS | str, command_arg: str = None) -> str
- - close() -> bool
- Properties:
arming
power
frequency
- Read only properties:
firmware_version
emission
serial_number
wavelength
frequencies
connected
Note that reading or writing any property as well as sending any command without an instance of the BDU application will raise a ChildProcessError.
- INSTRUCTIONS
alias of
Literal[‘Armed’, ‘GetArmed’, ‘Power’, ‘GetPower’, ‘Frequ’, ‘GetFreq’, ‘GetFreqStrings’, ‘GetEmissionStatus’, ‘GetSN’, ‘GetWL’, ‘GetFwVersion’, ‘Stop’]
- property arming: bool
Sets/Returns the state of the arming control in the BDU application.
When enabled the laser and the laser power is set to greater than 0.0 the laser might emit light given that external conditions do not prevent the BDU from doing so.
- command(command: Literal['Armed', 'GetArmed', 'Power', 'GetPower', 'Frequ', 'GetFreq', 'GetFreqStrings', 'GetEmissionStatus', 'GetSN', 'GetWL', 'GetFwVersion', 'Stop'] | str, command_arg: str = None) str[source]
Sends a command and optional arguments to the connected BDU application.
This can be used to facilitate functionalities/commands that are not yet wrapped by this library.
As long as the application is still loading the command is blocking.
- property connected: bool
Returns the connection state of a BDU laser and the BDU application.
- property emission: bool
Returns the emission state of the connected BDU.
External factors like laser interlock or external trigger signals can result in a false positive. Meaning the emission state merely indicates the possibility on part of the software for the laser actually emitting light.
- property firmware_version: str
Returns the firmware version string of the connected BDU
- property frequencies: list[str]
Returns the pulse frequency names (if present including CW) of the connected BDU laser as a list of strings.
These names are the possible names that can be used to set the frequency property.
- property frequency: str
Sets/Returns the current pulse frequency of the connected BDU laser.
Raises a ValueError if the given frequency name is not one of the puls frequency names of the connected BDU laser.
- property power: float
Sets/Returns the current laser power of the connected BDU laser in %.
Raises a ValueError if set to something outside of the allowed range from 0.0 to 100.0 [%].
- property serial_number: str | None
Returns the serial number string of the connected BDU.
- property wavelength: float | None
Returns the wavelength of the connected BDU in nm.
- class bhpy.bh_lv_wrapper.LVConnectQC008(dll_path: Path | str | None = None, machine_name: str | None = None, default_timeout_s: int = 3, error_string_buffer_len: int = 512, result_string_buffer_len: int = 512)[source]
Bases:
objectWrapper around
ControlQC008.dllfor SPC QC 008 control.Provides a typed command interface and properties for querying status and rates, as well as helpers to orchestrate common actions.
- INSTRUCTIONS
alias of
Literal[‘AutoAdjust’, ‘HideAnalysis’, ‘HideCardSettings’, ‘HideCorrelation’, ‘HideDebugInfo’, ‘HideDeltaT’, ‘HideMCS’, ‘LoadAutoSavedSettings’, ‘RepeatMeasurement’, ‘ScanThreshold’, ‘ShowAnalysis’, ‘ShowCardSettings’, ‘ShowCorrelation’, ‘ShowDebugInfo’, ‘ShowDeltaT’, ‘ShowMCS’, ‘StartMeasurement’, ‘StopMeasurement’]
- MEASUREMENT_STATUS
alias of
Literal[‘repeating’, ‘measuring’, ‘noData’, ‘DataAvailable’]
- command(command: Literal['AutoAdjust', 'HideAnalysis', 'HideCardSettings', 'HideCorrelation', 'HideDebugInfo', 'HideDeltaT', 'HideMCS', 'LoadAutoSavedSettings', 'RepeatMeasurement', 'ScanThreshold', 'ShowAnalysis', 'ShowCardSettings', 'ShowCorrelation', 'ShowDebugInfo', 'ShowDeltaT', 'ShowMCS', 'StartMeasurement', 'StopMeasurement'])[source]
Send a command without arguments to the QC008 control DLL.
- property dll_version: str
- property file_saving_path: Path
- property firmware_version: str
- property gap_events: int
- property initialized: bool
- property measurement_status: Literal['repeating', 'measuring', 'noData', 'DataAvailable']
- property rates: list[int]
- property serial_number: str
Configuration helpers for SPC/TDC modules.
These classes provide simple load/save helpers and reasonable defaults for different hardware families. They write JSON files to the per-user data directory so that applications can persist configuration between runs.
- class bhpy.spc_tdc_config.Pms800Conf[source]
Bases:
objectDefault locations and helpers for PMS-800 configuration files.
- default_path = 'appdirs.user_data_dir/Pms800/Config.json'
- class bhpy.spc_tdc_config.SpcQcX04Conf(config_path: str = 'appdirs.user_data_dir/SpcQcX04/Config.json')[source]
Bases:
objectDefault locations and helpers for SPC QC X04 configuration files.
The string constants for edges are kept as-is to match the GUI representation expected by external tools.
- DELTA_TIME_MODE = 'Δt'
- NEGATIVE_EDGE = '͞ |͟ (falling)'
- POSITIVE_EDGE = '͟ |͞ (rising)'
- POS_NEG_LIST = ['͟ |͞ (rising)', '͞ |͟ (falling)']
- default_path = 'appdirs.user_data_dir/SpcQcX04/Config.json'
- load_conf(conf_path=None) None[source]
Load configuration from
conf_path; write defaults if missing.
- restore_config() None[source]
Reset hardware-related settings to safe defaults.
Settings that rarely change after initial setup (e.g. thresholds tied to the physical setup) are reset to hardware defaults or good starting points.
- restore_defaults() None[source]
Reset all settings and parameters to defaults.
Convenience dispatcher that calls the config and measurement resetters.
- class bhpy.spc_tdc_config.SpcQcX08Conf[source]
Bases:
objectDefault locations and helpers for SPC QC X08 configuration files.
- default_path = 'appdirs.user_data_dir/SpcQcX08/Config.json'
Wrappers for SPC/TDC DLLs (SPC QC X04/X08, PMS-800).
This module provides typed, Pythonic facades around the underlying C DLLs. It focuses on readability and encapsulates low-level ctypes details while exposing properties and methods aligned with the device capabilities.
Only a subset of the wide surface is annotated in detail. Refer to vendor documentation together with the docstrings below when in doubt.
- class bhpy.spc_tdc_wrapper.Markers[source]
Bases:
TypedDictTyped mapping for marker enables/polarities by name.
- frame: bool | Literal['Falling', 'Rising', 0, 1] = 0
- line: bool | Literal['Falling', 'Rising', 0, 1] = 0
- marker3: bool | Literal['Falling', 'Rising', 0, 1] = 0
- pixel: bool | Literal['Falling', 'Rising', 0, 1] = 0
- class bhpy.spc_tdc_wrapper.ModuleInit[source]
Bases:
Structurectypes structure reflecting a single module’s initialization status.
- device_nr
Structure/Union member
- device_type_str
Structure/Union member
- initialized
Structure/Union member
- serial_nr_str
Structure/Union member
- class bhpy.spc_tdc_wrapper.Pms800(dll_path: Path | str | None = None)[source]
Bases:
__8ChannelDllWrapper,__EventStream32BitWrapper for PMS-800 devices (8 channels, extended input modes).
- INPUT_MODES
alias of
Literal[‘Input’, ‘Gated Input’, ‘Calibration Input’, 0, 1, 2]
- property event_count_thresholds
- input_modes = {'Calibration Input': 2, 'Gated Input': 1, 'Input': 0}
- property inputmodes
- modes_input = {0: 'Input', 1: 'Gated Input', 2: 'Calibration Input'}
- class bhpy.spc_tdc_wrapper.SpcQcX04(dll_path: Path | str | None = None)[source]
Bases:
__EventStream32BitWrapper for SPC QC X04 devices (4 channels, 32-bit event stream).
- property cfd_thresholds: list[float]
- property cfd_zero_cross: list[float]
- property channel_delays: list[float]
- property channel_divider
- property dithering_enable
- get_events_from_buffer(buffer: numpy.typing.NDArray.numpy.uint32, max_events, card_number, filter_mtos: bool = False)[source]
Fill
bufferwith events from the device and return count.- Parameters:
buffer – Pre-allocated NumPy array of dtype
uint32.max_events – Maximum number of events to pull.
card_number – Card index to read from.
filter_mtos – If
True, apply DLL-side filtering.
- Returns:
A tuple
(buffer, events)whereeventsis the number of items written tobuffer.
- property hardware_collection_timer_expired
- property hardware_fifo_empty
- property hardware_fifo_full
- property marker_polarities
- property marker_status
- property module_is_armed
- property module_is_measuring
- property module_status
- property routing_compensation
- property routing_enables
- property trigger_polarity: Literal['Falling', 'Rising', 0, 1]
- property waiting_for_trigger
- class bhpy.spc_tdc_wrapper.SpcQcX08(dll_path: Path | str | None = None)[source]
Bases:
__8ChannelDllWrapperWrapper for SPC QC X08 devices.
Exposes 8-channel specific getters/setters for thresholds, polarities and trigger-related configuration.
- INPUT_MODES
alias of
Literal[‘Input’, ‘Calibration Input’, 0, 2]
- get_event_triplets_from_buffer(buffer: numpy.typing.NDArray.numpy.uint64, card_number: int, max_event_triplets: int | None = None) tuple[numpy.typing.NDArray.numpy.uint32, int][source]
- get_event_triplets_from_buffer_to_file(card_number: int, dir_path: str, idx: int, min_event_triplets: int, max_event_triplets: int | None = None, timeout_ms: int = 10000) tuple[str, int][source]
- input_modes = {'Calibration Input': 2, 'Input': 0}
- property inputmodes
- modes_input = {0: 'Input', 2: 'Calibration Input'}
- property sync_channel
- class bhpy.spc_tdc_wrapper.TdcLiterals[source]
Bases:
objectLiteral groups and small mappings used across TDC wrappers.
- DEFAULT_NAMES
alias of
Literal[‘spc_qc_X04’, ‘spc_qc_X08’, ‘pms_800’]
- MARKER
alias of
Literal[‘pixel’, ‘line’, ‘frame’, ‘marker3’, 0, 1, 2, 3]
- POLARITIES
alias of
Literal[‘Falling’, ‘Rising’, 0, 1]