using Elastic.Clients.Elasticsearch.Tasks;
using Microsoft.AspNetCore.SignalR;
using RazorEngine.Compilation.ImpromptuInterface.Dynamic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WCS.Application;
public static class PLCCommon
{
private static readonly ISqlSugarClient _db = SqlSugarSetup.ITenant.GetConnectionScope(SqlSugarConst.MainConfigId);
///
/// 获取任务相关信息
///
/// 目标位置
/// 1:出库任务 2:移库任务
/// 起始巷道
/// 目标巷道
///
public static PlcTaskInfo GetCTaskInfo(string endLocat,string taskType,string roadWay,string endRoadWay)
{
// 各层输送线跺机放货工位集合
var conveyList1 = new List() { "033", "039", "044", "051", "059" };
var conveyList2 = new List() { "205", "234" };
var conveyList3 = new List() { "440", "443" };
PlcTaskInfo taskInfo = new PlcTaskInfo();
taskInfo.EndCeng = "3";
taskInfo.EndLie = "65";
taskInfo.EndPai = int.Parse(roadWay.Substring(1,2)).ToString();
// 移库任务
if (taskType == "2")
{
if (roadWay == endRoadWay) // 同巷道移库,获取目标地址
{
taskInfo = GetEndPai(endLocat.Substring(1, 2), endLocat.Substring(0, 2), endLocat.Substring(4, 2), endLocat.Substring(6, 2));
}
else // 跨巷道移库,获取三楼出库口
{
taskInfo.Ip = "10.18.51.130";
switch (roadWay)
{
case "R01":
taskInfo.EndStation = "402";
break;
case "R02":
taskInfo.EndStation = "406";
break;
case "R03":
taskInfo.EndStation = "410";
break;
case "R04":
taskInfo.EndStation = "414";
break;
case "R05":
taskInfo.EndStation = "418";
break;
case "R06":
taskInfo.EndStation = "422";
break;
case "R07":
taskInfo.EndStation = "426";
break;
case "R08":
taskInfo.EndStation = "430";
break;
case "R09":
taskInfo.EndStation = "434";
break;
case "R10":
taskInfo.EndStation = "438";
break;
}
}
}
// 出库任务
if (taskType == "1")
{
if (conveyList1.Contains(endLocat))
{
taskInfo.Ip = "10.18.51.110";
taskInfo.EndCeng = "1";
#region 一层输送线
switch (roadWay)
{
case "R01":
taskInfo.EndStation = "147";
break;
case "R02":
taskInfo.EndStation = "139";
break;
case "R03":
taskInfo.EndStation = "129";
break;
case "R04":
taskInfo.EndStation = "121";
break;
case "R05":
taskInfo.EndStation = "111";
break;
case "R06":
taskInfo.EndStation = "103";
break;
case "R07":
taskInfo.EndStation = "093";
break;
case "R08":
taskInfo.EndStation = "85";
break;
case "R09":
taskInfo.EndStation = "75";
break;
case "R10":
taskInfo.EndStation = "67";
break;
}
#endregion
}
else if (conveyList2.Contains(endLocat))
{
#region 二层输送线
taskInfo.Ip = "10.18.51.120";
taskInfo.EndCeng = "2";
switch (roadWay)
{
case "R01":
taskInfo.EndStation = "254";
break;
case "R02":
taskInfo.EndStation = "262";
break;
case "R03":
taskInfo.EndStation = "272";
break;
case "R04":
taskInfo.EndStation = "280";
break;
case "R05":
taskInfo.EndStation = "290";
break;
case "R06":
taskInfo.EndStation = "294";
break;
case "R07":
taskInfo.EndStation = "309";
break;
case "R08":
taskInfo.EndStation = "317";
break;
case "R09":
taskInfo.EndStation = "327";
break;
case "R10":
taskInfo.EndStation = "331";
break;
}
#endregion
}
else if (conveyList3.Contains(endLocat))
{
#region 三层输送线
taskInfo.Ip = "10.18.51.130";
taskInfo.EndCeng = "3";
switch (roadWay)
{
case "R01":
taskInfo.EndStation = "402";
break;
case "R02":
taskInfo.EndStation = "406";
break;
case "R03":
taskInfo.EndStation = "410";
break;
case "R04":
taskInfo.EndStation = "414";
break;
case "R05":
taskInfo.EndStation = "418";
break;
case "R06":
taskInfo.EndStation = "422";
break;
case "R07":
taskInfo.EndStation = "426";
break;
case "R08":
taskInfo.EndStation = "430";
break;
case "R09":
taskInfo.EndStation = "434";
break;
case "R10":
taskInfo.EndStation = "438";
break;
}
#endregion
}
else
{
throw new Exception("出库口工位未查询到");
}
}
return taskInfo;
}
///
/// 根据工位号获取对应的输送线Ip
///
///
///
public static PLCUtil GetPlcIp(string startStation)
{
string strIp = "";
var conveyList1 = new List() { "147", "145", "139", "137", "129", "127", "121", "119", "111", "109", "103", "101", "093", "091", "085", "083", "075", "073", "067", "065" };
var conveyList2 = new List() { "252", "254", "260", "262", "272", "272", "278", "280", "288", "290", "294", "301", "307", "309", "315", "317", "325", "327", "331", "337" };
var conveyList3 = new List() { "401", "402", "405", "406", "409", "410", "413", "414", "417", "418", "421", "422", "425", "426", "429", "430", "433", "434", "437", "438" };
if (conveyList1.Contains(startStation))
{
strIp = "10.18.51.110";
}
else if (conveyList2.Contains(startStation))
{
strIp = "10.18.51.120";
}
else if (conveyList3.Contains(startStation))
{
strIp = "10.18.51.130";
}
else
{
throw Oops.Bah("工位未查询到");
}
var plcConveyorConn = PLCTaskAction.listPlcConn.First(m => m.PlcIP == strIp);
return plcConveyorConn;
}
///
/// 根据wms目标地址转换为Plc目标地址
///
/// 列
/// 排
/// 层
/// 深度
///
public static PlcTaskInfo GetEndPai(string lie, string pai,string ceng, string dept)
{
var roadNum = int.Parse(lie);
var paiNum = int.Parse(pai);
var deptNum = int.Parse(dept);
var paiVal = 0;
// 判断巷道奇偶数
if (roadNum % 2 == 0)// 偶数
{
// 判断排奇偶数
if (paiNum % 2 == 0)
{
if (deptNum == 1)
{
paiVal = 3;
}
else
{
paiVal = 4;
}
}
else
{
if (deptNum == 1)
{
paiVal = 1;
}
else
{
paiVal = 2;
}
}
}
else // 奇数
{
// 判断排奇偶数
if (paiNum % 2 == 0)
{
if (deptNum == 1)
{
paiVal = 3;
}
else
{
paiVal = 4;
}
}
else
{
if (deptNum == 1)
{
paiVal = 2;
}
else
{
paiVal = 1;
}
}
}
PlcTaskInfo taskInfo = new PlcTaskInfo();
taskInfo.EndPai = pai;
taskInfo.EndCeng = ceng;
taskInfo.EndLie = paiVal.ToString();
return taskInfo;
}
}