1
huanghongfeng
2024-11-11 3ecd03b3a0a30a57153468beaed3199bfe906772
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Hosting;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using Quartz;
using System;
using System.Collections.Generic;
@@ -17,6 +18,7 @@
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
@@ -47,6 +49,8 @@
                CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
                if (commonStackerCrane != null)
                {
                    //Signalinteraction(commonStackerCrane);  //出库信号交互
                    Siganlinteraction2(commonStackerCrane); //入库信号交互
                    if (!commonStackerCrane.IsEventSubscribed)
                    {
                        commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//订阅任务完成事件
@@ -54,10 +58,6 @@
                    if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal)
                    {
                        CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
                        Signalinteraction(conveyorLine, commonStackerCrane);
                        commonStackerCrane.CheckStackerCraneTaskCompleted();//防止任务完成事件监测超时,再手动触发一次
                        if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby)
@@ -175,13 +175,18 @@
        /// <returns>如果未被占用,返回传入的任务信息,否则,返回null</returns>
        private Dt_Task? OutTaskStationIsOccupied([NotNull] Dt_Task task)
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1002");
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceProDTOs.Exists(x => x.DeviceChildCode == task.TargetAddress));
            if (device != null)
            {
                CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                if (conveyorLine.IsOccupied(task.TargetAddress))//出库站台未被占用
                DeviceProDTO? deviceProDTO = GetDeviceProDTO(conveyorLine, task.TargetAddress, "R_Event");    //根据堆垛机地址,地址名称找协议
                if (deviceProDTO != null)
                {
                    return task;
                    int B_Event_Test = GetLine(conveyorLine, deviceProDTO.DeviceProDataBlock);        //判断输送线是否允许放货信号
                    if (B_Event_Test == 0)
                    {
                        return task;
                    }
                }
            }
            else
