diff --git a/vna_system/core/laser/laser_controller.py b/vna_system/core/laser/laser_controller.py index 877f597..8f32084 100644 --- a/vna_system/core/laser/laser_controller.py +++ b/vna_system/core/laser/laser_controller.py @@ -1,5 +1,7 @@ import logging import time +import json +from pathlib import Path from typing import Optional, Dict, Any from datetime import datetime @@ -26,7 +28,7 @@ class LaserController: TaskType format: String-based ("TT_CHANGE_CURR_1", "TT_CHANGE_CURR_2") """ - def __init__(self): + def __init__(self, config_path: Optional[str] = None): self.prt = None # Serial port object self.is_connected = False self.is_running = False @@ -34,14 +36,78 @@ class LaserController: self.current_status = LaserStatus() self.last_data: Optional[Dict[str, Any]] = None - # Default PI coefficients (multiplied by 256 as per device protocol) + # Load default parameters from JSON + self._load_default_parameters(config_path) + + logger.info("LaserController initialized") + + def _load_default_parameters(self, config_path: Optional[str] = None) -> None: + """ + Load default parameters from JSON configuration file. + + Args: + config_path: Path to JSON config file. If None, uses default location. + """ + try: + # Determine config file path + if config_path is None: + # Default path relative to this file + current_dir = Path(__file__).parent + config_path = current_dir / "RadioPhotonic_PCB_PC_software" / "init_params.json" + else: + config_path = Path(config_path) + + # Load JSON file + if not config_path.exists(): + logger.warning(f"Config file not found: {config_path}, using hardcoded defaults") + self._set_hardcoded_defaults() + return + + with open(config_path, 'r') as f: + config = json.load(f) + + # Set parameters from config + self.initial_temperature_1 = config.get("INITIAL_TEMPERATURE_1", 28) + self.initial_temperature_2 = config.get("INITIAL_TEMPERATURE_2", 28.9) + self.initial_current_1 = config.get("INITIAL_CURRENT_1", 33) + self.initial_current_2 = config.get("INITIAL_CURRENT_2", 35) + + # PI coefficients (multiplied by 256 as per device protocol) + self.proportional_coeff_1 = int(config.get("PROPORTIONAL_COEFF_1", 10) * 256) + self.proportional_coeff_2 = int(config.get("PROPORTIONAL_COEFF_2", 10) * 256) + self.integral_coeff_1 = int(config.get("INTEGRAL_COEFF_1", 0.5) * 256) + self.integral_coeff_2 = int(config.get("INTEGRAL_COEFF_2", 0.5) * 256) + self.message_id = config.get("MESSAGE_ID", "00FF") + + # Additional parameters + self.gui_timeout_interval = config.get("GUI_TIMEOUT_INTERVAL", 5) + self.save_points_number = config.get("SAVE_POINTS_NUMBER", 1000) + + logger.info(f"Default parameters loaded from {config_path}") + logger.info(f" Initial T1: {self.initial_temperature_1}°C, T2: {self.initial_temperature_2}°C") + logger.info(f" Initial I1: {self.initial_current_1} mA, I2: {self.initial_current_2} mA") + + except json.JSONDecodeError as e: + logger.error(f"Invalid JSON in config file: {e}") + self._set_hardcoded_defaults() + except Exception as e: + logger.error(f"Error loading config file: {e}") + self._set_hardcoded_defaults() + + def _set_hardcoded_defaults(self) -> None: + """Set hardcoded default parameters as fallback.""" + self.initial_temperature_1 = 28 + self.initial_temperature_2 = 28.9 + self.initial_current_1 = 33 + self.initial_current_2 = 35 self.proportional_coeff_1 = int(10 * 256) self.proportional_coeff_2 = int(10 * 256) self.integral_coeff_1 = int(0.5 * 256) self.integral_coeff_2 = int(0.5 * 256) self.message_id = "00FF" - - logger.info("LaserController initialized") + self.gui_timeout_interval = 5 + self.save_points_number = 1000 + logger.info("Using hardcoded default parameters") def start_cycle(self, parameters: LaserParameters) -> Dict[str, Any]: """ diff --git a/vna_system/web_ui/templates/index.html b/vna_system/web_ui/templates/index.html index 1c62cbb..3feb640 100644 --- a/vna_system/web_ui/templates/index.html +++ b/vna_system/web_ui/templates/index.html @@ -348,10 +348,10 @@

Параметры ручного режима

-
Температура лазера 1 (°C)
-
Температура лазера 2 (°C)
-
Управляющий ток лазера 1 (15-60 мА)
-
Управляющий ток лазера 2 (15-60 мА)
+
T1 (°C)
+
T2 (°C)
+
Ток L1 (мА)
+
Ток L2 (мА)