Initial commit: merge nuescan, pymso, pybbd202, and pypewpewhops into scanengine-3
- 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>
This commit is contained in:
@@ -0,0 +1,256 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Example usage of the Coherent HOPS Laser control library.
|
||||
|
||||
This script demonstrates how to use the library to control a real laser system.
|
||||
"""
|
||||
|
||||
from coherent_hops_laser import CoherentHOPSLaser, DummyLaser, I2CMode
|
||||
import time
|
||||
|
||||
|
||||
def demo_system_info(laser):
|
||||
"""Demonstrate system information queries."""
|
||||
print("=" * 60)
|
||||
print("SYSTEM INFORMATION")
|
||||
print("=" * 60)
|
||||
|
||||
info = laser.get_system_info()
|
||||
print(f"Hardware ID: {info.hardware_id}")
|
||||
print(f"Laser Model: {info.laser_model}")
|
||||
print(f"Wavelength: {info.wavelength}")
|
||||
print(f"Power Units: {info.power_units}")
|
||||
print(f"Head Type: {info.head_type}")
|
||||
print(f"Board Revision: {info.head_board_revision}")
|
||||
print()
|
||||
|
||||
|
||||
def demo_temperature_monitoring(laser):
|
||||
"""Demonstrate temperature monitoring."""
|
||||
print("=" * 60)
|
||||
print("TEMPERATURE MONITORING")
|
||||
print("=" * 60)
|
||||
|
||||
temps = laser.get_all_temperatures()
|
||||
print(f"Main Heatsink: {temps.main:.2f}°C")
|
||||
print(f"BRF (Birefringent): {temps.brf:.2f}°C")
|
||||
print(f"SHG (2nd Harmonic): {temps.shg:.2f}°C")
|
||||
print(f"THG (3rd Harmonic): {temps.thg:.2f}°C")
|
||||
print(f"ETA: {temps.eta:.2f}°C")
|
||||
print()
|
||||
|
||||
|
||||
def demo_temperature_control(laser):
|
||||
"""Demonstrate temperature setpoint control."""
|
||||
print("=" * 60)
|
||||
print("TEMPERATURE CONTROL")
|
||||
print("=" * 60)
|
||||
|
||||
# Read current setpoints
|
||||
print("Current Setpoints:")
|
||||
print(f" Main: {laser.get_temperature_setpoint_main():.2f}°C")
|
||||
print(f" BRF: {laser.get_temperature_setpoint_brf():.2f}°C")
|
||||
print(f" SHG: {laser.get_temperature_setpoint_shg():.2f}°C")
|
||||
print()
|
||||
|
||||
# Example: Set a new setpoint (commented out for safety)
|
||||
# print("Setting Main temperature setpoint to 26.0°C...")
|
||||
# laser.set_temperature_setpoint_main(26.0)
|
||||
# print(f" New setpoint: {laser.get_temperature_setpoint_main():.2f}°C")
|
||||
print("(Temperature setpoint modification disabled in demo)")
|
||||
print()
|
||||
|
||||
|
||||
def demo_power_control(laser):
|
||||
"""Demonstrate power control."""
|
||||
print("=" * 60)
|
||||
print("POWER CONTROL")
|
||||
print("=" * 60)
|
||||
|
||||
units = laser.get_power_units()
|
||||
current_power = laser.get_power_command()
|
||||
print(f"Current Power: {current_power} {units}")
|
||||
|
||||
power_limits = laser.get_power_limits()
|
||||
print(f"Power Limits: {power_limits}")
|
||||
|
||||
power_memory = laser.get_power_memory()
|
||||
print(f"Power Memory: {power_memory}")
|
||||
print()
|
||||
|
||||
# Example: Set power (commented out for safety)
|
||||
# print("Setting power to 100.0 mW...")
|
||||
# laser.set_power_command(100.0)
|
||||
# print(f" New power: {laser.get_power_command()} {units}")
|
||||
print("(Power modification disabled in demo)")
|
||||
print()
|
||||
|
||||
|
||||
def demo_current_control(laser):
|
||||
"""Demonstrate current control."""
|
||||
print("=" * 60)
|
||||
print("CURRENT CONTROL")
|
||||
print("=" * 60)
|
||||
|
||||
current = laser.get_current_command()
|
||||
print(f"Current Command: {current} A")
|
||||
|
||||
limits = laser.get_current_limits()
|
||||
print(f"Current Limits: {limits}")
|
||||
|
||||
mode = laser.get_control_mode()
|
||||
print(f"Control Mode: {mode}")
|
||||
print()
|
||||
|
||||
|
||||
def demo_status_monitoring(laser):
|
||||
"""Demonstrate status monitoring."""
|
||||
print("=" * 60)
|
||||
print("STATUS MONITORING")
|
||||
print("=" * 60)
|
||||
|
||||
print(f"Key Switch: {laser.get_key_switch_status()}")
|
||||
print(f"Fan Status: {laser.get_fan_status()}")
|
||||
print(f"Interlock: {laser.get_interlock_status()}")
|
||||
print(f"Remote Control: {laser.get_remote_control_status()}")
|
||||
print(f"Analog Values: {laser.get_analog_values()}")
|
||||
print()
|
||||
|
||||
|
||||
def demo_configuration(laser):
|
||||
"""Demonstrate configuration register access."""
|
||||
print("=" * 60)
|
||||
print("CONFIGURATION REGISTERS")
|
||||
print("=" * 60)
|
||||
|
||||
print(f"Config Register 0: {laser.get_config_register_0()}")
|
||||
print(f"Config Register 1: {laser.get_config_register_1()}")
|
||||
print(f"Config Register 2: {laser.get_config_register_2()}")
|
||||
print(f"Config Register 3: {laser.get_config_register_3()}")
|
||||
print()
|
||||
|
||||
|
||||
def main_dummy_demo():
|
||||
"""Run demo with simulated hardware."""
|
||||
print("\n" + "=" * 60)
|
||||
print("COHERENT HOPS LASER CONTROL - SIMULATION MODE")
|
||||
print("=" * 60 + "\n")
|
||||
|
||||
with DummyLaser() as laser:
|
||||
demo_system_info(laser)
|
||||
demo_temperature_monitoring(laser)
|
||||
demo_temperature_control(laser)
|
||||
demo_power_control(laser)
|
||||
demo_current_control(laser)
|
||||
demo_status_monitoring(laser)
|
||||
demo_configuration(laser)
|
||||
|
||||
# Demonstrate power control
|
||||
print("=" * 60)
|
||||
print("POWER CONTROL DEMONSTRATION (Simulation)")
|
||||
print("=" * 60)
|
||||
print(f"Initial power: {laser.get_power_command()} mW")
|
||||
laser.set_power_command(125.0)
|
||||
print(f"After setting to 125.0 mW: {laser.get_power_command()} mW")
|
||||
print()
|
||||
|
||||
|
||||
def main_real_hardware():
|
||||
"""Run demo with real hardware."""
|
||||
print("\n" + "=" * 60)
|
||||
print("COHERENT HOPS LASER CONTROL - REAL HARDWARE")
|
||||
print("=" * 60 + "\n")
|
||||
|
||||
# Configure for your specific setup
|
||||
FTDI_URL = 'ftdi://ftdi:2232/1' # Adjust if needed
|
||||
SLAVE_ADDRESS = 0x50 # Default NXP slave address
|
||||
I2C_FREQUENCY = I2CMode.STANDARD # or I2CMode.FAST
|
||||
|
||||
try:
|
||||
# Connect to laser
|
||||
laser = CoherentHOPSLaser(
|
||||
slave_address=SLAVE_ADDRESS,
|
||||
i2c_mode=I2C_FREQUENCY
|
||||
)
|
||||
|
||||
print(f"Connecting to FTDI device at {FTDI_URL}...")
|
||||
laser.connect(FTDI_URL)
|
||||
print("Connected successfully!\n")
|
||||
|
||||
# Run demos
|
||||
demo_system_info(laser)
|
||||
demo_temperature_monitoring(laser)
|
||||
demo_status_monitoring(laser)
|
||||
demo_power_control(laser)
|
||||
demo_current_control(laser)
|
||||
|
||||
# Clean disconnect
|
||||
laser.disconnect()
|
||||
print("Disconnected successfully.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
print("\nTroubleshooting:")
|
||||
print("1. Check FTDI device is connected (lsusb | grep FTDI)")
|
||||
print("2. Verify user permissions (add user to 'dialout' or 'plugdev' group)")
|
||||
print("3. Check FTDI URL matches your device")
|
||||
print("4. Try: sudo python3 example_usage.py (not recommended long-term)")
|
||||
|
||||
|
||||
def continuous_monitoring_example():
|
||||
"""Example of continuous temperature and power monitoring."""
|
||||
print("\n" + "=" * 60)
|
||||
print("CONTINUOUS MONITORING EXAMPLE")
|
||||
print("=" * 60 + "\n")
|
||||
|
||||
with DummyLaser() as laser:
|
||||
print("Monitoring laser parameters (5 iterations)...")
|
||||
print("Press Ctrl+C to stop\n")
|
||||
|
||||
try:
|
||||
for i in range(5):
|
||||
temps = laser.get_all_temperatures()
|
||||
power = laser.get_power_command()
|
||||
mode = laser.get_control_mode()
|
||||
|
||||
print(f"[{i+1}] T_main={temps.main:.1f}°C "
|
||||
f"T_shg={temps.shg:.1f}°C "
|
||||
f"Power={power:.1f}mW "
|
||||
f"Mode={mode}")
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\nMonitoring stopped.")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
|
||||
print("Coherent HOPS Laser Control - Example Usage\n")
|
||||
print("Available demos:")
|
||||
print(" 1. Simulation mode (no hardware required)")
|
||||
print(" 2. Real hardware mode")
|
||||
print(" 3. Continuous monitoring example")
|
||||
print()
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
choice = sys.argv[1]
|
||||
else:
|
||||
choice = input("Select demo (1/2/3) [default: 1]: ").strip() or "1"
|
||||
|
||||
if choice == "1":
|
||||
main_dummy_demo()
|
||||
print("\nContinuous monitoring demo:")
|
||||
continuous_monitoring_example()
|
||||
elif choice == "2":
|
||||
main_real_hardware()
|
||||
elif choice == "3":
|
||||
continuous_monitoring_example()
|
||||
else:
|
||||
print("Invalid choice. Use 1, 2, or 3.")
|
||||
sys.exit(1)
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("Demo complete!")
|
||||
print("=" * 60)
|
||||
Reference in New Issue
Block a user