ServerCommunication_AgvProcess.cs 3.5 KB
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DeviceLibrary
{
    partial class  ServerCommunication
    {
        Dictionary<string, string> AgvStatus() {
            Dictionary<string, string> status = new Dictionary<string, string>();
            status["X16"] = IOManager.GetDIValue("", 0, 16).Equals(IO_VALUE.HIGH) ? "1" : "0";
            status["X27"] = IOManager.GetDIValue("", 0, 27).Equals(IO_VALUE.HIGH) ? "1" : "0";
            status["X09"] = IOManager.GetDIValue("", 0, 09).Equals(IO_VALUE.HIGH) ? "1" : "0";
            status["X10"] = IOManager.GetDIValue("", 0, 10).Equals(IO_VALUE.HIGH) ? "1" : "0";
            status["X11"] = IOManager.GetDIValue("", 0, 11).Equals(IO_VALUE.HIGH) ? "1" : "0";
            status["X12"] = IOManager.GetDIValue("", 0, 12).Equals(IO_VALUE.HIGH) ? "1" : "0";

            status["Y02"] = IOManager.GetDOValue("", 0, 2).Equals(IO_VALUE.HIGH) ? "1" : "0";

            return status;
        }
        private void AgvProcess(Dictionary<string, string> dataMap)
        {
            bool v;
            //紧急料口 1开门 0关门
            if (YDataCheck(dataMap, "Y10", out v)|| YDataCheck(dataMap, "Y11", out v))
            {
                if (v)
                    RobotManage.mainMachine.SingleDoor.ToHigh(null);
                else
                    RobotManage.mainMachine.SingleDoor.ToLow(null);
            }
            //折叠门 1开门 0关门
            if (YDataCheck(dataMap, "Y15", out v)|| YDataCheck(dataMap, "Y14", out v))
            {
                if (v)
                    RobotManage.mainMachine.StringDoorOpen(null);
                else
                    RobotManage.mainMachine.StringDoorClose(null);
            }
            //滚筒正传
            if (YDataCheck(dataMap, "Y08", out v))
            {
                if (v)
                    RobotManage.mainMachine.Line.LineRun("remote", false, 999);
                else
                    RobotManage.mainMachine.Line.LineStop("remote");
            }
            //滚筒反转
            if (YDataCheck(dataMap, "Y09", out v))
            {
                if (v)
                    RobotManage.mainMachine.Line.LineRun("remote", true, 999);
                else
                    RobotManage.mainMachine.Line.LineStop("remote");
            }
        }
        Dictionary<string, int> LastSingnalSeq = new Dictionary<string, int>();
        bool YDataCheck(Dictionary<string, string> dataMap, string key, out bool value) {
            value = false;
            if (!dataMap.TryGetValue(key, out string v))
                return false;

            //var vs = v.Split('|');
            //if (vs.Length != 2)
            //    return false;

            //if (!int.TryParse(vs[1], out int result))
            //    return false;

            //if (!LastSingnalSeq.ContainsKey(key))
            //    LastSingnalSeq.Add(key, -1);

            //if (LastSingnalSeq[key] == result)
            //    return false;

            //LastSingnalSeq[key] = result;
            v = v.Trim().ToLower();
            LogUtil.info($"YDataCheck:{key},value:{v}");
            if (v == "open")
            {                
                value = true;
                return true;
            }
            else if (v == "close")
            {
                value = false;
                return true;
            }
            return false;
        }
    }
}