1
huanghongfeng
2025-06-06 f5b8c1ae89286dada20ea433ffac84f4c9e72a29
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -104,13 +104,21 @@
        public void RequestInbound(CommonConveyorLine conveyorLine)
        {
            //1楼输送线判断
            HandleEvent2(conveyorLine, "PLC_WCS_B._03_PLC_EVENT", "PLC_WCS_B._03_PLC_LPN", "WCS_PLC_B._03_WCS_TO","原材料扫码站台");  //判断巷道
            HandleEvent2(conveyorLine, "PLC_WCS_C._02_PLC_EVENT", "PLC_WCS_C._02_PLC_LPN", "WCS_PLC_C._02_WCS_TO", "成品扫码站台");  //判断巷道
            CheckForEmptyPallet(conveyorLine, "PLC_WCS_B._02_PLC_EVENT", "PLC_WCS_B._02_PLC_LPN", "PLC_WCS_B._02_PLC_PUT", "R02-002-027-001-01"); //判断是否取空托出库
            CheckForEmptyPallet(conveyorLine, "PLC_WCS_C._01_PLC_EVENT", "PLC_WCS_C._01_PLC_LPN", "PLC_WCS_C._01_PLC_PUT", "R01-002-041-001-01"); //判断是否取空托出库
            ProcessConveyorEvent(conveyorLine, "PLC_WCS_B._01_PLC_EVENT", "PLC_WCS_B._01_PLC_LPN", "R02-003-027-001-01", "WCS_PLC_B._03_WCS_TO");// å¤„理 B
            ProcessConveyorEvent(conveyorLine, "PLC_WCS_C._03_PLC_EVENT", "PLC_WCS_C._03_PLC_LPN", "R01-003-041-001-01", "WCS_PLC_C._02_WCS_TO");// å¤„理 C
            try
            {
                //1楼输送线判断
                HandleEvent2(conveyorLine, "PLC_WCS_B._03_PLC_EVENT", "PLC_WCS_B._03_PLC_LPN", "WCS_PLC_B._03_WCS_TO", "原材料扫码站台");  //判断巷道
                HandleEvent2(conveyorLine, "PLC_WCS_C._02_PLC_EVENT", "PLC_WCS_C._02_PLC_LPN", "WCS_PLC_C._02_WCS_TO", "成品扫码站台");  //判断巷道
                CheckForEmptyPallet(conveyorLine, "PLC_WCS_B._02_PLC_EVENT", "PLC_WCS_B._02_PLC_LPN", "PLC_WCS_B._02_PLC_PUT", "R02-002-027-001-01"); //判断是否取空托出库
                CheckForEmptyPallet(conveyorLine, "PLC_WCS_C._01_PLC_EVENT", "PLC_WCS_C._01_PLC_LPN", "PLC_WCS_C._01_PLC_PUT", "R01-002-041-001-01"); //判断是否取空托出库
                ProcessConveyorEvent(conveyorLine, "PLC_WCS_B._01_PLC_EVENT", "PLC_WCS_B._01_PLC_LPN", "R02-003-027-001-01", "WCS_PLC_B._03_WCS_TO");// å¤„理 B
                ProcessConveyorEvent(conveyorLine, "PLC_WCS_C._03_PLC_EVENT", "PLC_WCS_C._03_PLC_LPN", "R01-003-041-001-01", "WCS_PLC_C._02_WCS_TO");// å¤„理 C
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public void RequestInbound2(CommonConveyorLine conveyorLine)
@@ -130,45 +138,53 @@
        public void ConveyorLineInFinish(CommonConveyorLine conveyorLine, string SCAddress)
        {
            DeviceProDTO? deviceProDTO2 = GetDeviceProDTO(conveyorLine, SCAddress, "R_StackerCraneLowered");    //读取输送线 â€œå †åž›æœºæ”¾ä¸‹â€ ä¿¡å·
            if (deviceProDTO2 != null)
            try
            {
                byte strsd = GetLine(conveyorLine, deviceProDTO2.DeviceChildCode);
                if (strsd == 1)
                DeviceProDTO? deviceProDTO2 = GetDeviceProDTO(conveyorLine, SCAddress, "R_StackerCraneLowered");    //读取输送线 â€œå †åž›æœºæ”¾ä¸‹â€ ä¿¡å·
                if (deviceProDTO2 != null)
                {
                    Dt_Task task = _taskService.IngStackerCraneTask2(conveyorLine.DeviceCode);
                    if (task != null && task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
                    byte strsd = GetLine(conveyorLine, deviceProDTO2.DeviceChildCode);
                    if (strsd == 1)
                    {
                        byte PLCtypeTo = 1;
                        if (task.TargetAddress == "R02-002-027-011-01")
                        Dt_Task task = _taskService.IngStackerCraneTask2(conveyorLine.DeviceCode);
                        if (task != null && task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
                        {
                            PLCtypeTo = 2;
                        }
                        DeviceProDTO? deviceProDTO3 = GetDeviceProDTO(conveyorLine, SCAddress, "W_PalletBarcode");          //写入条码
                        DeviceProDTO? deviceProDTO4 = GetDeviceProDTO(conveyorLine, SCAddress, "W_PalletLayers");           //层数
                        DeviceProDTO? deviceProDTO5 = GetDeviceProDTO(conveyorLine, SCAddress, "W_PalletType");           //类型
                        DeviceProDTO? deviceProDTO6 = GetDeviceProDTO(conveyorLine, SCAddress, "W_Destination");           //类型
                        if (deviceProDTO3 != null && deviceProDTO4 != null && deviceProDTO5 != null && deviceProDTO6 != null)
                        {
                            if (SetLinestring(conveyorLine, deviceProDTO3.DeviceProDataBlock, task.PalletCode) && SetLine(conveyorLine, deviceProDTO4.DeviceProDataBlock, (byte)task.PalletCodequantity) && SetLine(conveyorLine, deviceProDTO5.DeviceProDataBlock, PLCtypeTo) && SetLine(conveyorLine, deviceProDTO6.DeviceProDataBlock, (byte)task.PLCTo))
                            byte PLCtypeTo = 1;
                            if (task.TargetAddress == "R02-002-027-011-01")
                            {
                                PLCtypeTo = 2;
                            }
                            DeviceProDTO? deviceProDTO3 = GetDeviceProDTO(conveyorLine, SCAddress, "W_PalletBarcode");          //写入条码
                            DeviceProDTO? deviceProDTO4 = GetDeviceProDTO(conveyorLine, SCAddress, "W_PalletLayers");           //层数
                            DeviceProDTO? deviceProDTO5 = GetDeviceProDTO(conveyorLine, SCAddress, "W_PalletType");           //类型
                            DeviceProDTO? deviceProDTO6 = GetDeviceProDTO(conveyorLine, SCAddress, "W_Destination");           //类型
                            if (deviceProDTO3 != null && deviceProDTO4 != null && deviceProDTO5 != null && deviceProDTO6 != null)
                            {
                                if (SetLinestring(conveyorLine, deviceProDTO3.DeviceProDataBlock, task.PalletCode) && SetLine(conveyorLine, deviceProDTO4.DeviceProDataBlock, (byte)task.PalletCodequantity) && SetLine(conveyorLine, deviceProDTO5.DeviceProDataBlock, PLCtypeTo) && SetLine(conveyorLine, deviceProDTO6.DeviceProDataBlock, (byte)task.PLCTo))
                                {
                                LogSignalStatus($"写入放货完成信息,托盘条码,层数,类型信息成功", deviceProDTO2.DeviceChildCode);
                                    LogSignalStatus($"写入放货完成信息,托盘条码,层数,类型信息成功", deviceProDTO2.DeviceChildCode);
                                }
                                else
                                {
                                    LogSignalStatus($"写入放货完成信息,托盘条码,层数,类型信息失败", deviceProDTO2.DeviceChildCode);
                                }
                            }
                            else
                            {
                                LogSignalStatus($"写入放货完成信息,托盘条码,层数,类型信息失败", deviceProDTO2.DeviceChildCode);
                                LogSignalStatus($"未找到输送线协议信息", task.TargetAddress);
                            }
                        }
                        else
                        {
                            LogSignalStatus($"未找到输送线协议信息", task.TargetAddress);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
@@ -178,58 +194,72 @@
            return conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SCAddress && x.DeviceProParamName == Interactivet);
        }
        /// <summary>
        /// ç”¨äºŽå…¥åº“判断巷道
        /// </summary>
        /// <param name="conveyorLine"></param>
        /// <param name="eventTag"></param>
        /// <param name="barcodeTag"></param>
        /// <param name="writeTag"></param>
        private void HandleEvent(CommonConveyorLine conveyorLine, string eventTag, string barcodeTag, string writeTag)
        //新的巷道判断
        private void HandleEvent2(CommonConveyorLine conveyorLine, string eventTag, string barcodeTag, string writeTag,string Platform)
        {
            try
            {
                byte events = conveyorLine.Communicator.Read<byte>(eventTag); // è¯»å–事件
                if (events == 1)
                string barcode = conveyorLine.Communicator.Read<string>(barcodeTag).Trim(); // è¯»å–条码
                if (events == 1 && barcode != "NoRead" && barcode != "" && barcode != null)
                {
                    string barcode = conveyorLine.Communicator.Read<string>(barcodeTag); // è¯»å–条码
                    if (barcode != "1" || barcode != "0")
                    WebResponseContent content = _taskService.ToPlatform(barcode);
                    if (content != null)
                    {
                        if ((_taskService.ToPlatform(barcode)).Status)
                        if (content.Status)
                        {
                            if (conveyorLine.Communicator.Read<string>("PLC_WCS_B._01_PLC_LPN") == "")
                            if (content.Data != null)
                            {
                                // å†™å…¥å޻向2号堆垛机
                                bool result = conveyorLine.Communicator.Write(writeTag, (byte)3);   //原材料去向
                                if (result)
                                if (content.Data.ToString() == "1")
                                {
                                    WriteLog.GetLog("PLC日志").Write("写入去向:3", "去向");
                                    if (conveyorLine.Communicator.Read<string>("PLC_WCS_C._03_PLC_LPN") == "")
                                    {
                                        // å†™å…¥å޻向2号堆垛机
                                        bool result = conveyorLine.Communicator.Write(writeTag, (byte)1);   //写入去向为长巷道
                                        if (result)
                                        {
                                            wcs_PLCto01(Platform + ":成功信息", "成功", $"条码{barcode},写入去向:1");
                                        }
                                    }
                                    else
                                    {
                                        wcs_PLCto01(Platform + ":错误信息", "错误", $"条码:{barcode},原因:当前需写入去向:1,但读取输送线“堆垛机取货站台”有条码,不可写入去向");
                                    }
                                }
                                else if (content.Data.ToString() == "3")
                                {
                                    if (conveyorLine.Communicator.Read<string>("PLC_WCS_B._01_PLC_LPN") == "")
                                    {
                                        // å†™å…¥å޻向2号堆垛机
                                        bool result = conveyorLine.Communicator.Write(writeTag, (byte)3);   //写入去向为短巷道
                                        if (result)
                                        {
                                            wcs_PLCto01(Platform + ":成功信息", "成功", $"条码{barcode},写入去向:3");
                                        }
                                    }
                                    else
                                    {
                                        wcs_PLCto01(Platform + ":错误信息", "错误", $"条码:{barcode},原因:当前需写入去向:3,但读取输送线“堆垛机取货站台”有条码,不可写入去向");
                                    }
                                }
                                else
                                {
                                    wcs_PLCto01(Platform + ":错误信息", "错误", $"条码:{barcode},申请入库失败:未获取到去向");
                                }
                            }
                        }
                    }
                    if (barcode == "1")
                    {
                        // å†™å…¥å޻向2号堆垛机
                        bool result = conveyorLine.Communicator.Write(writeTag, (byte)1);   //空托去向
                        if (result)
                        else
                        {
                            WriteLog.GetLog("PLC日志").Write("空托入库,写入去向:1", "去向");
                            wcs_PLCto01(Platform + ":错误信息", "错误", $"条码:{barcode},申请入库失败:{content.Message}");
                        }
                    }
                    /*else
                    {
                        // å†™å…¥å޻向1号堆垛机
                        bool result = conveyorLine.Communicator.Write(writeTag, (byte)1);
                        if (result)
                        {
                            WriteLog.GetLog("PLC日志").Write("写入去向:2", "去向");
                        }
                        WriteLog.GetLog("PLC日志").Write("入库失败", "入库组盘");
                    }*/
                }
                else
                {
                    wcs_PLCto01(Platform + ":错误信息", "错误", $"读取到输送线,申请:{events},条码:{barcode}");
                }
            }
            catch (Exception ex)
@@ -239,92 +269,35 @@
            }
        }
        //新的巷道判断
        private void HandleEvent2(CommonConveyorLine conveyorLine, string eventTag, string barcodeTag, string writeTag,string Platform)
        {
            byte events = conveyorLine.Communicator.Read<byte>(eventTag); // è¯»å–事件
            string barcode = conveyorLine.Communicator.Read<string>(barcodeTag).Trim(); // è¯»å–条码
            if (events == 1 && barcode !="NoRead" && barcode !="" && barcode != null)
            {
                WebResponseContent content = _taskService.ToPlatform(barcode);
                if (content != null)
                {
                    if (content.Status)
                    {
                        if (content.Data != null)
                        {
                            if (content.Data.ToString() == "1")
                            {
                                if (conveyorLine.Communicator.Read<string>("PLC_WCS_C._03_PLC_LPN") == "")
                                {
                                    // å†™å…¥å޻向2号堆垛机
                                    bool result = conveyorLine.Communicator.Write(writeTag, (byte)1);   //写入去向为长巷道
                                    if (result)
                                    {
                                        wcs_PLCto01(Platform + ":成功信息", "成功", $"条码{barcode},写入去向:1");
                                    }
                                }
                                else
                                {
                                    wcs_PLCto01(Platform + ":错误信息", "错误", $"条码:{barcode},原因:当前需写入去向:1,但读取输送线“堆垛机取货站台”有条码,不可写入去向");
                                }
                            }
                            else if (content.Data.ToString() == "3")
                            {
                                if (conveyorLine.Communicator.Read<string>("PLC_WCS_B._01_PLC_LPN") == "")
                                {
                                    // å†™å…¥å޻向2号堆垛机
                                    bool result = conveyorLine.Communicator.Write(writeTag, (byte)3);   //写入去向为短巷道
                                    if (result)
                                    {
                                        wcs_PLCto01(Platform + ":成功信息", "成功", $"条码{barcode},写入去向:3");
                                    }
                                }
                                else
                                {
                                    wcs_PLCto01(Platform + ":错误信息", "错误", $"条码:{barcode},原因:当前需写入去向:3,但读取输送线“堆垛机取货站台”有条码,不可写入去向");
                                }
                            }
                            else
                            {
                                wcs_PLCto01(Platform + ":错误信息", "错误", $"条码:{barcode},申请入库失败:未获取到去向");
                            }
                        }
                    }
                    else
                    {
                        wcs_PLCto01(Platform + ":错误信息", "错误", $"条码:{barcode},申请入库失败:{content.Message}");
                    }
                }
            }
            else
            {
                wcs_PLCto01(Platform+":错误信息", "错误", $"读取到输送线,申请:{events},条码:{barcode}");
            }
        }
        //用于判断是否补空托 A区
        private void CheckForEmptyPallet(CommonConveyorLine conveyorLine, string eventTag, string barcodeTag, string plcput, string Loc)
        {
            Byte events = conveyorLine.Communicator.Read<Byte>(eventTag);  // è¯»å–事件
            if (events == 1)        //1为空,0为有
            try
            {
                WebResponseContent content = _taskService.RequestWMSTask2("", Loc);
                // ç”Ÿæˆå †åž›æœºå–空托任务
                if (content.Status)
                Byte events = conveyorLine.Communicator.Read<Byte>(eventTag);  // è¯»å–事件
                if (events == 1)        //1为空,0为有
                {
                    wcs_PLCto02(Loc + ":成功信息", "成功", $"已生成空托出库任务");
                    WebResponseContent content = _taskService.RequestWMSTask2("", Loc);
                    // ç”Ÿæˆå †åž›æœºå–空托任务
                    if (content.Status)
                    {
                        wcs_PLCto02(Loc + ":成功信息", "成功", $"已生成空托出库任务");
                    }
                    else
                    {
                        wcs_PLCto02(Loc + ":错误信息", "错误", $"未生成空托出库任务,错误信息:{content.Message}");
                    }
                }
                else
                {
                    wcs_PLCto02(Loc + ":错误信息", "错误", $"未生成空托出库任务,错误信息:{content.Message}");
                    wcs_PLCto02(Loc + ":错误信息", "错误", $"读取到输送线,申请:{events}");
                }
            }
            else
            catch (Exception ex)
            {
                wcs_PLCto02(Loc + ":错误信息", "错误", $"读取到输送线,申请:{events}");
                throw;
            }
        }
@@ -332,97 +305,105 @@
        //用于判断入库站台
        private void ProcessConveyorEvent(CommonConveyorLine conveyorLine, string eventTag, string barcodeTag, string taskCode, string writeTag)
        {
            byte eventStatus = conveyorLine.Communicator.Read<byte>(eventTag);
            if (eventStatus == 1)
            try
            {
                string barcode = conveyorLine.Communicator.Read<string>(barcodeTag).Trim();
                if (barcode != null)
                byte eventStatus = conveyorLine.Communicator.Read<byte>(eventTag);
                if (eventStatus == 1)
                {
                    bool result = conveyorLine.Communicator.Write(writeTag, (byte)0);
                    wcs_PLCto03("去向清除", "成功", $"地址:{writeTag},去向清除为:0");
                    WebResponseContent content = _taskService.RequestWMSTask(barcode, taskCode); // ç”³è¯·å…¥åº“,生成堆垛机任务
                    if (content != null)
                    string barcode = conveyorLine.Communicator.Read<string>(barcodeTag).Trim();
                    if (barcode != null)
                    {
                        if (content.Status)
                        bool result = conveyorLine.Communicator.Write(writeTag, (byte)0);
                        wcs_PLCto03("去向清除", "成功", $"地址:{writeTag},去向清除为:0");
                        WebResponseContent content = _taskService.RequestWMSTask(barcode, taskCode); // ç”³è¯·å…¥åº“,生成堆垛机任务
                        if (content != null)
                        {
                            wcs_PLCto03(taskCode + ":成功信息", "成功", $"条码:{barcode},申请入库成功");
                            if (content.Status)
                            {
                                wcs_PLCto03(taskCode + ":成功信息", "成功", $"条码:{barcode},申请入库成功");
                            }
                            else
                            {
                                wcs_PLCto03(taskCode + ":错误信息", "错误", $"条码:{barcode},申请入库失败,错误信息:{content.Message}");
                            }
                        }
                        else
                        {
                            wcs_PLCto03(taskCode+ ":错误信息", "错误", $"条码:{barcode},申请入库失败,错误信息:{content.Message}");
                            wcs_PLCto03(taskCode + ":错误信息", "错误", $"条码:{barcode},申请入库失败,错误信息content返回值为空");
                        }
                    }
                    else
                    {
                        wcs_PLCto03(taskCode + ":错误信息", "错误", $"条码:{barcode},申请入库失败,错误信息content返回值为空");
                        wcs_PLCto03(taskCode + ":错误信息", "错误", $"读取到输送线信息为空");
                    }
                }
                else
                else if (eventStatus == 6)
                {
                    wcs_PLCto03(taskCode + ":错误信息", "错误", $"读取到输送线信息为空");
                }
            }
            else if (eventStatus == 6)
            {
                if (taskCode == "R02-003-027-011-01")
                {
                    WebResponseContent content = _taskService.RequestWMSTask4();
                    if (content != null)
                    if (taskCode == "R02-003-027-011-01")
                    {
                        if(content.Status && content.Data != null)
                        WebResponseContent content = _taskService.RequestWMSTask4();
                        if (content != null)
                        {
                            if (content.Data.ToString() == "1")
                            if (content.Status && content.Data != null)
                            {
                                if (conveyorLine.Communicator.Write(writeTag, (byte)1))
                                if (content.Data.ToString() == "1")
                                {
                                    wcs_PLCto04(taskCode + ":成功信息", "成功", $"写入成功,去向:1");
                                    if (conveyorLine.Communicator.Write(writeTag, (byte)1))
                                    {
                                        wcs_PLCto04(taskCode + ":成功信息", "成功", $"写入成功,去向:1");
                                    }
                                    else
                                    {
                                        wcs_PLCto04(taskCode + ":错误信息", "错误", $"写入失败,去向:1");
                                    }
                                }
                                else
                                else if (content.Data.ToString() == "3")
                                {
                                    wcs_PLCto04(taskCode + ":错误信息", "错误", $"写入失败,去向:1");
                                }
                            }
                            else if (content.Data.ToString() == "3")
                            {
                                if (conveyorLine.Communicator.Write(writeTag, (byte)3))
                                {
                                    wcs_PLCto04(taskCode + ":成功信息", "成功", $"写入成功,去向:3");
                                    if (conveyorLine.Communicator.Write(writeTag, (byte)3))
                                    {
                                        wcs_PLCto04(taskCode + ":成功信息", "成功", $"写入成功,去向:3");
                                    }
                                    else
                                    {
                                        wcs_PLCto04(taskCode + ":错误信息", "错误", $"写入失败,去向:3");
                                    }
                                }
                                else
                                {
                                    wcs_PLCto04(taskCode + ":错误信息", "错误", $"写入失败,去向:3");
                                    wcs_PLCto04(taskCode + ":错误信息", "错误", $"未找到写入去向");
                                }
                            }
                            else
                            {
                                wcs_PLCto04(taskCode + ":错误信息", "错误", $"未找到写入去向");
                                wcs_PLCto04(taskCode + ":错误信息", "错误", $"申请入库失败,错误信息:{content.Message}");
                            }
                        }
                        else
                        {
                            wcs_PLCto04(taskCode + ":错误信息", "错误", $"申请入库失败,错误信息:{content.Message}");
                            wcs_PLCto04(taskCode + ":错误信息", "错误", $"申请入库失败,错误信息:content返回值为空");
                        }
                    }
                    else
                    {
                        wcs_PLCto04(taskCode + ":错误信息", "错误", $"申请入库失败,错误信息:content返回值为空");
                    }
                }
                else if (taskCode == "R01-003-041-011-01")
                {
                    if (conveyorLine.Communicator.Write(writeTag, (byte)1))
                    {
                        wcs_PLCto04(taskCode + ":成功信息", "成功", $"写入失败,去向:1");
                    }
                    else
                    else if (taskCode == "R01-003-041-011-01")
                    {
                        wcs_PLCto04(taskCode + ":错误信息", "错误", $"写入失败,去向:1");
                    }
                        if (conveyorLine.Communicator.Write(writeTag, (byte)1))
                        {
                            wcs_PLCto04(taskCode + ":成功信息", "成功", $"写入失败,去向:1");
                        }
                        else
                        {
                            wcs_PLCto04(taskCode + ":错误信息", "错误", $"写入失败,去向:1");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public bool SetLine(CommonConveyorLine conveyorLine, string DeviceProDataBlock, byte Pali)
        {