FrmPackLine.cs 2.9 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DoubleLine
{
    public partial class FrmPackLine : Form
    {
        public FrmPackLine()
        {
            InitializeComponent();
        }

        private void FrmPackage_Load(object sender, EventArgs e)
        {
            Common.IO_Info[3].Box.DI_Changed_Event += DI4_Changed;
            Common.IO_Info[3].Box.DO_Changed_Event += DO4_Changed;
        }

        private void FrmPackLine_FormClosing(object sender, FormClosingEventArgs e)
        {
            Common.IO_Info[3].Box.DI_Changed_Event -= DI4_Changed;
            Common.IO_Info[3].Box.DO_Changed_Event -= DO4_Changed;
        }

        internal void DI4_Changed(Asa.IOModule.AIOBOX box, Asa.IOModule.Box_Sta[] sta)
        {
            for (int i = 0; i < sta.Length; i++)
            {
                if (Common.IO_Info[3].DI[i].Sta == sta[i]) continue;
                if (sta[i] == Asa.IOModule.Box_Sta.On)
                    tabPage1.Controls["DI4_" + i].BackColor = Color.Lime;
                else
                    tabPage1.Controls["DI4_" + i].BackColor = Color.LightGray;
                Common.IO_Info[3].DI[i].Sta = sta[i];
            }
        }

        internal void DO4_Changed(Asa.IOModule.AIOBOX box, Asa.IOModule.Box_Sta[] sta)
        {
            for (int i = 0; i < sta.Length; i++)
            {
                if (Common.IO_Info[3].DO[i].Sta == sta[i]) continue;
                if (sta[i] == Asa.IOModule.Box_Sta.On)
                    tabPage1.Controls["DO4_" + i].BackColor = Color.Lime;
                else
                    tabPage1.Controls["DO4_" + i].BackColor = Color.Transparent;

                Common.IO_Info[3].DO[i].Sta = sta[i];
            }
        }

        private void DO4_Click(object sender, EventArgs e)
        {
            if (!Common.IO_Info[3].Box.IsConn) return;

            int add = Convert.ToInt32((sender as Control).Name.Substring(4));
            if (add == 7)
                Common.IO_Info[3].Box.WriteDO(8, Asa.IOModule.Box_Sta.Off);
            else if (add == 8)
                Common.IO_Info[3].Box.WriteDO(7, Asa.IOModule.Box_Sta.Off);

            if (add == 10)
                Common.IO_Info[3].Box.WriteDO(11, Asa.IOModule.Box_Sta.Off);
            else if (add == 11)
                Common.IO_Info[3].Box.WriteDO(10, Asa.IOModule.Box_Sta.Off);

            if (add == 12)
                Common.IO_Info[3].Box.WriteDO(13, Asa.IOModule.Box_Sta.Off);
            else if (add == 13)
                Common.IO_Info[3].Box.WriteDO(12, Asa.IOModule.Box_Sta.Off);

            Asa.IOModule.Box_Sta sta = Common.IO_Info[3].Box.ReadDO(add);
            sta = Common.IO_Info[3].Box.ReverseStatus(sta);
            Common.IO_Info[3].Box.WriteDO(add, sta);
        }


    }
}