MainMachine _LedRGBProcess.cs 5.1 KB
using OnlineStore;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using static System.Windows.Forms.AxHost;

namespace DeviceLibrary
{
    partial class MainMachine
    {
        private Flyelectronic_485_RGB_Controller rGB_Controller = null;

        private bool rgbLedInitOk = false;
        public string lastColor = "";
        System.Threading.Timer ledRgbTimer;

        public bool CloseRgbLed()
        {
            if(rgbLedInitOk)
            {
                rGB_Controller.Dispose();
            }
            return true;
        }

        public bool InitRgbLed(out string msg)
        {
            msg = "";
            string port = Setting_Init.Device_LedLight_PortName;
            if (port == "")
            {
                LogUtil.info( "未配置LED灯端口号");
                return false;
            }
            rGB_Controller = new Flyelectronic_485_RGB_Controller("LED");
            bool result = rGB_Controller.OpenPort(port, out msg);
            if (result)
            {
                LogUtil.error("LED灯初始化成功");
                rgbLedInitOk = true;
                ledRgbTimer = new System.Threading.Timer(new TimerCallback(RgbLedProcess), null, 0, 1000);
                GC.KeepAlive(ledtimer);
                msg = "";
                return true;
            }
            else
            {
                LogUtil.error("LED灯初始化失败:" + msg);
            }
            return false;
        }
        public void CloseColor()
        {
            rGB_Controller.CloseLed();
            lastColor = "";
        }
        public  void ShowColor(Color color)
        {
            if (lastColor!=""&& lastColor.Equals(color.Name.ToString()))
            {
                return;
            }
            //rGB_Controller.CloseLed();
            rGB_Controller.ShowColor(color);
            lastColor = color.Name.ToString();
        }
       public void ShowYellowLight()
        {
            lastColor = "yellowL";
            //rGB_Controller.CloseLed();
            rGB_Controller.ShowYellowLight();
        }
        public void ShowGreenLight()
        {
            lastColor = "greenL";
            //rGB_Controller.CloseLed();
            rGB_Controller.ShowGreenLight();
        }
        private void RgbLedProcess(object o)
        {
            if (rGB_Controller == null || (!rgbLedInitOk))
            {
                return;
            }

            //            红色: 急停,
            //紫色: 异常, 
            //蓝绿: 待机
            //流动绿: 入库
            //流动黄: 出库,
            //白色: 等待用户响应(等待取走盘等), 
            //蓝色: 扫码检测
            if (runStatus == RunStatus.Stop)
            {
                //未启动 黑色
                ShowColor(Color.Black);
            }

            else if (isInSuddenDown)
            {
                //红色: 急停,
                ShowColor(Color.Red);
            }
            else if (hasAlarm)
            {
                //紫色: 异常,
                ShowColor(Color.Purple);

            } //温度超限  
            else if (IsTHoutRange())
            {
                //紫色: 异常,
                ShowColor(Color.Purple);
            }
            //温度超限30分钟 
            else if (IsTHoutRangeOver30m())
            {
                //紫色: 异常,
                ShowColor(Color.Purple);
            }
            else if (runStatus == RunStatus.Running)
            {
                var h = NGDoor_Tray_Test_Reel;

                if (h != null && h.Value)
                {
                    //等待料盘拿走
                    //白色: 等待用户响应(等待取走盘等), 
                    //蓝色: 扫码检测 
                    ShowColor(Color.White);
                }
                else if (ClampMoveInfo.IsStep(MoveStep.ReelClamp_10) && (!RobotManage.InoutDebugMode) && (!ClampMoveInfo.MoveParam.IsNg))
                {
                    //蓝色: 扫码检测 
                    ShowColor(Color.Blue);
                }
                //出入库 绿闪 黄闪
                else if (StoreMoveInfo.MoveStep >= MoveStep.StoreOut10)
                {
                    ////流动黄: 出库, 
                    //if (lastColor.Equals("yellowRun"))
                    //{
                    //    return;
                    //}
                    ShowYellowLight();

                }
                else if (StoreMoveInfo.MoveStep >= MoveStep.StoreIn01)
                {

                    ////流动绿: 入库
                    //if (lastColor.Equals("yellowRun"))
                    //{
                    //    return;
                    //}
                    ShowGreenLight();
                }
            }
            else
            {
                //待机 蓝绿
                ShowColor(Color.FromArgb(0, 128, 128));
            }
        }
    }
}