zxx
2025-05-31 267ffc1263e9975adf0d3dcca9ccc5d7dbd239f6
HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs
@@ -26,6 +26,7 @@
using System.ComponentModel;
using Newtonsoft.Json.Linq;
using S7.Net;
using System.Threading.Tasks;
namespace HH.WCS.JuShi.process
{
@@ -823,6 +824,53 @@
                    {
                        list.RemoveAll(s => loca.Contains(s.S_CODE));
                    }
                    // 3. 如果是立库入库区,检查 PLC 是否允许卸载
                    var reservoirs = Settings.ReservoirAreas.FirstOrDefault(s => s.areaName == "立库入库区");
                    if (reservoirs != null && reservoirs.areaCode.Equals(area))
                    {
                        var plcDeviceTable = S7Helper.plcDeviceTables;
                        // 先收集要移除的货位,避免在遍历时修改集合
                        List<Location> locationsToRemove = new List<Location>();
                        foreach (var location in list)
                        {
                            var safeInteraction = Settings.SafeInteractions.FirstOrDefault(s => s.location == location.S_CODE);
                            if (safeInteraction != null)
                            {
                                // 检查 PLC 是否允许卸载(取第二位数字,判断是否为 1)
                                string allowUnloadStr = plcDeviceTable.RGVAllowUnload[safeInteraction.code].ToString();
                                int allowUnload = int.Parse(allowUnloadStr.Substring(1, 1));
                                if (allowUnload != 1)
                                {
                                    locationsToRemove.Add(location); // 不允许卸载,加入待移除列表
                                }
                            }
                        }
                        // 遍历结束后,再统一移除不符合条件的货位
                        foreach (var locToRemove in locationsToRemove)
                        {
                            list.Remove(locToRemove);
                        }
                    }
                    ////过滤一下 允许进入的才分配
                    //var reservoirs = Settings.ReservoirAreas.Where(s => s.areaName == "立库入库区").FirstOrDefault();
                    //if (reservoirs.areaCode.Equals(area))
                    //{
                    //    var plcDeviceTable = S7Helper.plcDeviceTables;
                    //    foreach (var l in list)
                    //    {
                    //        var safeInteraction = Settings.SafeInteractions.Where(s => s.location == l.S_CODE).FirstOrDefault();
                    //        var res = int.Parse(plcDeviceTable.RGVAllowUnload[safeInteraction.code].ToString().Substring(1, 1));
                    //        if (res!=1)
                    //        {
                    //            list.Remove(l);
                    //        }
                    //    }
                    //}
                    //符合条件的排序选第一个  先找第一个
                    if (list.Count > 0)
                    {
@@ -1762,7 +1810,7 @@
                    {
                        LogHelper.Info($"RGV安全交互  请求点位:{model.STATION_NAME}请求码:{model.APPLY_CODE}");
                        //处理信号
                        var res =int.Parse(plcDeviceTable.RGVAllowUnload[reservoirs.code].ToString().Substring(1, 1));
                        var res = int.Parse(plcDeviceTable.RGVAllowUnload[reservoirs.code].ToString().Substring(1, 1));
                        //根据ip读状态
                        LogHelper.Info($"RGV安全交互缓存信号{res},{JsonConvert.SerializeObject(plcDeviceTable.RGVAllowUnload)}");
                        //卸货请求进入
@@ -1779,7 +1827,20 @@
                        else if (model.APPLY_CODE.Equals("8"))
                        {
                            //发送卸货完成、复位信号
                            safeAssistant(reservoirs.code,res);
                            //卸货完成信号
                            S7Helper.WriteInt(50, reservoirs.code * 2 - 2, (short)(reservoirs.code * 10 + 1));
                            // 启动后台任务处理延迟复位
                            Task.Run(async () =>
                            {
                                //10秒后复位
                                await Task.Delay(10000);
                                S7Helper.WriteInt(50, reservoirs.code * 2 - 2, (short)(reservoirs.code * 10));
                                LogHelper.Info($"RGV安全交互 复位完成");
                            });
                            //10秒后复位
                            //S7Helper.WriteInt(50, reservoirs.code * 2 - 2, (short)(reservoirs.code * 10));
                            //safeAssistant(reservoirs.code, res);
                            LogHelper.Info($"RGV安全交互 卸货完成");
                            return new safeResult() { code = "0", msg = "success" };
                        }
@@ -1862,19 +1923,23 @@
            }
        }
        //循环发送信号
        private static void safeAssistant(int code,int res) {
            //2卸货完成确认
            if (res != 2)
            {
                //卸货完成信号
                S7Helper.WriteInt(50, 0, (short)(code * 10 + 1));
                Thread.Sleep(3000);
                safeAssistant(code,res);
            }
            else
            {
                S7Helper.WriteInt(50, 0, (short)(code * 10));
            }
        private static void safeAssistant(int code, int res)
        {
            Thread.Sleep(10000);
            S7Helper.WriteInt(50, code * 2 - 2, (short)(code * 10));
            LogHelper.Info($"RGV安全交互 复位完成");
            ////2卸货完成确认
            //if (res != 2)
            //{
            //    //卸货完成信号
            //    S7Helper.WriteInt(50, code * 2 - 2, (short)(code * 10 + 1));
            //    Thread.Sleep(3000);
            //    safeAssistant(code, res);
            //}
            //else
            //{
            //    S7Helper.WriteInt(50, code * 2 - 2, (short)(code * 10));
            //}
        }