fc43fbe4b0
- Merged four separate hardware control projects into unified platform - Created unified requirements.txt with all dependencies - Added comprehensive .gitignore - Added project overview README Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
260 lines
6.5 KiB
Python
260 lines
6.5 KiB
Python
"""
|
|
T3R-SL Device Controller
|
|
Handles communication with T3R-SL device via USB/Serial
|
|
|
|
The T3R-SL is a specialized instrument control device that provides
|
|
timing, triggering, and coordination for the SRAS scanning system.
|
|
"""
|
|
|
|
import time
|
|
from typing import Dict, List, Optional
|
|
|
|
|
|
class T3RDevice:
|
|
"""
|
|
Controller for T3R-SL device
|
|
|
|
Provides methods for:
|
|
- Connecting/disconnecting
|
|
- Device initialization and homing
|
|
- Status monitoring
|
|
- Trigger and timing control
|
|
"""
|
|
|
|
def __init__(self):
|
|
"""Initialize T3R device controller"""
|
|
self._connected = False
|
|
self._port = None
|
|
self._homed = False
|
|
self._ready = False
|
|
|
|
# Device state
|
|
self._initialized = False
|
|
self._error_state = False
|
|
|
|
print("INFO: T3R-SL Device controller initialized (stub)")
|
|
|
|
def get_available_ports(self) -> List[str]:
|
|
"""
|
|
Get list of available COM ports
|
|
|
|
Returns:
|
|
list: Available port names
|
|
"""
|
|
# Stub implementation - return dummy ports
|
|
# In production, would scan for actual serial ports
|
|
return [
|
|
"COM1", "COM2", "COM3", "COM4", "COM5",
|
|
"/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB2"
|
|
]
|
|
|
|
def connect(self, port: str) -> bool:
|
|
"""
|
|
Connect to T3R device on specified port
|
|
|
|
Args:
|
|
port: COM port name
|
|
|
|
Returns:
|
|
bool: True if connection successful
|
|
"""
|
|
print(f"DEBUG: Connecting to T3R device on {port}")
|
|
|
|
# Stub implementation
|
|
time.sleep(0.1)
|
|
|
|
self._port = port
|
|
self._connected = True
|
|
self._ready = False # Need to initialize after connect
|
|
|
|
print(f"INFO: Connected to T3R device on {port}")
|
|
|
|
# Auto-initialize
|
|
return self._initialize()
|
|
|
|
def disconnect(self) -> bool:
|
|
"""
|
|
Disconnect from T3R device
|
|
|
|
Returns:
|
|
bool: True if disconnection successful
|
|
"""
|
|
print("DEBUG: Disconnecting from T3R device")
|
|
|
|
self._connected = False
|
|
self._homed = False
|
|
self._ready = False
|
|
self._initialized = False
|
|
|
|
print("INFO: Disconnected from T3R device")
|
|
return True
|
|
|
|
def is_connected(self) -> bool:
|
|
"""Check if device is connected"""
|
|
return self._connected
|
|
|
|
def _initialize(self) -> bool:
|
|
"""
|
|
Initialize T3R device after connection
|
|
|
|
Returns:
|
|
bool: True if initialization successful
|
|
"""
|
|
print("DEBUG: Initializing T3R device")
|
|
|
|
if not self._connected:
|
|
print("ERROR: Cannot initialize - device not connected")
|
|
return False
|
|
|
|
# Stub - simulate initialization
|
|
time.sleep(0.2)
|
|
|
|
self._initialized = True
|
|
self._error_state = False
|
|
|
|
# Perform homing
|
|
return self.home()
|
|
|
|
def home(self) -> bool:
|
|
"""
|
|
Home/zero T3R device
|
|
|
|
Returns:
|
|
bool: True if homing successful
|
|
"""
|
|
print("DEBUG: Homing T3R device")
|
|
|
|
if not self._connected or not self._initialized:
|
|
print("ERROR: Cannot home - device not initialized")
|
|
return False
|
|
|
|
# Stub - simulate homing
|
|
time.sleep(0.3)
|
|
|
|
self._homed = True
|
|
self._ready = True
|
|
|
|
print("INFO: T3R device homed successfully")
|
|
return True
|
|
|
|
def get_status(self) -> Dict[str, bool]:
|
|
"""
|
|
Get current device status
|
|
|
|
Returns:
|
|
dict: Status information
|
|
"""
|
|
return {
|
|
'connected': self._connected,
|
|
'initialized': self._initialized,
|
|
'homed': self._homed,
|
|
'ready': self._ready,
|
|
'error': self._error_state
|
|
}
|
|
|
|
def prepare_for_scan(self, params: Dict) -> bool:
|
|
"""
|
|
Prepare T3R device for scanning operation
|
|
|
|
Args:
|
|
params: Scan parameters dictionary
|
|
|
|
Returns:
|
|
bool: True if preparation successful
|
|
"""
|
|
print("DEBUG: Preparing T3R device for scan")
|
|
print(f" Number of scans: {params.get('num_scans', 1)}")
|
|
print(f" Trigger voltage: {params.get('trigger_voltage', 0)}V")
|
|
|
|
if not self._ready:
|
|
print("ERROR: T3R device not ready for scanning")
|
|
return False
|
|
|
|
# Configure device for scan parameters
|
|
# Stub implementation
|
|
time.sleep(0.1)
|
|
|
|
print("INFO: T3R device ready for scanning")
|
|
return True
|
|
|
|
def trigger_acquisition(self) -> bool:
|
|
"""
|
|
Trigger a data acquisition event
|
|
|
|
Returns:
|
|
bool: True if trigger successful
|
|
"""
|
|
if not self._ready:
|
|
print("ERROR: Cannot trigger - device not ready")
|
|
return False
|
|
|
|
print("DEBUG: Triggering acquisition")
|
|
# Stub - would send trigger command
|
|
return True
|
|
|
|
def read_position(self) -> Optional[float]:
|
|
"""
|
|
Read current position from T3R device
|
|
|
|
Returns:
|
|
float: Current position value, or None if error
|
|
"""
|
|
if not self._ready:
|
|
return None
|
|
|
|
# Stub - return dummy position
|
|
return 0.0
|
|
|
|
def set_timing_parameters(self, acquisition_time: float,
|
|
delay_time: float) -> bool:
|
|
"""
|
|
Set timing parameters for acquisition
|
|
|
|
Args:
|
|
acquisition_time: Acquisition window time in seconds
|
|
delay_time: Delay before acquisition in seconds
|
|
|
|
Returns:
|
|
bool: True if parameters set successfully
|
|
"""
|
|
print(f"DEBUG: Setting timing - acq: {acquisition_time}s, delay: {delay_time}s")
|
|
|
|
if not self._connected:
|
|
print("ERROR: Device not connected")
|
|
return False
|
|
|
|
# Stub implementation
|
|
return True
|
|
|
|
def get_error_status(self) -> Dict[str, any]:
|
|
"""
|
|
Get detailed error status
|
|
|
|
Returns:
|
|
dict: Error status information
|
|
"""
|
|
return {
|
|
'has_error': self._error_state,
|
|
'error_code': 0,
|
|
'error_message': 'No error'
|
|
}
|
|
|
|
def reset(self) -> bool:
|
|
"""
|
|
Reset T3R device to initial state
|
|
|
|
Returns:
|
|
bool: True if reset successful
|
|
"""
|
|
print("DEBUG: Resetting T3R device")
|
|
|
|
if not self._connected:
|
|
return False
|
|
|
|
self._error_state = False
|
|
self._homed = False
|
|
self._ready = False
|
|
|
|
# Re-initialize
|
|
return self._initialize()
|