分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-02-23 538f1f0db8d02103d040b96a489b1a5803750a11
´úÂë¹ÜÀí/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs
@@ -4,10 +4,12 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm;
using WIDESEA_Core.EFDbContext;
using WIDESEA_WCS.IRepositories;
using WIDESEA_WCS.Repositories;
using WIDESEA_WCS.WCSClient;
using static System.Collections.Specialized.BitVector32;
namespace WIDESEA_WCS
{
@@ -17,9 +19,9 @@
        Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
        Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
        Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
        /// <summary>
        /// æŸ¥è¯¢è½¦è½®æ•°æ®
        /// </summary>
        Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
        #region æŸ¥è¯¢è½¦è½®æ•°æ®
        public void QueryWheeldata(PLCClient client)
        {
            try
@@ -30,21 +32,23 @@
                {
                    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);
                    if ((Int16)on == 1)
                    if ((byte)on == 1)
                    {
                        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);
                        if (geometry == null)
                        {
                            //DBExtension.Write(details.Where(x => x.plcdetail_name == "W_i_status").First(), client, (Int16)2);
                            client.WriteByOrder("W_i_status", (Int16)2, name);//1-找到数据,2-未找到工件类型数据
                            client.WriteByOrder("W_i_skip_op", "1", name);//屏蔽工艺(屏蔽视觉检测/屏蔽涂油);
                                                                          //0-使用,1-跳过
                            client.WriteByOrder("R_oi_on", (Int16)0, name);
                            //1-找到数据,2-未找到工件类型数据
                            client.WriteByOrder("W_i_status", (byte)2, name);
                            //屏蔽工艺(屏蔽视觉检测/屏蔽涂油);
                            //client.WriteByOrder("W_i_skip_op", "1", name);
                            client.WriteByOrder("R_oi_on", (byte)0, name);
                        }
                        else
                        {
                            client.WriteByOrder("W_i_status", (Int16)1, name);
                            //1-找到数据,2-未找到工件类型数据
                            client.WriteByOrder("W_i_status", (byte)1, name);
                            client.WriteByOrder("W_i_parameter_a", (float)geometry.a, name);
                            client.WriteByOrder("W_i_parameter_b", (float)geometry.b, name);
                            client.WriteByOrder("W_i_parameter_c", (float)geometry.c, name);
@@ -54,8 +58,13 @@
                            client.WriteByOrder("W_i_parameter_g", (float)geometry.g, name);
                            client.WriteByOrder("W_i_parameter_h", (float)geometry.h, name);
                            //屏蔽工艺(屏蔽视觉检测/屏蔽涂油)
                            client.WriteByOrder("W_i_skip_op", "0", name);//字符串写入-2
                            client.WriteByOrder("R_oi_on", (Int16)0, name);
                            if (name != "辊道上料查询车轮")
                            {
                                client.WriteByOrder("W_i_skip_op_SJ1", (byte)1, name);//屏蔽视觉检测设备1
                                client.WriteByOrder("W_i_skip_op_SJ2", (byte)1, name);//屏蔽视觉检测设备2
                                client.WriteByOrder("W_i_skip_op_LT", (byte)1, name);//屏蔽链条机
                            }
                            client.WriteByOrder("R_oi_on", (byte)0, name);
                        }
                    }
                }
