LEDHelper.cs 2.73 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LEDhelper
{
    public class LEDHelper
    {
        //led对应的IP地址
        private byte[] led_ip;
        //led对应的端口号
        private uint led_port;
        //句柄
        private uint hand;
        //超时时间
        private int timeout = 1;

        private int mode = 0;

        public LEDHelper(string ledIp, uint port, int timesec)
        {
            led_ip = Encoding.ASCII.GetBytes(ledIp);
            led_port = port;
            timeout = timesec;
        }

        public int SendLedInfo(string sendText)
        {
            int result = 0;
            if (hand <= 0)
            {
                CreateClient();
            }
            LedInfo ledinfo = new LedInfo(sendText);
            result = Led5kSDK.SCREEN_SendDynamicArea(hand, ledinfo.bx_5k, (ushort)ledinfo.AreaText.Length, ledinfo.AreaText);
            return result;
        } 

        public uint CreateClient()
        {
            hand= Led5kSDK.CreateClient(led_ip, led_port, Led5kSDK.bx_5k_card_type.BX_5MK2,timeout, mode, null);
            return hand;
        }

        public void CloseClient()
        {
            Led5kSDK.Destroy(hand);
        }

        public int CheckPing()
        {
            return  Led5kSDK.CON_PING(hand);
        }

        /// <summary>
        /// 获取控制器类型的对应16进制编码
        /// 任意
        ///BX_5K1
        ///BX_5K2
        ///BX_5MK1
        ///BX_5MK2
        ///BX_5K1Q_YY
        ///BX_6K1
        ///BX_6K2
        ///BX_6K3
        ///BX_6K1_YY
        ///BX_6K2_YY
        ///BX_6K3_YY
        /// </summary>
        /// <param name="controllerType"></param>
        /// <returns></returns>
        private static byte getControllerTypeByName(string controllerType)
        {
            byte result = 0;
            switch (controllerType)
            {
                case "任意": { result = 0xFE; break; };
                case "BX_5K1": { result = 0x51; break; };
                case "BX_5K2": { result = 0x58; break; };
                case "BX_5MK1": { result = 0x54; break; };
                case "BX_5MK2": { result = 0x53; break; };
                case "BX_5K1Q_YY": { result = 0x5c; break; };
                case "BX_6K1": { result = 0x61; break; };
                case "BX_6K2": { result = 0x62; break; };
                case "BX_6K3": { result = 0x63; break; };
                case "BX_6K1_YY": { result = 0x64; break; };
                case "BX_6K2_YY": { result = 0x65; break; };
                case "BX_6K3_YY": { result = 0x66; break; };
                default:result = 0; break;
            }
            return result;
        }
    }
}