分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-06-20 00ad010a45f2f58807eb0f4f70e2dcf66ef35085
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using WIDESEA_Comm.LogInfo;
using WIDESEA_Core.BaseProvider;
using WIDESEA_Core.FreeDB;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Entity.ToAGV;
using WIDESEA_WCS.WCSClient;
 
namespace WIDESEA_WCS
{
    public class AGVandGantry
    {
        static FreeDB FreeDB = new FreeDB();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="requestin"></param>
        /// <param name="MethodName">方法名</param>
        /// <returns></returns>
        public static AGVRespone GetSetGantry(AGVRequestin requestin, string MethodName)
        {
            AGVRespone respone = new AGVRespone();
            try
            {
                var Gantry_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "桁架");
                if (Gantry_client == null) throw new Exception("桁架调度服务未开启!");
                if (!Gantry_client.IsConnected) throw new Exception("与桁架连接超时!");
                var Gantryplc = FreeDB.Select<dt_plcinfohead>().Where(x => x.plcinfo_name == Gantry_client.PLCName).First();
                var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "链条机");
                if (Pipeline_client == null) throw new Exception("链条机调度服务未开启!");
                if (!Pipeline_client.IsConnected) throw new Exception("与链条机连接超时!");
                List<string> numbers = new List<string>() { "1单元防呆", "2单元防呆", "3单元防呆", "上料区防呆" };
                var details = FreeDB.Select<dt_plcinfodetail>().Where(x => x.plcdetail_iotype == Gantryplc.plcinfo_iotyep && x.plcdetail_number == numbers[requestin.AreaNr - 1]).ToList();
                if (MethodName == "AGVRequestin")//请求进入区域
                {
                    Gantry_client.WriteByOrder("W_AreaNr", (Int16)requestin.AreaNr, numbers[requestin.AreaNr - 1]);//区域号
                    Gantry_client.WriteByOrder("W_AGV_Request_In", true, numbers[requestin.AreaNr - 1]);//申请进入区域
                    var Release = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Release_In").First(), Gantry_client);//允许进入区域
                    var Gantry_Out_of_Area = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Gantry_Out_of_Area").First(), Gantry_client);//桁架不在该区域
                    #region 日志记录
                    WriteDBLog.Success("AGV请求进入区域", $"写入桁架信息:\n区域号:{requestin.AreaNr}\n申请进入区域:true" +
                        $"\n\n读取桁架信息:\n允许进入区域:{Release}\n桁架不在该区域:{Gantry_Out_of_Area}", "AGV");
                    #endregion
                    if (!Release) throw new Exception("桁架未允许进入!");
                    if (!Gantry_Out_of_Area) throw new Exception("桁架在区域内!");
                }
                else if (MethodName == "EnteriorLeav")//进入/离开区域
                {
                    Gantry_client.WriteByOrder("W_AreaNr", (Int16)requestin.AreaNr, numbers[requestin.AreaNr - 1]);//区域号
                    if (requestin.Type == 1)
                    {
                        Pipeline_client.WriteByOrder("W_AGV_Entering", (Int16)1, numbers[requestin.AreaNr - 1]);//光栅屏蔽
                        Gantry_client.WriteByOrder("W_AGV_Leaving", false, numbers[requestin.AreaNr - 1]);//正在离开
                        Gantry_client.WriteByOrder("W_AGV_Entering", true, numbers[requestin.AreaNr - 1]);//正在进入
                        var Area_Occupied_by_AGV = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Area_Occupied_by_AGV").First(), Gantry_client);//桁架反馈AGV占位信号
                        #region 日志记录
                        WriteDBLog.Success("AGV正在进入区域", $"写入桁架信息:\n区域号:{requestin.AreaNr}\n正在离开:false\n正在进入:true\n光栅屏蔽:1" +
                            $"\n\n读取桁架信息:\n反馈AGV占位信号:{Area_Occupied_by_AGV}", "AGV");
                        #endregion
                        if (!Area_Occupied_by_AGV) throw new Exception("桁架未反馈AGV占位信号");
                    }
                    else if (requestin.Type == 2)
                    {
                        Pipeline_client.WriteByOrder("W_AGV_Entering", (Int16)0, numbers[requestin.AreaNr - 1]);//光栅启用
                        Gantry_client.WriteByOrder("W_AGV_Request_In", false, numbers[requestin.AreaNr - 1]);//申请进入区域
                        Gantry_client.WriteByOrder("W_AGV_Entering", false, numbers[requestin.AreaNr - 1]);//正在进入
                        Gantry_client.WriteByOrder("W_AGV_Leaving", true, numbers[requestin.AreaNr - 1]);//正在离开
                        var Area_Occupied_by_AGV = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Area_Occupied_by_AGV").First(), Gantry_client);//桁架反馈AGV占位信号
                        #region 日志记录
                        WriteDBLog.Success("AGV正在离开区域", $"写入桁架信息:\n区域号:{requestin.AreaNr}\n申请进入区域:false\n正在进入:false\n正在离开:true\n光栅启用:0" +
                            $"\n\n读取桁架信息:\n反馈AGV离开信号:{!Area_Occupied_by_AGV}", "AGV");
                        #endregion
                        if (Area_Occupied_by_AGV) throw new Exception("桁架未反馈AGV离开信号");
                    }
                }
                else if (MethodName == "AGVOutofArea")//AGV不在区域内
                {
                    Gantry_client.WriteByOrder("W_AreaNr", (Int16)requestin.AreaNr, numbers[requestin.AreaNr - 1]);//区域号
                    Gantry_client.WriteByOrder("W_AGV_OUT_OF_Area", requestin.OUTOFArea == 1 ? true : false, numbers[requestin.AreaNr - 1]);//AGV不在该区域
                    #region 日志记录
                    WriteDBLog.Success("AGV不在区域内", $"写入桁架信息:\n区域号:{requestin.AreaNr}\nAGV不在该区域:{(requestin.OUTOFArea == 1 ? true : false)}", "AGV");
                    #endregion
                }
                else if (MethodName == "GantryOutofArea")//桁架不在区域内
                {
                    var Gantry_Out_of_Area = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Gantry_Out_of_Area").First(), Gantry_client);//桁架不在该区域
                    #region 日志记录
                    WriteDBLog.Success("桁架不在区域内", $"读取桁架信息:\n区域号:{requestin.AreaNr}\n桁架不在该区域:{Gantry_Out_of_Area}", "AGV");
                    #endregion
                    if (!Gantry_Out_of_Area) throw new Exception("桁架在区域内!");
                }
                respone.success = 1;
            }
            catch (Exception ex)
            {
                respone.Message = ex.Message;
                return respone;
            }
            return respone;
        }
    }
}