@@ -65,9 +74,9 @@
                throw;
            }
        }
        /// <summary>
        /// æŸ¥è¯¢è®¢å•,是否需要加工
        /// </summary>
        #endregion
        #region æŸ¥è¯¢è®¢å•,是否需要加工
        public void QueryOrder(PLCClient client)
        {
            try
@@ -78,20 +87,23 @@
                {
                    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);
                    if ((Int16)on == 1)
                    if ((byte)on == 1)
                    {
                        var wp_id = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_o_wp_id").First(), client);
                        //需添加查询车轮SN号订单逻辑
                        //需添加查询车轮SN号订单逻辑   éœ€æ·»åŠ å…¥åº“æ¨¡å¼åˆ¤æ–­ï¼Œæ‰‹åŠ¨å…¥åº“æ¨¡å¼éœ€äººå·¥æ·»åŠ å…¥åº“åº“åŒºï¼Œå¦åˆ™æŠ¥è­¦
                        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);
                        if (geometry == null)
                        {
                            client.WriteByOrder("W_i_status", (Int16)2, name);//1-好,允许加工,2-不在列表中,3-不加工车轮类型
                            //1-好,允许加工,2-不在列表中,3-不加工车轮类型,4-手动入库模式人工未选择库区
                            client.WriteByOrder("W_i_status", (Int16)2, name);
                            client.WriteByOrder("R_oi_on", (Int16)0, name);
                        }
                        else
                        {
                            //1-好,允许加工,2-不在列表中,3-不加工车轮类型,4-手动入库模式人工未选择库区
                            client.WriteByOrder("W_i_status", (Int16)1, name);
                            //client.WriteByOrder("W_i_job_id", "", name);
                            //client.WriteByOrder("W_i_drawing_id", "", name);
@@ -108,35 +120,64 @@
                throw;
            }
        }
        /// <summary>
        /// ä¸‹æ–™ä½äº¤äº’
        /// </summary>
        #endregion
        #region ä¸‹æ–™ä½äº¤äº’
        public void Layofflevel(PLCClient client)
        {
            try
            {
                var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                List<string> names = new List<string>() { "1单元下料区", "2单元下料区", "3单元下料区", "上料区" };
                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 Request = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Request_Load").First(), client);
                    if (!Request) continue;
                    var PartStatus = (Int32)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PartStatus").First(), client);//1:ok;2:nok
                    List<string> StationCodes = new List<string>() { "X01001001", "X01001002", "X01001003" };
                    if (name == "2单元下料区")
                        StationCodes = new List<string>() { "X02001001", "X02001002", "X02001003" };
                    if (name == "3单元下料区")
                        StationCodes = new List<string>() { "X03001001", "X03001002" };
                    var Wheel_Type = (Int32)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_Type").First(), client);//车轮类型
                    var Wheel_id = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_id").First(), client).ToString();//车轮SN号
                    client.WriteByOrder("W_AreaNr", (Int16)1, name);//区域货位号
                    client.WriteByOrder("W_IndexNr", (Int16)1, name);//托盘上的第几个车轮
                    client.WriteByOrder("W_Storage_Type", true, name);//托盘类型1-横放;2-竖放
                    client.WriteByOrder("W_Enabl_Load", true, name);//是否允许
                    for (int i = 0; i < StationCodes.Count - 1; i++)
                    {
                        var PartStatus = (Int32)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PartStatus").First(), client);//1:ok;2:nok
                        string NG = StationCodes[StationCodes.Count - 1];//NG货位
                        var station = stationinfoRepository.FindFirst(x => x.stationCode == StationCodes[i] && x.enable && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity < 5);
                        if (station == null) continue;
                        var Pipelinedetails = plcRepository.Find(x => x.plcdetail_iotype == Pipelineplc.plcinfo_iotyep && x.plcdetail_number == StationCodes[i]).ToList();
                        var PalletSignal = (Int16)DBExtension.Read(Pipelinedetails.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//读取托盘信号:1:有,2无
                        if (PalletSignal == 1)
                        {
                            if (PartStatus == 1 && NG != station.stationCode)
                            {
                                client.WriteByOrder("W_AreaNr", (Int16)i + 1, name);//区域货位号
                                client.WriteByOrder("W_IndexNr", (Int16)station.quantity + 1, name);//托盘上的第几个车轮
                            }
                            else if (PartStatus == 2 && NG == station.stationCode)
                            {
                                client.WriteByOrder("W_AreaNr", (Int16)i + 1, name);//区域货位号
                                client.WriteByOrder("W_IndexNr", (Int16)station.quantity + 1, name);//托盘上的第几个车轮
                            }
                            client.WriteByOrder("W_Storage_Type", (Int16)1, name);//托盘类型1-横放;2-竖放(暂时只有横放托盘)
                            client.WriteByOrder("W_Enabl_Load", true, name);//是否允许
                        }
                    }
                    var finished = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_load_finished").First(), client);//放料完成
                    if (finished)
                    {
                        var AreaNr = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_AreaNr").First(), client);
                        var station = stationinfoRepository.FindFirst(x => x.stationCode == StationCodes[AreaNr - 1]);
                        station.quantity = station.quantity++;
                        stationinfoRepository.Update(station);
                        client.WriteByOrder("W_Storage_update", true, name);//货位状态更新
                    }
                }
@@ -146,30 +187,6 @@
                throw;
            }
        }
        /// <summary>
        /// é˜²å‘†æŽªæ–½
        /// </summary>
        static bool Gantry_Out_of_Area1;//桁架是否在区域内
        static bool Gantry_Out_of_Area2;//桁架是否在区域内
        static bool Gantry_Out_of_Area3;//桁架是否在区域内
        static bool Gantry_Out_of_Area4;//桁架是否在区域内
        public void Stupidproofmeasure(PLCClient client)
        {
            try
            {
                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 Release_In = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Release_In").First(), client);//允许进入
                    if (!Release_In) { }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        #endregion
    }
}