hwh
2024-09-13 d4beffac7005967f3eeb5b175170de20ab963781
Admin.NET/WCS.Application/PLC/PLCCommon.cs
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.SignalR;
using Elastic.Clients.Elasticsearch.Tasks;
using Microsoft.AspNetCore.SignalR;
using RazorEngine.Compilation.ImpromptuInterface.Dynamic;
using System;
using System.Collections.Generic;
@@ -215,33 +216,32 @@
    /// </summary>
    /// <param name="startStation"></param>
    /// <returns></returns>
    public static PlcTaskInfo GetPlcIp(string startStation)
    public static PLCUtil GetPlcIp(string startStation)
    {
        PlcTaskInfo taskInfo = new PlcTaskInfo();
        string strIp = "";
        var conveyList1 = new List<string>() { "147", "145", "139", "137", "129", "127", "121", "119", "111", "109", "103", "101", "093", "091", "085", "083", "075", "073", "067", "065" };
        var conveyList2 = new List<string>() { "252", "254", "260", "262", "272", "272", "278", "280", "288", "290", "294", "301", "307", "309", "315", "317", "325", "327", "331", "337" };
        var conveyList3 = new List<string>() { "401", "402", "405", "406", "409", "410", "413", "414", "417", "418", "421", "422", "425", "426", "429", "430", "433", "434", "437", "438" };
        if (conveyList1.Contains(startStation))
        {
            taskInfo.Ip = "10.18.51.110";
            strIp = "10.18.51.110";
        }
        else if (conveyList2.Contains(startStation))
        {
            taskInfo.Ip = "10.18.51.120";
            strIp = "10.18.51.120";
        }
        else if (conveyList3.Contains(startStation))
        {
            taskInfo.Ip = "10.18.51.130";
            strIp = "10.18.51.130";
        }
        else
        {
            throw new Exception("工位未查询到");
            throw Oops.Bah("工位未查询到");
        }
        return taskInfo;
        var plcConveyorConn = PLCTaskAction.listPlcConn.First(m => m.PlcIP == strIp);
        return plcConveyorConn;
    }
    /// <summary>
