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;
|
}
|
}
|
}
|