RobotBean_Partial.cs 7.1 KB
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace OnlineStore.DeviceLibrary
{
    partial class RobotBean
    {
        #region 定时处理方法 
          
        private DateTime preIoTimerOutTime = DateTime.Now;
        private void IOTimeOutProcess()
        {
            try
            {
                TimeSpan span = DateTime.Now - preIoTimerOutTime;
                if (span.TotalSeconds > 1 && alarmType.Equals(AlarmType.IoSingleTimeOut))
                {
                    preIoTimerOutTime = DateTime.Now;

                    if (runStatus < RobotRunStatus.Runing || isInSuddenDown || isNoAirCheck)
                    {
                        return;
                    }

                    //若BOX和移栽都没有在等待Io的过程中则此Io超时异常可能已经处理过
               //     if (MoveInfo.IsInWait.Equals(false) && SW41_MoveInfo.IsInWait.Equals(false) && SW23_MoveInfo.IsInWait.Equals(false))
                    {
                        LogUtil.info(Name + "清理信号超时报警【" + WarnMsg + "】 ");
                        alarmType = AlarmType.None;
                        SetWarnMsg("");
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtil.error("IOTimeOutProcess出错:", ex);
            }
        }
        private DateTime preRWTime = DateTime.Now;
        private void CheckWait(RobotMoveInfo checkWaitInfo)
        {
            try
            {
                List<WaitResultInfo> list = checkWaitInfo.WaitList;
                if (list.Count <= 0)
                {
                    checkWaitInfo.EndStepWait();
                    return;
                }

                //当等待超过一分钟时,需要打印提示 
                TimeSpan span = DateTime.Now - checkWaitInfo.LastSetpTime;
                string NotOkMsg = "";
                bool isOk = true;
                if (checkWaitInfo.OneWaitCanEndStep)
                {
                    isOk = false;
                }
                foreach (WaitResultInfo wait in list)
                {
                    if (wait == null || wait.IsEnd)
                    {
                        continue;
                    }
                    NotOkMsg = " [" + wait.ToStr() + "] ";
                    if (wait.WaitType.Equals(WaitEnum.W002_IOValue))
                    {
                        NotOkMsg = " [" + IOManager.GetDI(wait.IoType, DeviceID).DisplayStr + "=" + wait.IoValue + "] ";
                        wait.IsEnd = IOValue(wait.IoType).Equals(wait.IoValue);

                        if (!wait.IsEnd)
                        { 
                            TimeSpan rwSpan = DateTime.Now - preRWTime;
                            //一分钟还未检测到
                            if (span.TotalSeconds > RobotManager.Config.IOSingle_TimerOut && NoAlarm())
                            {
                                ConfigIO io = baseConfig.getWaitIO(wait.IoType);
                                WarnMsg = Name + "[" + checkWaitInfo.MoveStep + "]等待" + NotOkMsg + " 超时";
                                Alarm(AlarmType.IoSingleTimeOut);
                                LogUtil.error(MoveInfo.Name + WarnMsg, 901);
                            }
                            //超过报警时长
                            else if (rwSpan.TotalSeconds > 5 && span.TotalSeconds > 6 && span.TotalSeconds < RobotManager.Config.IOSingle_TimerOut * 2)
                            {
                                preRWTime = DateTime.Now;
                                string msg = checkWaitInfo.Name + "  " + NotOkMsg + "已等待 " + Math.Round(span.TotalSeconds,1) + "秒,重写DO:";
                                bool isLog = false;
                                foreach (WaitResultInfo ww in list)
                                {
                                    if (ww != null && ww.WaitType.Equals(2) && baseConfig.DOList.ContainsKey(ww.IoType))
                                    {
                                        if (IOManager.DOValue(ww.IoType, baseConfig.Id).Equals(ww.IoValue).Equals(false))
                                        {
                                            isLog = true;
                                            IOMove(ww.IoType, ww.IoValue);
                                            msg += ww.ToStr() + ",";
                                        }
                                    }
                                }
                                if (isLog)
                                {
                                    LogUtil.error(msg);
                                }
                            }
                            if (!checkWaitInfo.OneWaitCanEndStep)
                            {
                                isOk = false;
                                break;
                            }
                        }
                    }
                    else if (wait.WaitType.Equals(WaitEnum.W003_Time))
                    {
                        wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
                    }
                 
                    if (wait.IsEnd)
                    {
                        if (checkWaitInfo.OneWaitCanEndStep)
                        {
                            isOk = true;
                            break;
                        }
                    }
                    else
                    {
                        if (!checkWaitInfo.OneWaitCanEndStep)
                        {
                            isOk = false;
                            break;
                        }
                    }
                }
                if (isOk)
                {
                    checkWaitInfo.EndStepWait();
                }
                else if (span.TotalSeconds > checkWaitInfo.TimeOutSeconds)
                {
                    WarnMsg = checkWaitInfo.Name + "[" + checkWaitInfo.MoveStep + "][" + NotOkMsg + "]已等待[" + Math.Round(span.TotalSeconds, 1) + "]秒";
                    LogUtil.error(WarnMsg, 900);
                    Alarm(AlarmType.IoSingleTimeOut);
                }
            }
            catch (Exception ex)
            {
                LogUtil.error(checkWaitInfo.Name + " [" + checkWaitInfo.MoveStep + "] CheckWait 出错:", ex);
            }
        }
        #endregion


       

        public override bool StartLabelling(WorkParam param)
        {
            return true;
        }
        protected override void LabellingProcess()
        {
        }
    

      

        public override bool StartWorking(WorkParam param)
        {
            return true;

        }
        protected override void WorkingProcess()
        {
        }
         
         
        private void InOutLog(string msg)
        {
            LogUtil.debug(Name + msg);
        }

        public override void Alarm(AlarmType alarmType)
        { 
        }
         



    }
}