分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-03-14 73a926018601d9a5a5a3d3f4c051537f45a8eff4
´úÂë¹ÜÀí/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs
@@ -1,11 +1,14 @@
using StackExchange.Redis;
using FreeSql.Internal.Model;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm;
using WIDESEA_Comm.LogInfo;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.FreeDB;
using WIDESEA_WCS.IRepositories;
using WIDESEA_WCS.Repositories;
using WIDESEA_WCS.WCSClient;
@@ -15,20 +18,26 @@
{
    public class Gantry
    {
        static VOLContext Context = new VOLContext();
        Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
        Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
        Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
        Idt_geometry_data_detectionlineRepository detectionlineRepository = new dt_geometry_data_detectionlineRepository(Context);
        Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
        Idt_mes_detailRepository mes_DetailRepository = new dt_mes_detailRepository(Context);
        Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
        Idt_patternRepository patternRepository = new dt_patternRepository(Context);
        //FreeDB freeDB = new FreeDB();
        //static VOLContext Context = new VOLContext();
        //Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
        //Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
        //Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
        //Idt_geometry_data_detectionlineRepository detectionlineRepository = new dt_geometry_data_detectionlineRepository(Context);
        ////Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
        //Idt_mes_detailRepository mes_DetailRepository = new dt_mes_detailRepository(Context);
        //Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
        //Idt_patternRepository patternRepository = new dt_patternRepository(Context);
        #region æŸ¥è¯¢è½¦è½®æ•°æ®
        public void QueryWheeldata(PLCClient client)
        {
            try
            {
                VOLContext Context = new VOLContext();
                Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
                Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
                Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
                Idt_geometry_data_detectionlineRepository detectionlineRepository = new dt_geometry_data_detectionlineRepository(Context);
                var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                List<string> names = new List<string>() { "1单元辊道下料查询车轮", "2单元辊道下料查询车轮", "3单元辊道下料查询车轮", "辊道上料查询车轮" };
                foreach (string name in names)
@@ -47,6 +56,9 @@
                                //1-找到数据,2-未找到工件类型数据
                                client.WriteByOrder("W_i_status", (byte)2, name);
                                client.WriteByOrder("R_oi_on", (byte)0, name);
                                #region æ—¥å¿—记录
                                WriteDBLog.Error(name, $"读取桁架信息:\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到机加工车轮信息", "PCS");
                                #endregion
                            }
                            else
                            {
@@ -61,6 +73,10 @@
                                client.WriteByOrder("W_i_parameter_g", (float)geometry.g, name);
                                client.WriteByOrder("W_i_parameter_h", (float)geometry.h, name);
                                client.WriteByOrder("R_oi_on", (byte)0, name);
                                #region æ—¥å¿—记录
                                WriteDBLog.Success(name, $"读取桁架信息:\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:1" + $"\na:{(float)geometry.a}\nb:{(float)geometry.b}\nc:{(float)geometry.c}\n" +
                                    $"d:{(float)geometry.d}\ne:{(float)geometry.e}\nf:{(float)geometry.f}\ng:{(float)geometry.g}\nh:{(float)geometry.h}\nR_oi_on:0", "PCS");
                                #endregion
                            }
                        }
                        else
@@ -70,6 +86,9 @@
                            {
                                client.WriteByOrder("W_i_status", (byte)2, name);
                                client.WriteByOrder("R_oi_on", (byte)0, name);
                                #region æ—¥å¿—记录
                                WriteDBLog.Error(name, $"读取桁架信息:\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到检测线车轮信息", "PCS");
                                #endregion
                            }
                            else
                            {
@@ -83,6 +102,10 @@
                                client.WriteByOrder("W_i_parameter_g", (float)geometry.g, name);
                                client.WriteByOrder("W_i_parameter_h", (float)geometry.h, name);
                                client.WriteByOrder("R_oi_on", (byte)0, name);
                                #region æ—¥å¿—记录
                                WriteDBLog.Success(name, $"读取桁架信息:\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:1" + $"\na:{(float)geometry.a}\nb:{(float)geometry.b}\nc:{(float)geometry.c}\n" +
                                    $"d:{(float)geometry.d}\ne:{(float)geometry.e}\nf:{(float)geometry.f}\ng:{(float)geometry.g}\nh:{(float)geometry.h}\nR_oi_on:0", "PCS");
                                #endregion
                            }
                        }
@@ -101,21 +124,51 @@
        {
            try
            {
                VOLContext Context = new VOLContext();
                Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
                Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
                Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
                Idt_geometry_data_detectionlineRepository detectionlineRepository = new dt_geometry_data_detectionlineRepository(Context);
                Idt_mes_detailRepository mes_DetailRepository = new dt_mes_detailRepository(Context);
                Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
                Idt_patternRepository patternRepository = new dt_patternRepository(Context);
                var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                List<string> names = new List<string>() { "1单元辊道下料查询订单", "2单元辊道下料查询订单", "3单元辊道下料查询订单", "辊道上料查询订单" };
                foreach (string name in names)
                {
                    var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == name).ToList();
                    var on = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_oi_on").First(), client);
                    //var on = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_oi_on" && x.plcdetail_number == name).First(), client);
                    if ((byte)on == 1)
                    {
                        //var wp_id = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_o_wp_id").First(), client).ToString();
                        var wp_id = client.ReadByOrder<string>("R_o_wp_id", name);
                        if (string.IsNullOrEmpty(wp_id))
                        {
                            #region æ—¥å¿—记录
                            client.WriteByOrder("W_i_status", (byte)2, name);
                            client.WriteByOrder("R_oi_on", (byte)0, name);
                            WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n车轮SN号为空", "PCS");
                            #endregion
                            continue;
                        }
                        var wp_type = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_o_wp_type").First(), client);
                        var mes_Detail = mes_DetailRepository.FindFirst(x => x.SN == wp_id);
                        #region æµ‹è¯•使用
                        if (mes_Detail == null)
                        {
                            mes_Detail = mes_DetailRepository.FindFirst(x => x.jobID == (name == "3单元辊道下料查询订单" ? "01180127004-2" : "01180127004-1"));
                            mes_Detail.SN = wp_id;
                            mes_DetailRepository.Update(mes_Detail, true);
                        }
                        #endregion
                        if (mes_Detail == null)
                        {
                            client.WriteByOrder("W_i_status", (byte)2, name);
                            client.WriteByOrder("R_oi_on", (byte)0, name);
                            #region æ—¥å¿—记录
                            WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到工单详情", "PCS");
                            #endregion
                            continue;
                        }
                        var mes_Head = mes_HeadRepository.FindFirst(x => x.jobID == mes_Detail.jobID);
@@ -123,6 +176,9 @@
                        {
                            client.WriteByOrder("W_i_status", (byte)2, name);
                            client.WriteByOrder("R_oi_on", (byte)0, name);
                            #region æ—¥å¿—记录
                            WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到工单头表", "PCS");
                            #endregion
                            continue;
                        }
@@ -134,16 +190,21 @@
                            {
                                client.WriteByOrder("W_i_status", (byte)4, name);
                                client.WriteByOrder("R_oi_on", (byte)0, name);
                                #region æ—¥å¿—记录
                                WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:4\nR_oi_on:0\n\n手动入库模式未选择库区", "PCS");
                                #endregion
                                continue;
                            }
                            var wp_type = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_o_wp_type").First(), client);
                            //var geometry = dataRepository.FindFirst(x => x.TypeId == (Int32)wp_type);
                            var geometry = dataRepository.FindFirst(x => x.Description == mes_Head.drawingNo);
                            var geometry = dataRepository.Find(x => x.Description == mes_Head.drawingNo && x.TypeId == (Int32)wp_type).FirstOrDefault();
                            if (geometry == null)
                            {
                                //1-好,允许加工,2-不在列表中,3-不加工车轮类型,4-手动入库模式人工未选择库区
                                client.WriteByOrder("W_i_status", (byte)2, name);
                                client.WriteByOrder("R_oi_on", (byte)0, name);
                                #region æ—¥å¿—记录
                                WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到机加工车轮信息", "PCS");
                                #endregion
                                continue;
                            }
                            else
@@ -159,22 +220,30 @@
                                //屏蔽工艺(屏蔽视觉检测/屏蔽涂油)
                                //if (name != "辊道上料查询车轮")
                                //{
                                client.WriteByOrder("W_i_skip_op_SJ1", mes_Head.skip_op_1, name);//屏蔽视觉检测设备1
                                client.WriteByOrder("W_i_skip_op_SJ2", mes_Head.skip_op_2, name);//屏蔽视觉检测设备2
                                client.WriteByOrder("W_i_skip_op_SJ1", name == "3单元辊道下料查询订单" ? true : mes_Head.skip_op_1, name);//屏蔽视觉检测设备1
                                client.WriteByOrder("W_i_skip_op_SJ2", name == "3单元辊道下料查询订单" ? true : mes_Head.skip_op_2, name);//屏蔽视觉检测设备2
                                client.WriteByOrder("W_i_skip_op_LT", mes_Head.skip_op_3, name);//屏蔽链条机
                                //}
                                client.WriteByOrder("R_oi_on", (byte)0, name);
                                #region æ—¥å¿—记录
                                WriteDBLog.Success(name, $"读取桁架信息:\n车轮SN:{wp_id}\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:1" +
                                    $"\nW_i_job_id:{mes_Detail.jobID}\nW_i_drawing_id:{mes_Head.drawingNo}\nW_i_heat_id:{mes_Detail.heatID}\nW_i_batch_id:{mes_Detail.heatBatchID}" +
                                    $"\nW_i_skip_op_SJ1:{(name == "3单元辊道下料查询订单" ? true : mes_Head.skip_op_1)}\nW_i_skip_op_SJ2:{(name == "3单元辊道下料查询订单" ? true : mes_Head.skip_op_2)}" +
                                    $"\nW_i_skip_op_LT:{mes_Head.skip_op_3}\nR_oi_on:0", "PCS");
                                #endregion
                            }
                        }
                        else
                        {
                            var geometry = dataRepository.FindFirst(x => x.Description == mes_Head.drawingNo);
                            var geometry = detectionlineRepository.Find(x => x.Description == mes_Head.drawingNo && x.TypeId == (Int32)wp_type).FirstOrDefault();
                            if (geometry == null)
                            {
                                //1-好,允许加工,2-不在列表中,3-不加工车轮类型,4-手动入库模式人工未选择库区
                                client.WriteByOrder("W_i_status", (byte)2, name);
                                client.WriteByOrder("R_oi_on", (byte)0, name);
                                #region æ—¥å¿—记录
                                WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到检测线车轮信息", "PCS");
                                #endregion
                                continue;
                            }
                            else
@@ -187,6 +256,10 @@
                                //client.WriteByOrder("W_i_sourceheat", "", name);
                                client.WriteByOrder("W_i_batch_id", mes_Detail.heatBatchID, name);
                                client.WriteByOrder("R_oi_on", (byte)0, name);
                                #region æ—¥å¿—记录
                                WriteDBLog.Success(name, $"读取桁架信息:\n车轮SN:{wp_id}\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:1" + $"\nW_i_job_id:{mes_Detail.jobID}" +
                                    $"\nW_i_drawing_id:{mes_Head.drawingNo}\nW_i_heat_id:{mes_Detail.heatID}\nW_i_batch_id:{mes_Detail.heatBatchID}\nR_oi_on:0", "PCS");
                                #endregion
                            }
                        }
@@ -207,15 +280,85 @@
        {
            try
            {
                VOLContext Context = new VOLContext();
                Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
                Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
                Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
                Idt_geometry_data_detectionlineRepository detectionlineRepository = new dt_geometry_data_detectionlineRepository(Context);
                Idt_mes_detailRepository mes_DetailRepository = new dt_mes_detailRepository(Context);
                Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
                Idt_patternRepository patternRepository = new dt_patternRepository(Context);
                var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "链条机");
                if (Pipeline_client == null) throw new Exception("链条机调度服务未开启!");
                if (!Pipeline_client.IsConnected) throw new Exception("与链条机连接超时!");
                var Pipelineplc = repository.FindFirst(x => x.plcinfo_name == Pipeline_client.PLCName);
                List<string> names = new List<string>() { "1单元下料区", "2单元下料区", "3单元下料区" };
                foreach (string name in names)
                {
                    var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == name).ToList();
                    var Wheel_Type = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_Type").First(), client);//车轮类型
                    var Wheel_id = client.ReadByOrder<string>("R_Wheel_id", name);//车轮SN号
                    if (string.IsNullOrEmpty(Wheel_id)) continue;
                    //var Wheel_id = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_id").First(), client).ToString();
                    var mes_Detail = mes_DetailRepository.FindFirst(x => x.SN == Wheel_id);
                    if (mes_Detail == null)
                    {
                        #region æ—¥å¿—记录
                        WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{Wheel_id}\n\n未查询到工单详情", "PCS");
                        #endregion
                        continue;
                    }
                    var mes_Head = mes_HeadRepository.FindFirst(x => x.jobID == mes_Detail.jobID);
                    if (mes_Head == null)
                    {
                        #region æ—¥å¿—记录
                        WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{Wheel_id}\n\n未查询到工单头表", "PCS");
                        #endregion
                        continue;
                    }
                    var finished = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_load_finished").First(), client);//放料完成
                    var updatefinished = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_Storage_update").First(), client);//货位状态更新
                    if (!finished && updatefinished)
                    {
                        client.WriteByOrder("W_Storage_update", false, name);//货位状态更新
                        #region æ—¥å¿—记录
                        WriteDBLog.Success(name + "货位状态更新复位", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n\n写入桁架信息:\nW_Storage_update:false", "PCS");
                        #endregion
                    }
                    if (finished && !updatefinished)
                    {
                        var AreaNr = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_AreaNr").First(), client);
                        var areaCode = PipelineJob.area_code(name);   //根据下料口单元名获取区域代码
                        var station = stationinfoRepository.FindFirst(x => x.area == areaCode && x.stationCode.Substring(x.stationCode.Length - 1, 1) == AreaNr.ToString());  //此处有问题 ä¸çŸ¥é“是结尾为1的哪个下料口
                        station.quantity++;    //todo æ­¤å¤„数量不会增加  ä½†æ˜¯æ›´æ–°å®žä½“影响报错 æ˜Žæ—¥æµ‹è¯•
                        if (station.quantity > 5)
                            throw new Exception($"下料位信息更新失败!下料位车轮数量大于5:{station.stationCode}");
                        //station.bindSN = station.bindSN == string.Empty ? Wheel_id : station.bindSN + "," + Wheel_id;
                        station.bindSN = string.IsNullOrEmpty(station.bindSN) ? Wheel_id : station.bindSN + "," + Wheel_id;
                        if (station.quantity == 1)
                        {
                            station.stationType = mes_Head.drawingNo;
                            station.Number = mes_Head.jobID;
                            station.heatNumber = mes_Detail.heatID;
                            station.tray_status = "StrogeTray";
                        }
                        var count = stationinfoRepository.Update(station, true);
                        if (count < 1)
                            throw new Exception($"下料位信息更新失败!下料位编号:{station.stationCode}");
                        client.WriteByOrder("W_Storage_update", true, name);//货位状态更新
                        client.WriteByOrder("W_Enabl_Load", false, name);//是否允许
                        #region æ—¥å¿—记录
                        WriteDBLog.Success(name + "放料完成", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n下料位号:{AreaNr}" +
                            $"\n\n写入桁架信息:\nW_Storage_update:true" + $"\nW_Enabl_Load:false", "PCS");
                        #endregion
                    }
                    var Request = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Request_Load").First(), client);
                    if (!Request) continue;
@@ -225,18 +368,27 @@
                    var NGStation = "X01001003";
                    if (name == "2单元下料区") NGStation = "X02001003";
                    if (name == "3单元下料区") NGStation = "X03001002";
                    foreach (var station in Stations)
                    foreach (var station in Stations)     //任何一个下料位为空或禁用时,都会停止桁架
                    {
                        if (!station.enable || station.location_state == LocationStateEnum.Empty.ToString())
                            client.WriteByOrder("W_Enabl_Load", false, name);//信号为false桁架停止进入
                    }
                    var Wheel_Type = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_Type").First(), client);//车轮类型
                    var Wheel_id = client.ReadByOrder<string>("R_Wheel_id", name);//车轮SN号
                    //var Wheel_id = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_id").First(), client).ToString();
                    var mes_Detail = mes_DetailRepository.FindFirst(x => x.SN == Wheel_id);
                    var mes_Head = mes_HeadRepository.FindFirst(x => x.jobID == mes_Detail.jobID);
                    //var currentAreaNr = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_Are00aNr").First(), client);
                    //var currentAreaCode = PipelineJob.area_code(name);   //根据下料口单元名获取区域代码
                    //var currentStation = stationinfoRepository.FindFirst(x => x.area == currentAreaCode && x.stationCode.Substring(x.stationCode.Length - 1, 1) == currentAreaNr.ToString());
                    //if (!currentStation.enable || currentStation.location_state == LocationStateEnum.Empty.ToString())
                    //    client.WriteByOrder("W_Enabl_Load", false, name);//信号为false桁架停止进入
                    var wheel = PipelineJob.QueryMateriel(mes_Head.drawingNo);
                    if (wheel == null)
                    {
                        #region æ—¥å¿—记录
                        WriteDBLog.Error(name, $"未查询到车轮信息!", "PCS");
                        #endregion
                        continue;
                    }
                    var PartStatus = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PartStatus").First(), client);//1:ok;2:nok
                    if ((Int16)PartStatus == 1)
@@ -256,31 +408,54 @@
                            Stationinfo = Stations.Where(x => x.enable && x.stationCode != NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity == 0).FirstOrDefault();
                        if (Stationinfo != null)
                        {
                            #region æ‰˜ç›˜ç±»åž‹ä¸ä¸€è‡´éœ€æ›´æ¢æ‰˜ç›˜
                            if (Stationinfo.tray_type != (wheel.e < 1100 ? "SmallTray" : "LargeTray"))
                            {
                                Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
                                Stationinfo.tray_type = Stationinfo.tray_type == "SmallTray" ? "SmallTray/LargeTray" : "LargeTray/SmallTray";
                                Stationinfo.remark = "托盘类型不一致需更换托盘";
                                stationinfoRepository.Update(Stationinfo, true);
                                continue;
                            }
                            #endregion
                            var Pipelinedetails = plcRepository.Find(x => x.plcdetail_iotype == Pipelineplc.plcinfo_iotyep && x.plcdetail_number == Stationinfo.stationCode).ToList();
                            var PalletSignal = (Int16)DBExtension.Read(Pipelinedetails.Where(x => x.plcdetail_name == "R_PalletSignal").First(), Pipeline_client);//读取托盘信号:1:有,2无
                            //var MaterialSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_MaterialSignal").First(), Pipeline_client);//读取货物信号:1:有,2无
                            //var Wheel_id = client.ReadByOrder<string>("R_Wheel_id", name);
                            if (PalletSignal == 1)
                            {
                                var SNS = Stationinfo.bindSN.Split(",");
                                List<string> list = new List<string>();
                                foreach (var SN in SNS)
                                if (Stationinfo.bindSN != null)
                                {
                                    if (!string.IsNullOrEmpty(SN))
                                        list.Add(SN);
                                    var SNS = Stationinfo.bindSN.Split(",");
                                    foreach (var SN in SNS)
                                    {
                                        if (!string.IsNullOrEmpty(SN))
                                            list.Add(SN);
                                    }
                                }
                                //缓存架上车轮数量与SN号数量不一致
                                if (list.Count != Stationinfo.quantity)
                                {
                                    Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
                                    Stationinfo.remark = "车轮数量与SN号数量不一致";
                                    stationinfoRepository.Update(Stationinfo, true);
                                    continue;
                                    //写入桁架报警信号
                                    throw new Exception("下料位车轮数量与SN号数量不一致,下料位编号:" + Stationinfo.stationCode);
                                    //throw new Exception("下料位车轮数量与SN号数量不一致,下料位编号:" + Stationinfo.stationCode);
                                }
                                var area = Convert.ToInt16(Stationinfo.stationCode.Substring(Stationinfo.stationCode.Length - 1, 1));
                                client.WriteByOrder("W_AreaNr", (Int16)area, name);//区域货位号
                                client.WriteByOrder("W_IndexNr", (Int16)(Stationinfo.quantity + 1), name);//托盘上的第几个车轮
                                client.WriteByOrder("W_Storage_Type", (Int16)1, name);//托盘类型1-横放;2-竖放(暂时只有横放托盘)
                                client.WriteByOrder("W_Enabl_Load", true, name);//是否允许
                                #region æ—¥å¿—记录
                                WriteDBLog.Success(name + "放料申请", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:OK" +
                                    $"\n读取托盘光电信号:{PalletSignal}" +
                                    $"\n\n写入桁架信息:\n下料位号:{area}\n第几个车轮:{(Stationinfo.quantity + 1)}\n托盘类型:1\nW_Enabl_Load:true", "PCS");
                                #endregion
                                return;
                            }
                        }
@@ -296,32 +471,54 @@
                        && x.tray_type == (wheel.e < 1100 ? "SmallTray" : "LargeTray")
                        && x.Number == mes_Detail.jobID
                        && x.heatNumber == mes_Detail.heatID).FirstOrDefault();
                        if (Stationinfo == null)
                            Stationinfo = Stations.Where(x => x.enable && x.stationCode == NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity == 0).FirstOrDefault();
                        if (Stationinfo != null)
                        {
                            #region æ‰˜ç›˜ç±»åž‹ä¸ä¸€è‡´éœ€æ›´æ¢æ‰˜ç›˜
                            if (Stationinfo.tray_type != (wheel.e < 1100 ? "SmallTray" : "LargeTray"))
                            {
                                Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
                                Stationinfo.tray_type = Stationinfo.tray_type == "SmallTray" ? "SmallTray/LargeTray" : "LargeTray/SmallTray";
                                Stationinfo.remark = "托盘类型不一致需更换托盘";
                                stationinfoRepository.Update(Stationinfo, true);
                            }
                            #endregion
                            var Pipelinedetails = plcRepository.Find(x => x.plcdetail_iotype == Pipelineplc.plcinfo_iotyep && x.plcdetail_number == Stationinfo.stationCode).ToList();
                            var PalletSignal = (Int16)DBExtension.Read(Pipelinedetails.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//读取托盘信号:1:有,2无
                            var PalletSignal = (Int16)DBExtension.Read(Pipelinedetails.Where(x => x.plcdetail_name == "R_PalletSignal").First(), Pipeline_client);//读取托盘信号:1:有,2无
                            if (PalletSignal == 1)
                            {
                                var SNS = Stationinfo.bindSN.Split(",");
                                List<string> list = new List<string>();
                                foreach (var SN in SNS)
                                if (Stationinfo.bindSN != null)
                                {
                                    if (!string.IsNullOrEmpty(SN))
                                        list.Add(SN);
                                    foreach (var SN in SNS)
                                    {
                                        if (!string.IsNullOrEmpty(SN))
                                            list.Add(SN);
                                    }
                                }
                                //缓存架上车轮数量与SN号数量不一致
                                if (list.Count != Stationinfo.quantity)
                                {
                                    Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
                                    Stationinfo.remark = "车轮数量与SN号数量不一致";
                                    stationinfoRepository.Update(Stationinfo, true);
                                    continue;
                                    //写入桁架报警信号
                                    throw new Exception("下料位车轮数量与SN号数量不一致,下料位编号:" + Stationinfo.stationCode);
                                    //throw new Exception("下料位车轮数量与SN号数量不一致,下料位编号:" + Stationinfo.stationCode);
                                }
                                var area = Convert.ToInt16(Stationinfo.stationCode.Substring(Stationinfo.stationCode.Length - 1, 1));
                                client.WriteByOrder("W_AreaNr", (Int16)area, name);//区域货位号
                                client.WriteByOrder("W_IndexNr", (Int16)(Stationinfo.quantity + 1), name);//托盘上的第几个车轮
                                client.WriteByOrder("W_Storage_Type", (Int16)1, name);//托盘类型1-横放;2-竖放(暂时只有横放托盘)
                                client.WriteByOrder("W_Enabl_Load", true, name);//是否允许
                                #region æ—¥å¿—记录
                                WriteDBLog.Success(name + "放料申请", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:NG" +
                                    $"\n读取托盘光电信号:{PalletSignal}" +
                                    $"\n\n写入桁架信息:\n下料位号:{area}\n第几个车轮:{(Stationinfo.quantity + 1)}\n托盘类型:1\nW_Enabl_Load:true", "PCS");
                                #endregion
                                return;
                            }
                        }
@@ -348,28 +545,7 @@
                    //    StationCodes = new List<string>() { "X03001001", "X03001002" };
                    #endregion
                    var finished = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_load_finished").First(), client);//放料完成
                    var updatefinished = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_Storage_update").First(), client);//货位状态更新
                    if (!finished && updatefinished)
                        client.WriteByOrder("W_Storage_update", false, name);//货位状态更新
                    if (finished && !updatefinished)
                    {
                        var AreaNr = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_AreaNr").First(), client);
                        var station = stationinfoRepository.FindFirst(x => x.stationCode.Substring(x.stationCode.Length - 1, 1) == AreaNr.ToString());
                        station.quantity = station.quantity++;
                        station.bindSN = station.bindSN == string.Empty ? Wheel_id : station.bindSN + "," + Wheel_id;
                        if (station.quantity == 0)
                        {
                            station.stationType = mes_Head.drawingNo;
                            station.Number = mes_Head.jobID;
                            station.heatNumber = mes_Detail.heatID;
                        }
                        var count = stationinfoRepository.Update(station);
                        if (count < 1)
                            throw new Exception($"下料位信息更新失败!下料位编号:{station.stationCode}");
                        client.WriteByOrder("W_Storage_update", true, name);//货位状态更新
                        client.WriteByOrder("W_Enabl_Load", false, name);//是否允许
                    }
                    #region
                    //for (int i = 0; i < StationCodes.Count - 1; i++)
                    //{