BatchAxisController.cs 2.5 KB
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OnlineStore.DeviceLibrary
{
    /// <summary>
    /// 批量上下料 轴,检测料盘检测信号处理
    /// </summary>
    public class BatchAxisController
    {
      
        private static  bool IsStop = false;
        private static  System.Timers.Timer checkTimer = null;
        private static string TargetIoType = IO_Type.TrayCheck_LoadMaterial;
        private static IO_VALUE TargetIoValue = IO_VALUE.HIGH;
        public static bool StartCheck(string targetIo, IO_VALUE value = IO_VALUE.HIGH)
        {
            if (checkTimer == null)
            {
                checkTimer = new System.Timers.Timer();
                checkTimer.AutoReset = true;
                checkTimer.Interval += 30;
                checkTimer.Elapsed += CheckTimer_Elapsed;
                checkTimer.Enabled = false;
            }
            TargetIoValue = value;
            TargetIoType = targetIo;
            checkTimer.Start();
            return true;
        }
         
        public static bool StopCheck()
        {
            if (!(checkTimer == null))
            {
                checkTimer.Stop();
            }
            return true;
        }
        private static  bool IsInProcess = false;
        private static DateTime preTime = DateTime.Now;
        private static void CheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (IsInProcess) { return; }
            IsInProcess = true;
            bool result = false;
            if (IOManager.IOValue(TargetIoType).Equals(TargetIoValue))
            {
                LogUtil.info("批量上料轴,检测到 " + TargetIoType + "="+TargetIoValue+",可以停止运动");
                result = true;
            } 
            //else if (IOManager.IOValue(IO_Type.BatchAxis_Limit).Equals(IO_VALUE.HIGH)) 
            //{
            //    LogUtil.info("批量上料轴,检测到正极限信号,可以停止运动");
            //    result = true; 
            //}
            if (result)
            {
                //AutoAxisIsMove = 0;
                LogUtil.debug("批量上料轴, 停止运动");
                ACServerManager.SuddenStop(StoreManager.Config.Batch_Axis.DeviceName, StoreManager.Config.Batch_Axis.GetAxisValue());
                StopCheck();
            }
            preTime = DateTime.Now;
            IsInProcess = false;
        }
    }
}