1
huanghongfeng
2024-11-16 3865dee5741693d2ce8cf1b1ee06242a7cbca1bb
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -18,6 +18,7 @@
using AutoMapper;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Quartz;
using StackExchange.Profiling.Internal;
@@ -36,6 +37,7 @@
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
@@ -63,12 +65,21 @@
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
                if ( conveyorLine != null )
                {
                    if(conveyorLine.DeviceCode == "1002")
                    {
                        RequestInbound(conveyorLine);   //一楼C,B区业务
                    }
                RequestInbound(conveyorLine);   //检测入料口信息
                RequestInNextAddress(conveyorLine);
                }
                //RequestInNextAddress(conveyorLine);
            }
@@ -83,40 +94,88 @@
            return Task.CompletedTask;
        }
        /// <summary>
        /// è¾“送线请求入库到哪个巷道
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void RequestInbound(CommonConveyorLine conveyorLine)
        {
            HandleEvent(conveyorLine, "PLC_WCS_B.03_EVENT", "PLC_WCS_B.03_PLC_LPN", "PLC_WCS_B.03_WCS_TO");
            HandleEvent(conveyorLine, "PLC_WCS_C.02_EVENT", "PLC_WCS_C.02_PLC_LPN", "PLC_WCS_C.02_WCS_TO");
            CheckForEmptyPallet(conveyorLine,"PLC_WCS_B.01_EVENT");
            CheckForEmptyPallet(conveyorLine,"PLC_WCS_C.01_EVENT");
            // å¤„理 B ç«™å°äº‹ä»¶
            ProcessConveyorEvent(conveyorLine, "PLC_WCS_B.01_EVENT", "PLC_WCS_B.01_PLC_LPN", "B1", "R01-003-027-001-01");
            // å¤„理 C ç«™å°äº‹ä»¶
            ProcessConveyorEvent(conveyorLine, "PLC_WCS_C.03_EVENT", "PLC_WCS_C.03_PLC_LPN", "C7", "R01-003-041-001-01");
            //1楼输送线判断
            HandleEvent(conveyorLine, "PLC_WCS_B._03_PLC_EVENT", "PLC_WCS_B._03_PLC_LPN", "WCS_PLC_B._03_WCS_TO");  //判断巷道
            HandleEvent(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
        }
        /// <summary>
        /// åˆ¤æ–­å‡ºåº“站台是否需要空托
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void ConveyorLineInFinish(CommonConveyorLine conveyorLine)
        public void RequestInbound2(CommonConveyorLine conveyorLine)
        {
            //顶楼楼输送线判断
            HandleEvent(conveyorLine, "PLC_WCS_D._05_PLC_EVENT", "PLC_WCS_D._05_PLC_LPN", "WCS_PLC_D._05_WCS_TO");  //判断入库巷道
            ProcessConveyorEvent(conveyorLine, "PLC_WCS_D._01_PLC_EVENT", "PLC_WCS_D._01_PLC_LPN", "R02-003-027-011-01", "WCS_PLC_D._05_WCS_TO");// å¤„理 1巷道 ç«™å°äº‹ä»¶å…¥ç©º
            ProcessConveyorEvent(conveyorLine, "PLC_WCS_D._03_PLC_EVENT", "PLC_WCS_D._03_PLC_LPN", "R01-003-041-011-01", "WCS_PLC_D._05_WCS_TO");// å¤„理 2巷道 ç«™å°äº‹ä»¶ å…¥ç©º
            CheckForEmptyPallet2(conveyorLine, "PLC_WCS_D._02_PLC_EVENT", "PLC_WCS_D._02_PLC_LPN", "PLC_WCS_D._02_PLC_PUT", "R02-002-027-011-01"); //原材料出库    è¯»å–条码选库区出库
            CheckForEmptyPallet2(conveyorLine, "PLC_WCS_D._04_PLC_EVENT", "PLC_WCS_D._04_PLC_LPN", "PLC_WCS_D._04_PLC_PUT", "R01-002-041-011-01"); //原材料出库    è¯»å–条码选库区出库
            //ConveyorLineInFinish(conveyorLine); //用于写入输送线条码信息,暂时未用
        }
        public void RequestInbound3(CommonConveyorLine conveyorLine)
        {
            ProcessConveyorEvent(conveyorLine, "PLC_WCS_A._02_PLC_EVENT", "PLC_WCS_A._02_PLC_LPN", "R02-003-043-011-01", "WCS_PLC_A._02_WCS_TO");// å¤„理 A21 ç«™å°äº‹ä»¶å…¥åº“
            ProcessConveyorEvent(conveyorLine, "PLC_WCS_A._03_PLC_EVENT", "PLC_WCS_A._03_PLC_LPN", "R01-003-042-011-01", "WCS_PLC_A._03_WCS_TO");// å¤„理 A22 ç«™å°äº‹ä»¶ å…¥æ–™
            ConveyorLineInFinish(conveyorLine,"R01-002-044-001-01"); //用于写入输送线条码信息,用于出库
        }
        public void ConveyorLineInFinish(CommonConveyorLine conveyorLine,string SCAddress)
        {
            DeviceProDTO? deviceProDTO2 = GetDeviceProDTO(conveyorLine,SCAddress, "R_StackerCraneLowered");    //读取输送线 â€œå †åž›æœºæ”¾ä¸‹â€ ä¿¡å·
            if ( deviceProDTO2 != null )
            {
                byte strsd = GetLine(conveyorLine, deviceProDTO2.DeviceChildCode);
                if (strsd == 1)
                {
                    Dt_Task task = _taskService.IngStackerCraneTask2(conveyorLine.DeviceCode);
                    if(task != null && task.TaskType==(int)TaskOutboundTypeEnum.Outbound)
                    {
                        byte PalletType = 2;
                        if (task.TargetAddress == "R02-002-027-001-01" || task.TargetAddress == "R01-002-041-001-01")
                        {
                            PalletType = 1;
                        }
                        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, PalletType) && SetLine(conveyorLine, deviceProDTO6.DeviceProDataBlock, (byte)task.PLCTo))
                            {
                                LogSignalStatus($"写入放货完成信息,托盘条码,层数,类型信息成功", deviceProDTO2.DeviceChildCode);
                            }
                            else
                            {
                                LogSignalStatus($"写入放货完成信息,托盘条码,层数,类型信息失败", deviceProDTO2.DeviceChildCode);
                            }
                        }
                        else
                        {
                            LogSignalStatus($"未找到输送线协议信息", task.TargetAddress);
                        }
                    }
                }
            }
        }
        //获取输送线实例
        public DeviceProDTO? GetDeviceProDTO(CommonConveyorLine conveyorLine, string SCAddress, string Interactivet)
        {
            return conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SCAddress && x.DeviceProParamName == Interactivet);
        }
        /// <summary>
        /// ç”¨äºŽå…¥åº“判断巷道
