MainMachine _LedProcess.cs 4.7 KB
using CodeLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DeviceLibrary
{
    partial class MainMachine
    {
        Led AlarmLed;
        Led StandbyLed;
        Led RunningLed;

        System.Threading.Timer ledtimer;
        void LedProcessInit()
        {
            ledtimer = new System.Threading.Timer(new TimerCallback(LedProcess), null, 0, 1000);
            GC.KeepAlive(ledtimer);
        }

        void LedProcess(object o)
        {
            StandbyLed.LedState = LedState.off;
            AlarmLed.LedState = LedState.off;
            RunningLed.LedState = LedState.off;
            //回原 绿闪
            if (runStatus == RunStatus.HomeReset)
            {
                RunningLed.LedState = LedState.blink;
            }
            //正常 绿亮
            else if (runStatus == RunStatus.Running)
            {
                RunningLed.LedState = LedState.on;

                //出入库 绿闪 黄闪
                if (ClampMoveInfo.MoveStep > MoveStep.Wait
                || StoreMoveInfo.MoveStep > MoveStep.Wait
                || (StringMoveInfo.MoveStep > MoveStep.Wait && StringMoveInfo.MoveStep != MoveStep.StringReadyPut && StringMoveInfo.MoveStep <= MoveStep.StringOut_01))
                {
                    RunningLed.LedState = LedState.blink;
                    StandbyLed.LedState = LedState.blink;
                }
                //温度超限 绿亮 黄闪
                if (IsTHoutRange())
                {
                    RunningLed.LedState = LedState.on;
                    StandbyLed.LedState = LedState.blink;
                }
                //温度超限30分钟 绿亮 黄闪 红闪
                if (IsTHoutRangeOver30m())
                {
                    RunningLed.LedState = LedState.on;
                    StandbyLed.LedState = LedState.blink;
                    AlarmLed.LedState = LedState.blink;
                }
                //系统暂停,说明书未定义, 绿闪, 红闪
                if (!canRunning || UserPause)
                {
                    RunningLed.LedState = LedState.blink;
                    AlarmLed.LedState = LedState.blink;
                }
            }
            else if (runStatus == RunStatus.Stop)
            {
                //系统停止时有报警, 红亮
                if (hasAlarm)
                {
                    RunningLed.LedState = LedState.off;
                    StandbyLed.LedState = LedState.off;
                    AlarmLed.LedState = LedState.on;
                }
            }
            //系统运行时报警, 绿亮,红闪
            if (runStatus != RunStatus.Stop && hasAlarm)
            {
                RunningLed.LedState = LedState.on;
                StandbyLed.LedState = LedState.off;
                AlarmLed.LedState = LedState.blink;

                if (UserPause) {
                    RunningLed.LedState = LedState.blink;
                    StandbyLed.LedState = LedState.blink;
                }

                //if (ResetMoveInfo.MoveStep >= MoveStep.H13_HomeReset && ResetMoveInfo.MoveStep <= MoveStep.H14_HomeReset)
                //{
                //    StandbyLed.LedState = LedState.blink;
                //}
                //if (ClampMoveInfo.MoveStep >= MoveStep.NGOUT_02 && ClampMoveInfo.MoveStep <= MoveStep.NGOUT_03)
                //{
                //    StandbyLed.LedState = LedState.blink;
                //}
            }
            Led.LedGroup.ForEach((x) => { x.run(); });
        }
    }
    public class Led {
        public static List<Led> LedGroup = new List<Led>();
        public LedState LedState = LedState.off;
        ushort ledio;
        public Led(ushort io) {            
            ledio = io;
            LedGroup.Add(this);
        }
        IO_VALUE iovalue;
        IO_VALUE lastiovalue;
        public void run() {
            if (this.LedState == LedState.on) {
                iovalue = IO_VALUE.HIGH;
            }
            if (this.LedState == LedState.off)
            {
                iovalue = IO_VALUE.LOW;
            }
            if (this.LedState == LedState.blink)
            {
                if (iovalue == IO_VALUE.LOW)
                {
                    iovalue = IO_VALUE.HIGH;
                }
                else {
                    iovalue = IO_VALUE.LOW;
                }
            }
            if (iovalue != lastiovalue) {
                lastiovalue = iovalue;
                IOManager.WriteSingleDO("", 0x00, ledio, iovalue);
            }
        }
    }
    public enum LedState { 
        off,
        on,
        blink
    }
}