LEDModel.cs 1.19 KB
using LEDhelp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HHECS.LED
{
    public class LEDModel
    {
        public LEDHelper LED { get; set; }
        public Queue<string> InfoQueue { get; set; }

        public LEDModel(string ledIp, uint port, int timesec)
        {
            LED = new LEDHelper(ledIp, port, timesec);
            InfoQueue = new Queue<string>();
        }

        public void BeginSendInfo()
        {
            Task.Run(async () =>
            {
                if (LED != null && InfoQueue != null)
                {
                    while (true)
                    {
                        await Task.Delay(2000);
                        if (InfoQueue.Count > 0)
                        {
                            int i = LED.SendLedInfo(InfoQueue.Dequeue());
                            Console.WriteLine("LED发送返回值:" + i);
                            if (i != 0)
                            {
                                LED = new LEDHelper(null,0,0);
                            }
                        }
                    }
                }
            });
        }
    }
}