@@ -235,20 +240,623 @@
            return null;
        }
        public void Signalinteraction(CommonConveyorLine conveyorLine, CommonStackerCrane commonStackerCrane)
        public void Signalinteraction(CommonStackerCrane commonStackerCrane)
        {
            //入库信号交互
            int B_Event = conveyorLine.Communicator.Read<int>("PLC_WCS_B.01_EVENT");
            int B_Event2 = conveyorLine.Communicator.Read<int>("PLC_WCS_C.03_EVENT");
            if (B_Event == 1 || B_Event2 == 1)
            if (Applyrelease(commonStackerCrane)) //读取堆垛机放货申请
            {
                Stackerstatic(conveyorLine,commonStackerCrane);
            }
                Dt_Task task = _taskService.IngStackerCraneTask(commonStackerCrane.DeviceCode);
                if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
                {
                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceProDTOs.Exists(x => x.DeviceChildCode == task.TargetAddress));
                    if (device != null)
                    {
                        CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                        DeviceProDTO? deviceProDTO = GetDeviceProDTO(conveyorLine, task.TargetAddress, "R_Event");    //根据堆垛机地址,地址名称找协议
                        if (deviceProDTO != null)
                        {
                            int B_Event_Test = GetLine(conveyorLine, deviceProDTO.DeviceProDataBlock);        //判断输送线是否允许放货信号
                            if (B_Event_Test == 0)
                            {
                                if (Releasespermitted(commonStackerCrane, task.TargetAddress))  //写入堆垛机允许放货信
                                {
                                    LogSignalStatus("写入堆垛机允许放货信号失败", task.TargetAddress);
                                }
                            }
                            else
                            {
                                LogSignalStatus("未读取到输送线允许放货信号", task.TargetAddress);
                            }
                        }
            //出库信号交互
            //Stackerstatic2(conveyorLine, commonStackerCrane);
                        if (Completesignal(commonStackerCrane, task.TargetAddress))        //读取到放货完成信号
                        {
                            if(PLCSignal(conveyorLine, task.TargetAddress, task.PalletCode, (byte)task.PalletCodequantity)) //写入输送线 å †åž›æœºæ”¾è´§ æ‰˜ç›˜æ¡ç ï¼Œå±‚数,类型
                            {
                                //读取输送线反馈  å †åž›æœºæ”¾ä¸‹ä¿¡å·
                                DeviceProDTO? deviceProDTO2 = GetDeviceProDTO(conveyorLine, task.SourceAddress, "R_StackerCraneLowered");    //输送线协议找读取信号
                                if (deviceProDTO != null)
                                {
                                    int B_TAKE = GetLine(conveyorLine, deviceProDTO.DeviceProDataBlock);        //读取输送线的  å †åž›æœºæ”¾ä¸‹ ä¿¡å·
                                    if (B_TAKE == 1)
                                    {
                                        //写入给堆垛机,输送线的  å †åž›æœºæ”¾ä¸‹ç¡®è®¤ ä¿¡å·
                                        if (Releasespermitted4(commonStackerCrane, task.SourceAddress))
                                        {
                                            LogSignalStatus("写入堆垛机放下信号成功", task.SourceAddress);
                                        }
                                        else
                                        {
                                            LogSignalStatus("写入堆垛机放下信号失败", task.SourceAddress);
                                        }
                                    }
                                    else
                                    {
                                        LogSignalStatus("未读取输送线的堆垛机放下信号", task.SourceAddress);
                                    }
                                }
                            }
                            else
                            {
                                LogSignalStatus("写入输送线堆垛机放货 æ‰˜ç›˜æ¡ç ï¼Œå±‚数,类型失败", task.TargetAddress);
                            }
                        }
                        else
                        {
                            LogSignalStatus("未读取到堆垛机放货完成信号", task.TargetAddress);
                        }
                    }
                }
            }
        }
        public void Siganlinteraction2(CommonStackerCrane commonStackerCrane)
        {
            Dt_Task task = _taskService.IngStackerCraneTask(commonStackerCrane.DeviceCode);
            if (task != null && task.TaskType == (int)TaskInboundTypeEnum.Inbound)
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceProDTOs.Exists(x => x.DeviceChildCode == task.SourceAddress));
                if (device != null)
                {
                    CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                    DeviceProDTO? deviceProDTO = GetDeviceProDTO(conveyorLine, task.SourceAddress, "R_Event");    //根据堆垛机地址,地址名称找协议
                    if (deviceProDTO != null)
                    {
                        int B_Event_Test = GetLine(conveyorLine, deviceProDTO.DeviceProDataBlock);        //判断输送线是否允许取货信号
                        if (B_Event_Test == 1)
                        {
                            if (Releasespermitted2(commonStackerCrane, task.SourceAddress))  //写入堆垛机允许取货信号
                            {
                                LogSignalStatus("写入堆垛机允许取货信号失败", task.SourceAddress);
                            }
                        }
                        else
                        {
                            LogSignalStatus("未读取到输送线允许取货信号", task.SourceAddress);
                        }
                    }
                    if (Completesignal2(commonStackerCrane, task.SourceAddress))    //读取堆垛机取货完成信号
                    {
                        if(PLCSignal2(conveyorLine, task.SourceAddress, "W_StackerCranePicked"))    //写入输送线取货完成信号
                        {
                            DeviceProDTO? deviceProDTO2 = GetDeviceProDTO(conveyorLine, task.SourceAddress, "R_StackerCranePicked");    //输送线协议找读取信号
                            if (deviceProDTO != null)
                            {
                                int B_TAKE = GetLine(conveyorLine, deviceProDTO.DeviceProDataBlock);        //读取输送线的  å †åž›æœºå–èµ° ä¿¡å·
                                if (B_TAKE == 1)
                                {
                                    //写入给堆垛机,输送线的  å †åž›æœºå–èµ° ä¿¡å·
                                    if(Releasespermitted3(commonStackerCrane, task.SourceAddress))
                                    {
                                        LogSignalStatus("写入堆垛机取走信号成功", task.SourceAddress);
                                    }
                                    else
                                    {
                                        LogSignalStatus("写入堆垛机取走信号失败", task.SourceAddress);
                                    }
                                }
                                else
                                {
                                    LogSignalStatus("未读取输送线的堆垛机取走信号", task.SourceAddress);
                                }
                            }
                        }
                    }
                    else
                    {
                        LogSignalStatus("未读取到堆垛机放货完成信号", task.SourceAddress);
                    }
                }
            }
        }
        //获取输送线实例
        public DeviceProDTO? GetDeviceProDTO(CommonConveyorLine conveyorLine,string SCAddress,string Interactivet)
        {
            return conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SCAddress && x.DeviceProParamName == Interactivet);
        }
        //获取堆垛机例
        public DeviceProDTO? GetDeviceProDTO2(CommonStackerCrane commonStackerCrane, string DeviceName, string Interactivet)
        {
            return commonStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == DeviceName && x.DeviceProParamName == Interactivet);
        }
        //读取堆垛机申请放货信号
        public bool Applyrelease(CommonStackerCrane commonStackerCrane)
        {
            if (commonStackerCrane.DeviceCode == "SC02")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryRequest_Bout");
                if (deviceProDTO != null)
                {
                    return GetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress);
                }
                DeviceProDTO? deviceProDTO2 = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryRequest_Dout");
                if (deviceProDTO2 != null)
                {
                    return GetStacker(commonStackerCrane, deviceProDTO2.DeviceProAddress);
                }
            }
            if (commonStackerCrane.DeviceCode == "SC01")
            {
                DeviceProDTO? deviceProDTO3 = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryRequest_Dout");
                if (deviceProDTO3 != null)
                {
                    return GetStacker(commonStackerCrane, deviceProDTO3.DeviceProAddress);
                }
                DeviceProDTO? deviceProDTO4 = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryRequest_Cout");
                if (deviceProDTO4 != null)
                {
                    return GetStacker(commonStackerCrane, deviceProDTO4.DeviceProAddress);
                }
                DeviceProDTO? deviceProDTO5 = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryRequest_Aout");
                if (deviceProDTO5 != null)
                {
                    return GetStacker(commonStackerCrane, deviceProDTO5.DeviceProAddress);
                }
            }
            return false;
        }
        //写入堆垛机允许放货信号
        public bool Releasespermitted(CommonStackerCrane commonStackerCrane, string Destinationaddress)
        {
            if (Destinationaddress == "R02-002-027-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryPermission_Bout");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            if (Destinationaddress == "R02-002-027-011-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryPermission_Dout");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            //1号
            if (Destinationaddress == "R01-002-041-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryPermission_Cout");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            if (Destinationaddress == "R01-003-041-011-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryPermission_Dout");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            if (Destinationaddress == "R01-002-044-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryPermission_Aout");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            return false;
        }
        //读取堆垛机的放货完成信号
        public bool Completesignal(CommonStackerCrane commonStackerCrane,string Destinationaddress)
        {
            if (Destinationaddress == "R02-002-027-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryCompleted_Bout");
                if (deviceProDTO != null)
                {
                    return GetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress);
                }
            }
            if (Destinationaddress == "R02-002-027-011-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryCompleted_Dout");
                if (deviceProDTO != null)
                {
                    return GetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress);
                }
            }
            //1号
            if (Destinationaddress == "R01-002-041-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryCompleted_Cout");
                if (deviceProDTO != null)
                {
                    return GetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress);
                }
            }
            if (Destinationaddress == "R01-002-041-011-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryCompleted_Dout");
                if (deviceProDTO != null)
                {
                    return GetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress);
                }
            }
            if (Destinationaddress == "R01-002-044-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryCompleted_Aout");
                if (deviceProDTO != null)
                {
                    return GetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress);
                }
            }
            return false;
        }
        //写入堆垛机放货确认信号
        public bool Releasespermitted4(CommonStackerCrane commonStackerCrane, string Destinationaddress)
        {
            if (Destinationaddress == "R02-002-027-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryCompletion_Bout");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            if (Destinationaddress == "R02-002-027-011-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryCompletion_Din");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            //1号
            if (Destinationaddress == "R01-002-041-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryCompletion_Cout");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            if (Destinationaddress == "R01-002-041-011-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryCompletion_Dout");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            if (Destinationaddress == "R01-002-043-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "DeliveryCompletion_Aout");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            return false;
        }
        //写入堆垛机允许取货信号
        public bool Releasespermitted2(CommonStackerCrane commonStackerCrane, string Destinationaddress)
        {
            if (Destinationaddress == "R02-003-027-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupRequest_Bin");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            if (Destinationaddress == "R02-003-027-011-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupRequest_Din");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            //1号
            if (Destinationaddress == "R01-003-041-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupRequest_Cin");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            if (Destinationaddress == "R01-003-041-011-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupRequest_Din");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            if (Destinationaddress == "R01-002-042-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupRequest_Ain");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            if (Destinationaddress == "R01-002-043-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupRequest_A2in");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            return false;
        }
        //读取堆垛机取货完成信号
        public bool Completesignal2(CommonStackerCrane commonStackerCrane, string Destinationaddress)
        {
            if (Destinationaddress == "R02-003-027-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupCompleted_Bin");
                if (deviceProDTO != null)
                {
                    return GetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress);
                }
            }
            if (Destinationaddress == "R02-003-027-011-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupCompleted_Din");
                if (deviceProDTO != null)
                {
                    return GetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress);
                }
            }
            //1号
            if (Destinationaddress == "R01-003-041-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupCompleted_Cin");
                if (deviceProDTO != null)
                {
                    return GetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress);
                }
            }
            if (Destinationaddress == "R01-003-041-011-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupCompleted_Din");
                if (deviceProDTO != null)
                {
                    return GetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress);
                }
            }
            if (Destinationaddress == "R01-002-042-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupCompleted_Ain");
                if (deviceProDTO != null)
                {
                    return GetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress);
                }
            }
            if (Destinationaddress == "R01-002-043-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupCompleted_A2in");
                if (deviceProDTO != null)
                {
                    return GetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress);
                }
            }
            return false;
        }
        //写入堆垛机取货确认信号
        public bool Releasespermitted3(CommonStackerCrane commonStackerCrane, string Destinationaddress)
        {
            if (Destinationaddress == "R02-003-027-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupCompletion_Bin");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            if (Destinationaddress == "R02-003-027-011-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupCompletion_Din");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            //1号
            if (Destinationaddress == "R01-003-041-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupCompletion_Cin");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            if (Destinationaddress == "R01-003-041-011-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupCompletion_Din");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            if (Destinationaddress == "R01-002-042-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupCompletion_Ain");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            if (Destinationaddress == "R01-002-043-001-01")
            {
                DeviceProDTO? deviceProDTO = GetDeviceProDTO2(commonStackerCrane, commonStackerCrane.DeviceCode, "PickupCompletion_A2in");
                if (deviceProDTO != null)
                {
                    return SetStacker(commonStackerCrane, deviceProDTO.DeviceProAddress, true);
                }
            }
            return false;
        }
        //写入输送线放货完成信号,条码,层数,类型
        public bool PLCSignal(CommonConveyorLine conveyorLine,string TargetAddress,string PalletCode,byte PalletLayers)
        {
            byte PalletType = 2;
            if (TargetAddress == "R02-002-027-001-01" || TargetAddress == "R01-002-041-001-01")
            {
                 PalletType = 1;
            }
            //处理出库放料完成后逻辑
            try
            {
                DeviceProDTO? deviceProDTO2 = GetDeviceProDTO(conveyorLine, TargetAddress, "W_StackerCraneLowered");    //放货完成信号
                DeviceProDTO? deviceProDTO3 = GetDeviceProDTO(conveyorLine, TargetAddress, "W_PalletBarcode");          //写入条码
                DeviceProDTO? deviceProDTO4 = GetDeviceProDTO(conveyorLine, TargetAddress, "W_PalletLayers");           //层数
                DeviceProDTO? deviceProDTO5 = GetDeviceProDTO(conveyorLine, TargetAddress, "W_PalletType");           //类型
                if(deviceProDTO2 !=null && deviceProDTO3 != null && deviceProDTO4 != null && deviceProDTO5 != null)
                {
                    if(SetLine(conveyorLine, deviceProDTO2.DeviceProDataBlock, 1) && SetLinestring(conveyorLine, deviceProDTO3.DeviceProDataBlock,PalletCode) && SetLine(conveyorLine, deviceProDTO2.DeviceProDataBlock, PalletLayers) && SetLine(conveyorLine, deviceProDTO2.DeviceProDataBlock, PalletType))
                    {
                        LogSignalStatus($"写入放货完成信息,托盘条码,层数,类型信息成功", TargetAddress);
                        return true;
                    }
                    else
                    {
                        LogSignalStatus($"写入放货完成信息,托盘条码,层数,类型信息失败", TargetAddress);
                    }
                }
                else
                {
                    LogSignalStatus($"未找到输送线协议信息", TargetAddress);
                }
            }
            catch (Exception ex)
            {
                LogSignalStatus($"写入失败,错误信息:{ex.Message}", TargetAddress);
                throw;
            }
            return false;
        }
        //写入输送线 å †åž›æœºå–货完成信号
        public bool PLCSignal2(CommonConveyorLine conveyorLine, string SourceAddress,string DeviceProParamName)
        {
            DeviceProDTO? deviceProDTO2 = GetDeviceProDTO(conveyorLine, SourceAddress, DeviceProParamName);    //取货完成信号
            if (deviceProDTO2 != null)
            {
                return SetLine(conveyorLine, deviceProDTO2.DeviceProDataBlock, 1);
            }
            else
            {
                LogSignalStatus($"未找到输送线协议信息", SourceAddress);
            }
            return false;
        }
        /// <summary>
        /// æ ¹æ®åè®®ï¼Œåœ°å€ï¼Œå€¼ï¼Œå†™å…¥è¾“送线信息,
        /// </summary>
        /// <param name="conveyorLine"></param>
        /// <param name="DeviceProDataBlock"></param>
        /// <param name="Pali"></param>
        /// <returns></returns>
        public bool SetLine(CommonConveyorLine conveyorLine,string DeviceProDataBlock,byte Pali)
        {
            return conveyorLine.Communicator.Write(DeviceProDataBlock, Pali);
        }
        public bool SetLinestring(CommonConveyorLine conveyorLine, string DeviceProDataBlock, string Pali)
        {
            return conveyorLine.Communicator.Write(DeviceProDataBlock, Pali);
        }
        /// <summary>
        /// æ ¹åœ°å€è¯»å–输送线信息
        /// </summary>
        /// <param name="conveyorLine"></param>
        /// <param name="DeviceProDataBlock"></param>
        /// <returns></returns>
        public int GetLine(CommonConveyorLine conveyorLine, string DeviceProDataBlock)
        {
            return conveyorLine.Communicator.Read<byte>(DeviceProDataBlock);
        }
        /// <summary>
        /// è¯»å–堆垛机地址
        /// </summary>
        /// <param name="conveyorLine"></param>
        /// <param name="DeviceProDataBlock"></param>
        /// <returns></returns>
        public bool GetStacker(CommonStackerCrane commonStackerCrane,string DeviceProDataBlock)
        {
            return commonStackerCrane.Communicator.Read<bool>(DeviceProDataBlock);
        }
        /// <summary>
        /// å†™å…¥å †åž›æœºä¿¡å·
        /// </summary>
        /// <param name="conveyorLine"></param>
        /// <param name="DeviceProDataBlock"></param>
        /// <returns></returns>
        public bool SetStacker(CommonStackerCrane commonStackerCrane, string DeviceProDataBlock,bool Pali)
        {
            return commonStackerCrane.Communicator.Write(DeviceProDataBlock, Pali);
        }
        /// <summary>
        /// ä»»åŠ¡å®žä½“è½¬æ¢æˆå‘½ä»¤Model
        /// </summary>
