分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-01-31 50fd5cc9cfad08714c4daa6d481c5293ff2ae6b1
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
using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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();
                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);//桁架不在该区域
                    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)
                    {
                        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占位信号
                        if (!Area_Occupied_by_AGV) throw new Exception("桁架未反馈AGV占位信号");
                    }
                    else if (requestin.Type == 2)
                    {
                        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占位信号
                        if (Area_Occupied_by_AGV) throw new Exception("桁架未反馈AGV离开信号");
                    }
                }
                else if (MethodName == "AGVOutofArea")
                {
                    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不在该区域
                }
                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);//桁架不在该区域
                    if (!Gantry_Out_of_Area) throw new Exception("桁架在区域内!");
                }
                respone.success = 1;
            }
            catch (Exception ex)
            {
                respone.Message = ex.Message;
            }
            return respone;
        }
    }
}