haniwers.v1.cli.port#
Port management commands for haniwers v1 CLI.
Provides commands for discovering and testing serial ports. Helps users identify which port connects to the OSECHI detector.
Commands: list: Show all available serial ports test: Test connectivity to OSECHI detector
Dependencies: - pyserial (serial.tools.list_ports): Serial port enumeration - loguru: Structured logging
Module Contents#
Classes#
One line of data from OSECHI detector. |
|
Result of a port connectivity test. |
Functions#
List all available serial ports. |
|
Test connectivity to OSECHI detector. |
Data#
API#
- haniwers.v1.cli.port.app#
‘Typer(…)’
- class haniwers.v1.cli.port.DetectorData#
One line of data from OSECHI detector.
Format: “top mid btm adc tmp atm hmd” Example: “2 0 0 936 27.37 100594.35 41.43”
Fields: top: Top layer hit count (0-10) mid: Middle layer hit count (0-10) btm: Bottom layer hit count (0-10) adc: ADC value (0-1023, 10-bit) tmp: Temperature in °C (15-35) atm: Atmospheric pressure in Pa (95000-105000) hmd: Humidity in % (0-100)
- top: int#
None
- mid: int#
None
- btm: int#
None
- adc: int#
None
- tmp: float#
None
- atm: float#
None
- hmd: float#
None
- classmethod from_line(line: str) haniwers.v1.cli.port.DetectorData#
Parse a line of detector data.
Args: line: Space-separated values string
Returns: DetectorData instance
Raises: ValueError: If line format is invalid
Example: >>> data = DetectorData.from_line(“2 0 0 936 27.37 100594.35 41.43”) >>> data.tmp 27.37
- is_valid() bool#
Check if values are within expected ranges.
Returns: True if all values are reasonable, False otherwise
- class haniwers.v1.cli.port.TestResult#
Result of a port connectivity test.
Stores whether the test succeeded and why.
Fields: success: True if test passed, False otherwise message: Human-readable result message response_time: Time to receive data in seconds (optional) data_sample: First line of data received (optional) error_type: Error category if failed (optional)
- success: bool#
None
- message: str#
None
- response_time: Optional[float]#
None
- data_sample: Optional[str]#
None
- error_type: Optional[str]#
None
- classmethod success_result(response_time: float, data_sample: str) haniwers.v1.cli.port.TestResult#
Create a successful test result.
Args: response_time: Time taken to receive data (seconds) data_sample: First line of valid data
Returns: TestResult with success=True
- classmethod failure_result(error_type: str, message: str) haniwers.v1.cli.port.TestResult#
Create a failed test result.
Args: error_type: Category of error (timeout, permission, etc.) message: Human-readable error explanation
Returns: TestResult with success=False
- format_for_display() str#
Format result for user-friendly display.
Returns: Multi-line formatted string with all relevant info
- haniwers.v1.cli.port.list() None#
List all available serial ports.
Shows device paths, descriptions, and USB information for all serial ports on the system.
Example: $ haniwers-v1 port list
- haniwers.v1.cli.port.test_port_connectivity(device: str = typer.Argument(..., help='Device path to test (e.g., /dev/ttyUSB0, COM3)'), baudrate: int = typer.Option(115200, '--baudrate', min=1, help='Serial communication baud rate in bits per second (e.g., 9600, 115200).', rich_help_panel='Device Settings'), timeout: float = typer.Option(5.0, '--timeout', min=0.1, help='Serial read timeout in seconds (e.g., 1.0, 5.0).', rich_help_panel='Device Settings')) None#
Test connectivity to OSECHI detector.
Opens the specified port and attempts to read detector data to verify it’s the correct device.
Args: device: Path to serial device (e.g., /dev/ttyUSB0, COM3) baudrate: Baud rate in bits per second (default: 115200) timeout: Read timeout in seconds (default: 5.0)
Example: \( haniwers-v1 port test /dev/ttyUSB0 \) haniwers-v1 port test COM3 --timeout 10 \( haniwers-v1 port test /dev/ttyUSB0 --baudrate 9600 \) haniwers-v1 port test /dev/ttyUSB0 --baudrate 9600 --timeout 10