Device¶
Connect to the OSECHI detector via serial port and send commands.
PortDevice handles the actual serial communication, while DeviceProtocol defines the interface that both real and mock devices follow.
Use connect() to create a device connection.
Architecture¶
Class Diagram¶
classDiagram
class DeviceProtocol {
<<interface>>
+send_command(command: str) bool
+receive_response(field_type: str) DeviceResponse
+query(command: str) DeviceResponse
+close() None
+__enter__() Self
+__exit__() None
}
class PortDevice {
-port: str
-baudrate: int
-timeout: float
-device: serial.Serial
+__init__(port, baudrate, timeout)
+send_command(command: str) bool
+receive_response(field_type: str) DeviceResponse
+query(command: str) DeviceResponse
+close() None
}
class Serial {
<<external>>
-port: str
-baudrate: int
-timeout: float
-is_open: bool
+write(data: bytes) int
+readline() bytes
+reset_input_buffer() None
+flush() None
+close() None
}
DeviceProtocol <|.. PortDevice: implements
PortDevice --> Serial: uses
Device Selection Flow¶
flowchart TD
A["device(port, mock, timeout)"] --> B{mock = True?}
B -->|Yes| C["Return MockDevice<br/>from mock.py"]
B -->|No| D{port = 'auto'?}
D -->|Yes| E["detect_port()"]
D -->|No| F["Use specified port"]
E --> G["PortDevice(port, timeout)"]
F --> G
G --> H["Serial connection<br/>to detector"]
C --> I["Testing without<br/>hardware"]
H --> J["Real device<br/>communication"]
connect¶
::: kazunoko.device.connect options: show_root_heading: true show_source: true
detect_port¶
::: kazunoko.device.detect_port options: show_root_heading: true show_source: true
DeviceProtocol¶
::: kazunoko.device.DeviceProtocol options: show_root_heading: true show_source: true
PortDevice¶
::: kazunoko.device.PortDevice options: show_root_heading: true show_source: true