CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerStationJob/CommonStackerStationCraneJob.cs
@@ -73,15 +73,15 @@
                                    bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
                                    if (sendFlag)
                                    {
                                        StringBuilder builder = new StringBuilder();
                                        builder.AppendLine();
                                        builder.AppendLine($"【{commonStackerCrane.DeviceName}】堆垛机状态:【{commonStackerCrane.StackerCraneStatusDes}】,时间:【{DateTime.Now}】");
                                        builder.AppendLine($"【{commonStackerCrane.DeviceName}】手自动状态:【{commonStackerCrane.StackerCraneAutoStatusDes}】,时间:【{DateTime.Now}】");
                                        builder.AppendLine($"【{commonStackerCrane.DeviceName}】作业状态:【{commonStackerCrane.StackerCraneWorkStatusDes}】,时间:【{DateTime.Now}】");
                                        builder.AppendLine($"【{commonStackerCrane.DeviceName}】下发任务成功,【{JsonConvert.SerializeObject(stackerCraneTaskCommand, Formatting.Indented)}】");
                                        builder.AppendLine($"时间:【{DateTime.Now}】");
                                        builder.AppendLine();
                                        ConsoleHelper.WriteColorLine(builder, ConsoleColor.Blue);
                                        //StringBuilder builder = new StringBuilder();
                                        //builder.AppendLine();
                                        //builder.AppendLine($"【{commonStackerCrane.DeviceName}】堆垛机状态:【{commonStackerCrane.StackerCraneStatusDes}】,时间:【{DateTime.Now}】");
                                        //builder.AppendLine($"【{commonStackerCrane.DeviceName}】手自动状态:【{commonStackerCrane.StackerCraneAutoStatusDes}】,时间:【{DateTime.Now}】");
                                        //builder.AppendLine($"【{commonStackerCrane.DeviceName}】作业状态:【{commonStackerCrane.StackerCraneWorkStatusDes}】,时间:【{DateTime.Now}】");
                                        //builder.AppendLine($"【{commonStackerCrane.DeviceName}】下发任务成功,【{JsonConvert.SerializeObject(stackerCraneTaskCommand, Formatting.Indented)}】");
                                        //builder.AppendLine($"时间:【{DateTime.Now}】");
                                        //builder.AppendLine();
                                        //ConsoleHelper.WriteColorLine(builder, ConsoleColor.Blue);
                                        commonStackerCrane.LastTaskType = task.TaskType;
                                        _taskService.UpdateTaskStatusToNext(task.TaskNum);
                                    }
@@ -152,22 +152,41 @@
                    if (content.Status)
                    {
                        var task = content.Data as Dt_Task;
                        Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway && x.stationLocation == task.TargetAddress);
                        IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC);
                        if (device != null)
                        if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.TargetAddress == "001-000-001")
                        {
                            CommonConveyorLine_After conveyorLine = (CommonConveyorLine_After)device;
                            var proAddress = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == stationManager.stationChildCode).Where(x => x.DeviceProParamName == ConveyorLineDBName_After.InteractiveSignal.ToString()).FirstOrDefault().DeviceProAddress;
                            string? address = proAddress;
                            if (!proAddress.Contains(".0"))
                            Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway && x.stationLocation == task.TargetAddress);
                            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC);
                            if (device != null)
                            {
                                address = proAddress + ".0";
                                str = $"写入完成,给线体写入下降信号";
                                WriteInfo(commonStackerCrane.DeviceName, str);
                                ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
                                // 获取输送线对象
                                CommonConveyorLine_After conveyorLine = (CommonConveyorLine_After)device;
                                // 获取协议地址
                                var proAddress = conveyorLine.DeviceProDTOs
                                    .FirstOrDefault(x => x.DeviceChildCode == stationManager.stationChildCode && x.DeviceProParamName == ConveyorLineDBName_After.InteractiveSignal.ToString())
                                    ?.DeviceProAddress;
                                if (proAddress == null)
                                {
                                    str = "未找到协议地址";
                                    WriteInfo(commonStackerCrane.DeviceName, str);
                                    ConsoleHelper.WriteColorLine(str, ConsoleColor.Red);
                                    return;
                                }
                                string address = proAddress.Contains(".0") ? proAddress : proAddress + ".0";
                                // 写入 false 信号
                                WriteSignal(conveyorLine, address, false, commonStackerCrane.DeviceName);
                            }
                            conveyorLine.Communicator.Write(str, false);
                        }
                        else
                        {
                            _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到出库站台【{task.NextAddress}】对应的通讯对象,无法清除出库站台顶升状态");
                            else
                            {
                                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到出库站台【{task.NextAddress}】对应的通讯对象,无法清除出库站台顶升状态");
                            }
                        }
                    }
                }
@@ -211,7 +230,7 @@
            if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
            {
                if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
                if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.TargetAddress == "001-000-001")
                {
                    Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway && x.stationLocation == task.TargetAddress);
                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC);
@@ -361,5 +380,46 @@
            return stackerCraneTaskCommand;
        }
        /// <summary>
        /// 写入信号并验证写入结果
        /// </summary>
        /// <param name="conveyorLine">输送线对象</param>
        /// <param name="address">协议地址</param>
        /// <param name="signal">信号值</param>
        /// <param name="deviceName">设备名称</param>
        void WriteSignal(CommonConveyorLine_After conveyorLine, string address, bool signal, string deviceName)
        {
            string str = string.Empty;
            // 写入信号
            conveyorLine.Communicator.Write(address, signal);
            // 验证写入结果,最多重试5次
            for (int i = 0; i < 5; i++)
            {
                var isWrite = conveyorLine.Communicator.Read<bool>(address);
                if (isWrite == signal)
                {
                    break;
                }
                conveyorLine.Communicator.Write(address, signal);
            }
            // 最终验证写入结果
            var finalWrite = conveyorLine.Communicator.Read<bool>(address);
            if (finalWrite == signal)
            {
                str = $"{address}-写入{signal}成功";
                ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
                WriteInfo(deviceName, str);
            }
            else
            {
                str = $"{address}-写入{signal}失败";
                ConsoleHelper.WriteColorLine(str, ConsoleColor.Red);
                WriteInfo(deviceName, str);
            }
        }
    }
}