Form1.cs 7.65 KB
using LEDhelp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LedHelper
{
    public partial class Form1 : Form
    {
        LEDHelper ProduceLED;
        LEDHelper BatteriesLED;
        LEDHelper PartsStation1LED;
        LEDHelper PartsStation2LED;
        public Queue<string> ProduceQueue { get; set; } = new Queue<string>();
        public Queue<string> BatteriesQueue { get; set; } = new Queue<string>();
        public Queue<string> PartsStation1Queue { get; set; } = new Queue<string>();
        public Queue<string> PartsStation2Queue { get; set; } = new Queue<string>();

        LEDExcute ledExcute = new LEDExcute();

        public Form1()
        {
            InitializeComponent();
            string produceLedIP = ConfigurationManager.AppSettings["ProductLedIP"];
            string batteriesLedIP = ConfigurationManager.AppSettings["BatteriesLedIP"];
            string partsStation1LedIP = ConfigurationManager.AppSettings["PartsStation1LedIP"];
            string partsStation2LedIP = ConfigurationManager.AppSettings["PartsStation2LedIP"];
            int ledPort = Convert.ToInt32(ConfigurationManager.AppSettings["ledPort"]);
            ProduceLED = new LEDhelp.LEDHelper(produceLedIP, (uint)ledPort, 1);
            BatteriesLED = new LEDhelp.LEDHelper(batteriesLedIP, (uint)ledPort, 1);
            PartsStation1LED = new LEDhelp.LEDHelper(partsStation1LedIP, (uint)ledPort, 1);
            PartsStation2LED = new LEDhelp.LEDHelper(partsStation2LedIP, (uint)ledPort, 1);

            //LED
            //ledExcute.BeginSendInfo();
        }

        private void sendLedInfo(int direction, int color, String sendText)
        {
            if (color == LEDhelp.LEDHelper.GREEN)
            {
                sendText = "\\C2" + sendText;
            }
            else if (color == LEDhelp.LEDHelper.YELLOW)
            {
                sendText = "\\C3" + sendText;
            }
            else
            {
                sendText = "\\C1" + sendText;
            }
            if (direction == LEDhelp.LEDHelper.Produce)
            {
                ProduceLED.SendLedInfo(sendText);
            }

            if (direction == LEDhelp.LEDHelper.Batteries)
            {
                BatteriesLED.SendLedInfo(sendText);
            }


            if (direction == LEDhelp.LEDHelper.PartsStation1)
            {
                PartsStation1LED.SendLedInfo(sendText);
            }


            if (direction == LEDhelp.LEDHelper.PartsStation2)
            {
                PartsStation2LED.SendLedInfo(sendText);
            }

        }

        private void SCREEN_ForceOnOff(int direction, byte status)
        {
            if (direction == LEDhelp.LEDHelper.Produce)
            {
                ProduceLED.SCREEN_ForceOnOff(status);
            }

            if (direction == LEDhelp.LEDHelper.Batteries)
            {
                BatteriesLED.SCREEN_ForceOnOff(status);
            }


            if (direction == LEDhelp.LEDHelper.PartsStation1)
            {
                PartsStation1LED.SCREEN_ForceOnOff(status);
            }


            if (direction == LEDhelp.LEDHelper.PartsStation2)
            {
                PartsStation2LED.SCREEN_ForceOnOff(status);
            }
        }

        // value 0-15 值越大亮度越大
        public void setBrightness(int direction, byte value)
        {
            if (direction == LEDhelp.LEDHelper.Produce)
            {
                ProduceLED.setBrightness(1, value, null);
            }

            if (direction == LEDhelp.LEDHelper.Batteries)
            {
                BatteriesLED.setBrightness(1, value, null);
            }


            if (direction == LEDhelp.LEDHelper.PartsStation1)
            {
                PartsStation1LED.setBrightness(1, value, null);
            }


            if (direction == LEDhelp.LEDHelper.PartsStation2)
            {
                PartsStation2LED.setBrightness(1, value, null);
            }

        }

        public void SCREEN_DelDynamicArea(int direction, byte DeleteAreaId)
        {
            if (direction == LEDhelp.LEDHelper.Produce)
            {
                ProduceLED.SCREEN_DelDynamicArea(DeleteAreaId);
            }

            if (direction == LEDhelp.LEDHelper.Batteries)
            {
                BatteriesLED.SCREEN_DelDynamicArea(DeleteAreaId);
            }


            if (direction == LEDhelp.LEDHelper.PartsStation1)
            {
                PartsStation1LED.SCREEN_DelDynamicArea(DeleteAreaId);
            }


            if (direction == LEDhelp.LEDHelper.PartsStation2)
            {
                PartsStation2LED.SCREEN_DelDynamicArea(DeleteAreaId);
            }
        }


        private void button1_Click(object sender, EventArgs e)
        {
            string sendText = string.Format("任务类型:电芯\\n托盘条码:P00010\\n仓位:L-001-002-002-000\\n物料:2001020401,10\\n物料:2001020402,10\\n物料:2001020403,100\\n物料:2001020404,100");
           // ledExcute.BatteriesQueue.Enqueue(sendText);
            LED(5, sendText);
            //SCREEN_ForceOnOff(LEDhelp.LEDHelper.LEFT, LEDhelp.LEDHelper.OPEN);
            //SCREEN_DelDynamicArea(LEDhelp.LEDHelper.LEFT, 0);
            //sendLedInfo(LEDhelp.LEDHelper.LEFT, LEDhelp.LEDHelper.GREEN, sendText);
            //setBrightness(LEDhelp.LEDHelper.LEFT, 10);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string sendText = string.Format("任务类型:单排\\n托盘条码:P00010\\n仓位:L-001-002-002-000\\n物料:2001020401,10\\n物料:2001020402,10\\n物料:2001020403,100\\n物料:2001020404,100");
            //ledExcute.ProduceQueue.Enqueue(sendText);
            LED(4, sendText);
            //SCREEN_ForceOnOff(LEDhelp.LEDHelper.RIGHT, LEDhelp.LEDHelper.OPEN);
            //SCREEN_DelDynamicArea(LEDhelp.LEDHelper.RIGHT, 0);
            //sendLedInfo(LEDhelp.LEDHelper.RIGHT, LEDhelp.LEDHelper.RED, sendText);
            //setBrightness(LEDhelp.LEDHelper.RIGHT, 5);
        }

        public void LED(int led, string sendText)
        {
            if (led == 6)
            {
                SCREEN_ForceOnOff(LEDhelp.LEDHelper.Produce, LEDhelp.LEDHelper.OPEN);
                SCREEN_DelDynamicArea(LEDhelp.LEDHelper.Produce, 0);
                sendLedInfo(LEDhelp.LEDHelper.Produce, LEDhelp.LEDHelper.RED, sendText);
                setBrightness(LEDhelp.LEDHelper.Produce, 5);
            }

            if (led == 5)
            {
                SCREEN_ForceOnOff(LEDhelp.LEDHelper.Batteries, LEDhelp.LEDHelper.OPEN);
                SCREEN_DelDynamicArea(LEDhelp.LEDHelper.Batteries, 0);
                sendLedInfo(LEDhelp.LEDHelper.Batteries, LEDhelp.LEDHelper.RED, sendText);
                setBrightness(LEDhelp.LEDHelper.Batteries, 5);
            }

            if (led == 4)
            {
                SCREEN_ForceOnOff(LEDhelp.LEDHelper.PartsStation1, LEDhelp.LEDHelper.OPEN);
                SCREEN_DelDynamicArea(LEDhelp.LEDHelper.PartsStation1, 0);
                sendLedInfo(LEDhelp.LEDHelper.PartsStation1, LEDhelp.LEDHelper.RED, sendText);
                setBrightness(LEDhelp.LEDHelper.PartsStation1, 5);
            }

            if (led == 3)
            {
                SCREEN_ForceOnOff(LEDhelp.LEDHelper.PartsStation2, LEDhelp.LEDHelper.OPEN);
                SCREEN_DelDynamicArea(LEDhelp.LEDHelper.PartsStation2, 0);
                sendLedInfo(LEDhelp.LEDHelper.PartsStation2, LEDhelp.LEDHelper.RED, sendText);
                setBrightness(LEDhelp.LEDHelper.PartsStation2, 5);
            }
        }




    }
}