@@ -323,4 +323,435 @@
        return taskInfo;
    }
    /// <summary>
    /// 根据巷道和层数确定巷道口入库工位
    /// </summary>
    /// <param name="endRoadway"></param>
    /// <param name="ceng"></param>
    /// <returns></returns>
    public static string RoadwayToStationNum(string endRoadway, string ceng)
    {
        string stationNum = "";
        switch (endRoadway)
        {
            case "R01":
                if (ceng == "1")
                {
                    stationNum = "145";
                }
                if (ceng == "2")
                {
                    stationNum = "252";
                }
                if (ceng == "3")
                {
                    stationNum = "401";
                }
                break;
            case "R02":
                if (ceng == "1")
                {
                    stationNum = "137";
                }
                if (ceng == "2")
                {
                    stationNum = "260";
                }
                if (ceng == "3")
                {
                    stationNum = "405";
                }
                break;
            case "R03":
                if (ceng == "1")
                {
                    stationNum = "127";
                }
                if (ceng == "2")
                {
                    stationNum = "270";
                }
                if (ceng == "3")
                {
                    stationNum = "409";
                }
                break;
            case "R04":
                if (ceng == "1")
                {
                    stationNum = "119";
                }
                if (ceng == "2")
                {
                    stationNum = "278";
                }
                if (ceng == "3")
                {
                    stationNum = "413";
                }
                break;
            case "R05":
                if (ceng == "1")
                {
                    stationNum = "109";
                }
                if (ceng == "2")
                {
                    stationNum = "288";
                }
                if (ceng == "3")
                {
                    stationNum = "417";
                }
                break;
            case "R06":
                if (ceng == "1")
                {
                    stationNum = "101";
                }
                if (ceng == "2")
                {
                    stationNum = "301";
                }
                if (ceng == "3")
                {
                    stationNum = "421";
                }
                break;
            case "R07":
                if (ceng == "1")
                {
                    stationNum = "091";
                }
                if (ceng == "2")
                {
                    stationNum = "307";
                }
                if (ceng == "3")
                {
                    stationNum = "425";
                }
                break;
            case "R08":
                if (ceng == "1")
                {
                    stationNum = "83";
                }
                if (ceng == "2")
                {
                    stationNum = "315";
                }
                if (ceng == "3")
                {
                    stationNum = "429";
                }
                break;
            case "R09":
                if (ceng == "1")
                {
                    stationNum = "73";
                }
                if (ceng == "2")
                {
                    stationNum = "325";
                }
                if (ceng == "3")
                {
                    stationNum = "433";
                }
                break;
            case "R10":
                if (ceng == "1")
                {
                    stationNum = "65";
                }
                if (ceng == "2")
                {
                    stationNum = "337";
                }
                if (ceng == "3")
                {
                    stationNum = "437";
                }
                break;
        }
        return stationNum;
    }
    /// <summary>
    /// 根据工位号获取对应巷道
    /// </summary>
    /// <param name="StationNum">入出工位号</param>
    /// <returns>跺机联机</returns>
    public static string GetRoadwayByStation(string StationNum)
    {
        string value = "";
        var conveyList1 = new List<string>() { "147", "145", "252", "254", "401", "402", };
        var conveyList2 = new List<string>() { "139", "137", "260", "262", "405", "406", };
        var conveyList3 = new List<string>() { "129", "127", "272", "270", "409", "410", };
        var conveyList4 = new List<string>() { "121", "119", "278", "280", "413", "414", };
        var conveyList5 = new List<string>() { "111", "109", "288", "290", "417", "418", };
        var conveyList6 = new List<string>() { "103", "101", "294", "301", "421", "422", };
        var conveyList7 = new List<string>() { "093", "091", "307", "309", "425", "426", };
        var conveyList8 = new List<string>() { "085", "083", "315", "317", "429", "430", };
        var conveyList9 = new List<string>() { "075", "073", "325", "327", "433", "434", };
        var conveyList10 = new List<string>() { "067", "065", "331", "337", "437", "438", };
        if (conveyList1.Contains(StationNum))
        {
            value = "R01";
        }
        else if (conveyList2.Contains(StationNum))
        {
            value = "R02";
        }
        else if (conveyList3.Contains(StationNum))
        {
            value = "R03";
        }
        else if (conveyList4.Contains(StationNum))
        {
            value = "R04";
        }
        else if (conveyList5.Contains(StationNum))
        {
            value = "R05";
        }
        else if (conveyList6.Contains(StationNum))
        {
            value = "R06";
        }
        else if (conveyList7.Contains(StationNum))
        {
            value = "R07";
        }
        else if (conveyList8.Contains(StationNum))
        {
            value = "R08";
        }
        else if (conveyList9.Contains(StationNum))
        {
            value = "R09";
        }
        else if (conveyList10.Contains(StationNum))
        {
            value = "R10";
        }
        return value;
    }
    /// <summary>
    /// 根据巷道口出入库工位号获取对应楼层
    /// </summary>
    /// <param name="StationNum">入出工位号</param>
    /// <returns>跺机联机</returns>
    public static string GetRoadwayByStationNew(string StationNum)
    {
        string value = "";
        var conveyList1 = new List<string>() { "147", "145", "139", "137", "129", "127", "121", "119", "111", "109", "103", "101", "093", "091", "085", "083", "075", "073", "067", "065" };
        var conveyList2 = new List<string>() { "252", "254", "260", "262", "272", "270", "278", "280", "288", "290", "294", "301", "307", "309", "315", "317", "325", "327", "331", "337" };
        var conveyList3 = new List<string>() { "401", "402", "405", "406", "409", "410", "413", "414", "417", "418", "421", "422", "425", "426", "429", "430", "433", "434", "437", "438" };
        if (conveyList1.Contains(StationNum))
        {
            value = "1";
        }
        else if (conveyList2.Contains(StationNum))
        {
            value = "2";
        }
        else if (conveyList3.Contains(StationNum))
        {
            value = "3";
        }
        else
        {
            throw new Exception("工位未查询到");
        }
        return value;
    }
    /// <summary>
    /// 根据巷道号、层数 获取对应的跺机IP及入库工位排列层信息
    /// </summary>
    /// <param name="roadway">巷道号</param>
    /// <param name="ceng">连接集合</param>
    /// <returns></returns>
    public static StokInfo GetStokePlc(string roadway, string ceng)
    {
        StokInfo sInfo = new StokInfo();
        sInfo.Pai = "2";
        switch (roadway)
        {
            case "R01":
                sInfo.Ip = "10.18.51.10";
                if (ceng == "1")
                {
                    sInfo.Pai = "3";
                }
                break;
            case "R02":
                sInfo.Ip = "10.18.51.20";
                if (ceng == "1")
                {
                    sInfo.Pai = "3";
                }
                break;
            case "R03":
                sInfo.Ip = "10.18.51.30";
                if (ceng == "1")
                {
                    sInfo.Pai = "3";
                }
                break;
            case "R04":
                sInfo.Ip = "10.18.51.40";
                if (ceng == "1")
                {
                    sInfo.Pai = "3";
                }
                break;
            case "R05":
                sInfo.Ip = "10.18.51.50";
                if (ceng == "1")
                {
                    sInfo.Pai = "3";
                }
                break;
            case "R06":
                sInfo.Ip = "10.18.51.60";
                if (ceng == "2" || ceng == "1")
                {
                    sInfo.Pai = "3";
                }
                break;
            case "R07":
                sInfo.Ip = "10.18.51.70";
                if (ceng == "1")
                {
                    sInfo.Pai = "3";
                }
                break;
            case "R08":
                sInfo.Ip = "10.18.51.80";
                if (ceng == "1")
                {
                    sInfo.Pai = "3";
                }
                break;
            case "R09":
                sInfo.Ip = "10.18.51.90";
                if (ceng == "1")
                {
                    sInfo.Pai = "3";
                }
                break;
            case "R10":
                sInfo.Ip = "10.18.51.100";
                if (ceng == "2" || ceng == "1")
                {
                    sInfo.Pai = "3";
                }
                break;
        }
        sInfo.Lie = "65";
        sInfo.Ceng = "1";
        if (ceng == "2")
        {
            sInfo.Ceng = "2";
        }
        if (ceng == "3")
        {
            sInfo.Ceng = "3";
        }
        return sInfo;
    }
    /// <summary>
    /// 根据储位排获取跺机对应的地址排
    /// </summary>
    /// <param name="road">排</param>
    /// <param name="pai">排</param>
    /// <param name="dept">深度</param>
    /// <returns></returns>
    public static int GetDjAdress(string road, string pai, string dept)
    {
        var roadNum = int.Parse(road);
        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;
                }
            }
        }
        return paiVal;
    }
}