MainMachine _LedProcess.cs 3.5 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;
        Led RightLed;
        Led LeftLed;

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

        void LedProcess(object o)
        {
            //无法运行,量报警灯
            if (canRunning)
            {
                AlarmLed.LedState = LedState.on;
                StandbyLed.LedState = LedState.off;
            }
            else {
                AlarmLed.LedState = LedState.off;
                StandbyLed.LedState = LedState.on;
            }
            //所有过程都在运动,闪烁运行中灯
            if (!RightMoveInfo.IsStep(MoveStep.Wait)
                || !LeftMoveInfo.IsStep(MoveStep.Wait)
                || !MiddleMoveInfo.IsStep(MoveStep.M_Standby)
                || LabelMoveInfo.IsStep(MoveStep.Lbl_WaitPrint))
            {
                RunningLed.LedState = LedState.blink;
            }
            else {
                RunningLed.LedState = LedState.off;
            }

            if (alarmType == AlarmType.AxisAlarm
                || alarmType == AlarmType.AxisAlarm
                || alarmType == AlarmType.AxisMoveError) {
                AlarmLed.LedState = LedState.on;
            }
            if (runStatus == RunStatus.Running)
            {
                //右侧料串已空
                if (RightMoveInfo.IsStep(MoveStep.Wait) && IOValue(IO_Type.RightEnd_Check).Equals(IO_VALUE.HIGH) && RightShelfNoTray)
                    RightLed.LedState = LedState.blink;
                else
                    RightLed.LedState = LedState.off;
                //左侧料串已满
                if (LeftMoveInfo.IsStep(MoveStep.Wait) && IOValue(IO_Type.LeftEnd_Check).Equals(IO_VALUE.HIGH) && LeftShelfNoTray)
                    LeftLed.LedState = LedState.blink;
                else
                    LeftLed.LedState = LedState.off;
            }
            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
    }
}