RgbLedController.cs 2.1 KB
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TSA_V.Common;
using TSA_V.LoadCSVLibrary;

namespace TSA_V.DeviceLibrary
{
    public class RgbLedController
    {
        private static  int posLength = 8;
        public static Flyelectronic_485_RGB_Controller rGB_Controller = null;

        public static bool Init()
        {
            if (Setting_NInit.RGBLed_PortName == "")
            {
                LogUtil.error("未配置RGBLED端口号");
                return false;

            }
            rGB_Controller = new Flyelectronic_485_RGB_Controller("LED");
            rGB_Controller.OpenPort(Setting_NInit.RGBLed_PortName, out string errmsg);
            if (errmsg != null)
            {
                LogUtil.error("初始化RgbLed灯失败:" + errmsg);
                return false;
            }
            return true;
        }

        private static Color defColor = Color.Green;
        public static void OpenPosLed(TSAVPosition position)
        {
            if (position.IsRgbLed())
            {
                List<int> leds = position.getLedList();
                OpenPosLed(leds);
            }
        }
        public static void OpenPosLed(List<int> leds)
        {

            if (rGB_Controller == null)
            { 
                return;
            }
            if (leds.Count == 1)
            {
                int start = leds[0];
                for (int i = start + 1; i < start + posLength; i++)
                {
                    leds.Add(i);
                }
            }
            rGB_Controller.ShowLedColor(defColor, leds);

        }

        public static void CloseAll()
        {
            if (rGB_Controller == null)
            {
                return;
            }
            rGB_Controller.ShowColor(Color.Black);
        }

        public static void OpenAll()
        {
            if (rGB_Controller == null)
            {
                return;
            }
            rGB_Controller.ShowColor(defColor);
        }
    }
}