| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 加载配置文件(优先级:配置文件 > 默认配置) |
| | | /// </summary> |
| | | /// <remarks> |
| | | /// 从应用程序目录下的 StackerCraneJob/stackercrane-command-config.json 读取配置。 |
| | | /// 如果文件不存在或解析失败,使用默认配置。 |
| | | /// </remarks> |
| | | /// <returns>堆垛机命令配置</returns> |
| | | private static StackerCraneCommandConfig LoadConfig() |
| | | { |
| | | try |
| | | { |
| | | // 构造配置文件路径 |
| | | string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "StackerCraneJob", "stackercrane-command-config.json"); |
| | | if (File.Exists(configPath)) |
| | | { |
| | | // 读取并解析 JSON 配置 |
| | | string json = File.ReadAllText(configPath); |
| | | return System.Text.Json.JsonSerializer.Deserialize<StackerCraneCommandConfig>(json) ?? new StackerCraneCommandConfig(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 配置加载失败,使用默认配置 |
| | | Console.WriteLine($"配置加载失败: {ex.Message},使用默认配置"); |
| | | } |
| | | |
| | | return new StackerCraneCommandConfig(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Quartz Job 的执行入口 |
| | | /// </summary> |
| | | /// <remarks> |
| | |
| | | QuartzLogHelper.LogInfo(_logger, "Execute:订阅任务完成事件,设备: {DeviceCode}", "订阅任务完成事件", _deviceCode, _deviceCode); |
| | | } |
| | | |
| | | QuartzLogHelper.LogInfo(_logger, $"开始检查堆垛机完成状态,【{_deviceCode}】", _deviceCode); |
| | | // ========== 检查堆垛机任务完成状态 ========== |
| | | commonStackerCrane.CheckStackerCraneTaskCompleted(); |
| | | |
| | | QuartzLogHelper.LogInfo(_logger, $"检查完成,正在监听堆垛机任务完成,【{_deviceCode}】", _deviceCode); |
| | | |
| | | // ========== 检查是否可以发送新任务 ========== |
| | | //if (!commonStackerCrane.IsCanSendTask(commonStackerCrane.Communicator, commonStackerCrane.DeviceProDTOs, commonStackerCrane.DeviceProtocolDetailDTOs)) |
| | |
| | | // 堆垛机不可用(如正在执行上一任务),直接返回 |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | QuartzLogHelper.LogInfo(_logger, $"堆垛机可下发任务,【{_deviceCode}】", _deviceCode); |
| | | |
| | | // ========== 选择任务 ========== |
| | | // 任务选择下沉到专用选择器 |
| | |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | |
| | | QuartzLogHelper.LogInfo(_logger, $"获取到任务,开始构建任务下发命令,【{_deviceCode}】", _deviceCode); |
| | | |
| | | // ========== 构建命令 ========== |
| | | // 命令构建下沉到专用构建器 |
| | |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | |
| | | QuartzLogHelper.LogInfo(_logger, $"命令构建完成,开始下发任务,【{_deviceCode}】", _deviceCode); |
| | | |
| | | // ========== 发送命令 ========== |
| | | bool sendFlag = SendStackerCraneCommand(commonStackerCrane, stackerCraneTaskCommand); |
| | | if (sendFlag) |