@@ -127,67 +186,179 @@
        /// <param name="writeTag"></param>
        private void HandleEvent(CommonConveyorLine conveyorLine,string eventTag, string barcodeTag, string writeTag)
        {
            int events = conveyorLine.Communicator.Read<int>(eventTag); // è¯»å–事件
            if (events == 1)
            try
            {
                string barcode = conveyorLine.Communicator.Read<string>(barcodeTag); // è¯»å–条码
                if ((_taskService.ToPlatform(barcode)).Status)
                byte events = conveyorLine.Communicator.Read<byte>(eventTag); // è¯»å–事件
                if (events == 1)
                {
                    // å†™å…¥å޻向1号堆垛机
                    bool result = conveyorLine.Communicator.Write(writeTag, 1);
                    if (result)
                    string barcode = conveyorLine.Communicator.Read<string>(barcodeTag); // è¯»å–条码
                    if(barcode != "1" || barcode != "0")
                    {
                        WriteLog.GetLog("PLC日志").Write("写入去向:1", "去向");
                        if ((_taskService.ToPlatform(barcode)).Status)
                        {
                            // å†™å…¥å޻向2号堆垛机
                            bool result = conveyorLine.Communicator.Write(writeTag, (byte)1);   //原材料去向
                            if (result)
                            {
                                WriteLog.GetLog("PLC日志").Write("写入去向:3", "去向");
                            }
                        }
                    }
                }
                else
                {
                    // å†™å…¥å޻向2号堆垛机
                    bool result = conveyorLine.Communicator.Write(writeTag, 2);
                    if (result)
                    if (barcode == "1")
                    {
                        WriteLog.GetLog("PLC日志").Write("写入去向:2", "去向");
                        // å†™å…¥å޻向2号堆垛机
                        bool result = conveyorLine.Communicator.Write(writeTag, (byte)1);   //空托去向
                        if (result)
                        {
                            WriteLog.GetLog("PLC日志").Write("空托入库,写入去向:1", "去向");
                        }
                    }
                    /*else
                    {
                        // å†™å…¥å޻向1号堆垛机
                        bool result = conveyorLine.Communicator.Write(writeTag, (byte)1);
                        if (result)
                        {
                            WriteLog.GetLog("PLC日志").Write("写入去向:2", "去向");
                        }
                        WriteLog.GetLog("PLC日志").Write("入库失败", "入库组盘");
                    }*/
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        //用于判断是否补空托
        private void CheckForEmptyPallet(CommonConveyorLine conveyorLine,string eventTag)
        private void CheckForEmptyPallet(CommonConveyorLine conveyorLine,string eventTag, string barcodeTag,string plcput,string Loc)
        {
            int events = conveyorLine.Communicator.Read<int>(eventTag);  // è¯»å–事件
            if (events == 0)
            try
            {
                WriteLog.GetLog("PLC日志").Write($"读取到出库口补空托信号:{events}", "需要空托");
                // ç”Ÿæˆå †åž›æœºå–空托任务
                Byte events = conveyorLine.Communicator.Read<Byte>(eventTag);  // è¯»å–事件
                if (events == 1)        //1为空,0为有
                {
                    string barcode = conveyorLine.Communicator.Read<string>(barcodeTag); // è¯»å–条码
                    if(barcode == "")
                    {
                        WriteLog.GetLog("PLC日志出库日志").Write($"读取到出库口补空托信号:{events}", "需要空托");
                        // ç”Ÿæˆå †åž›æœºå–空托任务
                        byte plcputts = conveyorLine.Communicator.Read<byte>(plcput);
                        if (plcputts != 1)
                        {
                            if ((_taskService.RequestWMSTask2("", Loc)).Status)
                            {
                                WriteLog.GetLog("PLC日志出库日志").Write($"已生成空托出库任务:{events}", "需要空托");
                            }
                            else
                            {
                                WriteLog.GetLog("PLC日志出库日志").Write($"未生成空托出库任务:{events}", "需要空托");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        //用于判断入库站台
        private void ProcessConveyorEvent(CommonConveyorLine conveyorLine, string eventTag, string barcodeTag, string stationId, string taskCode)
        //用于判断是否出空托
        private void CheckForEmptyPallet2(CommonConveyorLine conveyorLine, string eventTag, string barcodeTag, string plcput, string Loc)
        {
            int eventStatus = conveyorLine.Communicator.Read<int>(eventTag);
            if (eventStatus == 1)
            Byte events = conveyorLine.Communicator.Read<Byte>(eventTag);  // è¯»å–事件
            if (events == 1)        //1为空,0为有
            {
                string barcode = conveyorLine.Communicator.Read<string>(barcodeTag);
                if (barcode != null)
                string barcode = conveyorLine.Communicator.Read<string>(barcodeTag); // è¯»å–条码
                if (barcode != "1" || barcode != "0")
                {
                    // æ‹¿å–托盘条码申请入库信息
                    WebResponseContent content = _taskService.RequestWMSTask(barcode, taskCode); // ç”³è¯·å…¥åº“,生成堆垛机任务
                    if (content.Status)
                    WriteLog.GetLog("PLC日志出库日志").Write($"读取到原材料出库信息,条码信息:{barcode}", "原材料出库");
                    byte outCount = conveyorLine.Communicator.Read<byte>(plcput);
                    if ((_taskService.RequestWMSTask3(barcode, outCount,Loc)).Status)
                    {
                        WriteLog.GetLog("PLC入库站台日志").Write($"申请入库成功,站台编号为:{stationId}", "站台信息");
                        //写入输送线清除信息
                        WriteLog.GetLog("PLC日志出库日志").Write($"已生成原材料出库任务,条码信息:{barcode}", "原材料出库");
                    }
                    else
                    {
                        WriteLog.GetLog("PLC入库站台日志").Write($"申请入库失败,站台编号为:{stationId}", "站台信息");
                        WriteLog.GetLog("PLC日志出库日志").Write($"未生成原材料出库任务,条码信息:{barcode}", "原材料出库");
                    }
                }
            }
        }
        //用于判断入库站台
        private void ProcessConveyorEvent(CommonConveyorLine conveyorLine, string eventTag, string barcodeTag, string taskCode,string writeTag)
        {
            byte eventStatus = conveyorLine.Communicator.Read<byte>(eventTag);
            if (eventStatus == 1)
            {
                WriteLog.GetLog("PLC入库站台日志").Write($"读取到输送线申请入库信息EVENT为:{eventStatus},站台编号为:{taskCode}", "站台信息");
                string barcode = conveyorLine.Communicator.Read<string>(barcodeTag);
                if(barcode == "1")
                {
                    string currentTime = DateTime.Now.ToString("HHmmss");
                    barcode = "KTP" + currentTime;
                }
                if (barcode != null)
                {
                    bool result = conveyorLine.Communicator.Write(writeTag, (byte)0);
                    if(taskCode== "R01-003-042-011-01")
                    {
                        if ((_taskService.ToPlatform(barcode)).Status)
                        {
                            WriteLog.GetLog("PLC入库站台日志").Write($"组盘成功,站台编号为:{taskCode}", "站台信息");
                        }
                    }
                    // æ‹¿å–托盘条码申请入库信息
                    WebResponseContent content = _taskService.RequestWMSTask(barcode, taskCode); // ç”³è¯·å…¥åº“,生成堆垛机任务
                    if (content !=null)
                    {
                        if (content.Status)
                        {
                            WriteLog.GetLog("PLC入库站台日志").Write($"申请入库成功,站台编号为:{taskCode}", "站台信息");
                        }
                        else
                        {
                            WriteLog.GetLog("PLC入库站台日志").Write($"申请入库失败,站台编号为:{taskCode}", "站台信息");
                        }
                    }
                }
                else
                {
                    WriteLog.GetLog("PLC入库站台日志").Write($"读取到输送线信息为空,站台编号为:{stationId}", "站台信息");
                    WriteLog.GetLog("PLC入库站台日志").Write($"读取到输送线信息为空,站台编号为:{taskCode}", "站台信息");
                }
            }
        }
        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);
        }
        public byte GetLine(CommonConveyorLine conveyorLine, string DeviceProDataBlock)
        {
            return conveyorLine.Communicator.Read<byte>(DeviceProDataBlock);
        }
        private void LogSignalStatus(string message, string sourceAddress)
        {
            WriteLog.GetLog("堆垛机与plc交互信号").Write($"站台编号:{sourceAddress},信息:{message}", $"{sourceAddress}");
        }
    }
}