@@ -268,9 +876,9 @@
                string[] targetCodest = task.SourceAddress.Split("-");
                if (targetCodest.Length == 5)
                {
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodest[1]);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodest[2]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodest[3]);
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(targetCodest[1]);
                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(targetCodest[2]);
                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(targetCodest[3]);
                }
                else
                {
@@ -352,189 +960,9 @@
            }
            return stackerCraneTaskCommand;
        }
        /// <summary>
        /// æ ¹æ®ç«™å°åç§°å†™å…¥
        /// </summary>
        /// <param name="commonStackerCrane"></param>
        /// <param name="platform"></param>
        public void Stackerstatic(CommonConveyorLine conveyorLine,CommonStackerCrane commonStackerCrane)
        {
            // è°ƒç”¨æ–¹æ³•处理不同 SourceAddress çš„任务
            Dt_Task task = _taskService.IngStackerCraneTask(commonStackerCrane.DeviceName);
            if (task.SourceAddress == "R01-003-027-001-01")
            {
                HandleStackerCraneTask(conveyorLine,commonStackerCrane,task, StackerCraneDBName.Requestpickup.ToString(), StackerCraneDBName.toRequestpickup.ToString(), "WCS_PLC_B.01_WCS_TAKE");
            }
            else if (task.SourceAddress == "R01-003-041-001-01")
            {
                HandleStackerCraneTask(conveyorLine, commonStackerCrane,task, StackerCraneDBName.Requestpickuptwo.ToString(), StackerCraneDBName.toRequestpickuptwo.ToString(), "WCS_PLC_C.03_WCS_TAKE");
            }
        }
        /// <summary>
        /// å‡ºåº“信息交互
        /// </summary>
        /// <param name="commonStackerCrane"></param>
        /// <param name="platform"></param>
        public void Stackerstatic2(CommonConveyorLine conveyorLine, CommonStackerCrane commonStackerCrane)
        {
            //读取堆垛机两个站台是否有放货申请
            // æ£€æŸ¥å †åž›æœºæ˜¯å¦è¯·æ±‚放货信号
            if (commonStackerCrane.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Requestpickupout))
            {
                LogSignalStatus("读取到堆垛机申请放货信号", "R01-002-027-001-01");
                Dt_Task? task = _taskService.IngStackerCraneTask(commonStackerCrane.DeviceName);
                WriteLogAndHandleConveyorSignal(conveyorLine, commonStackerCrane, task, StackerCraneDBName.toRequestpickupout, "R01-002-027-001-01");
            }
            // åˆ¤æ–­ä¸åŒçš„站台
            /*if (task.SourceAddress == "R01-002-027-001-01")
            {
                HandleStackerCraneForAddress027001(conveyorLine, commonStackerCrane, task);
            }
            else if (task.SourceAddress == "R01-002-041-001-01")
            {
                HandleStackerCraneForAddress041001(conveyorLine, commonStackerCrane, task);
            }*/
        }
        // å°è£…入库站台
        // å®šä¹‰ä¸€ä¸ªæ–¹æ³•来处理重复的堆垛机与PLC交互操作
        private void HandleStackerCraneTask(CommonConveyorLine conveyorLine, CommonStackerCrane commonStackerCrane,Dt_Task task, string requestSignal, string completionSignal, string writeAddress)
        {
            // å°† completionSignal è½¬æ¢ä¸º StackerCraneDBName æžšä¸¾å€¼
            if (Enum.TryParse(completionSignal, out StackerCraneDBName completionEnum))
            {
                // èŽ·å–å †åž›æœºå®Œæˆä¿¡å·
                if (commonStackerCrane.GetValue<StackerCraneDBName, bool>(completionEnum))
                {
                    WriteLog.GetLog("堆垛机与plc交互信号").Write($"读取到堆垛机完成信号为 true,站台编号:{task.SourceAddress}", "站台信息");
                    // å‘输送线写入取货完成信号
                    if (conveyorLine.Communicator.Write(writeAddress, 1))
                    {
                        WriteLog.GetLog("堆垛机与plc交互信号").Write($"写入输送线取货完成信号成功,1,站台编号:{task.SourceAddress}", "站台信息");
                    }
                    else
                    {
                        WriteLog.GetLog("堆垛机与plc交互信号").Write($"写入输送线取货完成信号失败,站台编号:{task.SourceAddress}", "站台信息");
                    }
                }
                else
                {
                    WriteLog.GetLog("堆垛机与plc交互信号").Write($"读取到堆垛机完成信号为 false,站台编号:{task.SourceAddress}", "站台信息");
                }
            }
            else
            {
                WriteLog.GetLog("堆垛机与plc交互信号").Write($"无法将completionSignal字符串{completionSignal}转换为有效的枚举值", "站台信息");
            }
            if(Enum.TryParse(requestSignal, out StackerCraneDBName completionEnum2)){
                // å†™å…¥è¯·æ±‚信号
                if (commonStackerCrane.SetValue(completionEnum2, true))
                {
                    WriteLog.GetLog("堆垛机与plc交互信号").Write($"写入信号成功,{requestSignal}", "站台信息");
                }
                else
                {
                    WriteLog.GetLog("堆垛机与plc交互信号").Write($"写入信号失败,{requestSignal}", "站台信息");
                }
            }
            else
            {
                WriteLog.GetLog("堆垛机与plc交互信号").Write($"无法将completionSignal字符串{completionSignal}转换为有效的枚举值", "站台信息");
            }
        }
        private void HandleStackerCraneForAddress027001(CommonConveyorLine conveyorLine, CommonStackerCrane commonStackerCrane, Dt_Task task)
        {
            // æ£€æŸ¥å †åž›æœºæ˜¯å¦è¯·æ±‚放货信号
            if (commonStackerCrane.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Requestpickupout))
            {
                WriteLogAndHandleConveyorSignal(conveyorLine, commonStackerCrane, task, StackerCraneDBName.toRequestpickupout, "R01-002-027-001-01");
            }
            else
            {
                LogSignalStatus("未读取到堆垛机申请放货信号", task.SourceAddress);
            }
            // æ£€æŸ¥å †åž›æœºå®Œæˆä¿¡å·
            if (commonStackerCrane.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.toRequestpickup))
            {
                WriteLogAndHandleConveyorSignal(conveyorLine, commonStackerCrane, task, StackerCraneDBName.toRequestpickup, "R01-002-027-001-01");
            }
            else
            {
                LogSignalStatus("读取到堆垛机完成信号为,false", task.SourceAddress);
            }
        }
        private void HandleStackerCraneForAddress041001(CommonConveyorLine conveyorLine, CommonStackerCrane commonStackerCrane, Dt_Task task)
        {
            if (commonStackerCrane.SetValue(StackerCraneDBName.Requestpickuptwo, true))
            {
                WriteLog.GetLog("堆垛机与plc交互信号").Write($"写入信号成功,Requestpickup", "站台信息");
            }
            else
            {
                WriteLog.GetLog("堆垛机与plc交互信号").Write($"写入信号失败,Requestpickup", "站台信息");
            }
            // æ£€æŸ¥å †åž›æœºå®Œæˆä¿¡å·
            if (commonStackerCrane.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.toRequestpickuptwo))
            {
                WriteLogAndHandleConveyorSignal(conveyorLine, commonStackerCrane, task, StackerCraneDBName.toRequestpickuptwo, "R01-002-041-001-01");
            }
            else
            {
                LogSignalStatus("读取到堆垛机完成信号为,false", task.SourceAddress);
            }
        }
        private void WriteLogAndHandleConveyorSignal(CommonConveyorLine conveyorLine, CommonStackerCrane commonStackerCrane, Dt_Task task, StackerCraneDBName signalType, string sourceAddress)
        {
            // è¯»å–输送线信号
            int events = conveyorLine.Communicator.Read<int>("PLC_WCS_B.01_EVENT");
            if (events == 0)
            {
                LogSignalStatus("读取到输送线允许放货信号", sourceAddress);
                // å†™å…¥å †åž›æœºä¿¡å·
                if (commonStackerCrane.SetValue(signalType, true))
                {
                    LogSignalStatus($"写入堆垛机允许放货信号", sourceAddress);
                }
                else
                {
                    LogSignalStatus($"未写入堆垛机允许放货信号", sourceAddress);
                }
            }
            else
            {
                LogSignalStatus($"未读取到输送线允许放货信号", sourceAddress);
            }
            // å†™å…¥å–货完成信号
            if (conveyorLine.Communicator.Write("WCS_PLC_B.01_WCS_TAKE", 1))
            {
                LogSignalStatus($"写入输送线取货完成信号成功", sourceAddress);
            }
            else
            {
                LogSignalStatus($"写入输送线取货完成信号失败", sourceAddress);
            }
        }
        private void LogSignalStatus(string message, string sourceAddress)
        {
            WriteLog.GetLog("堆垛机与plc交互信号").Write($"{message},站台编号:{sourceAddress}", "站台信息");
            WriteLog.GetLog("堆垛机与plc交互信号").Write($"站台编号:{sourceAddress},信息:{message}", $"{sourceAddress}");
        }
    }
}