From 4bc5ee48e537d56190c943330f0093562912fb4f Mon Sep 17 00:00:00 2001
From: wells <123>
Date: 星期六, 11 七月 2020 12:25:33 +0800
Subject: [PATCH] io索引问题

---
 src/Bro.UI.Device.Winform/MotionCard/CtrlMotionCardIOStatus.cs |   40 +++++++++++++++++++++++++++++++++++-----
 1 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/src/Bro.UI.Device.Winform/MotionCard/CtrlMotionCardIOStatus.cs b/src/Bro.UI.Device.Winform/MotionCard/CtrlMotionCardIOStatus.cs
index 13762cf..cef3b62 100644
--- a/src/Bro.UI.Device.Winform/MotionCard/CtrlMotionCardIOStatus.cs
+++ b/src/Bro.UI.Device.Winform/MotionCard/CtrlMotionCardIOStatus.cs
@@ -10,6 +10,8 @@
 using Bro.Common.Model;
 using Bro.UI.Model.Winform;
 using static Bro.Common.Helper.EnumHelper;
+using Bro.Common.Interface;
+using Bro.Common.Base;
 
 namespace Bro.UI.Device.Winform
 {
@@ -20,17 +22,43 @@
         public CtrlMotionCardIOStatus()
         {
             InitializeComponent();
+            InitIOEvent();
+        }
+        private IDevice Device { get; set; }
+
+        protected MotionCardBase MotionCard
+        {
+            get => Device as MotionCardBase;
         }
 
-
-        public CtrlMotionCardIOStatus(List<IOItem> monitorValues)
+        public CtrlMotionCardIOStatus(IDevice device)
         {
             InitializeComponent();
-            _monitorValues = monitorValues;
+            Device = device;
+            InitIOEvent();
+        }
+
+        private void InitIOEvent()
+        {
+            foreach (var ctr in groupBoxIOOut.Controls)
+            {
+                if (ctr is IOIndicatorCtrl ioOut)
+                {
+                    ioOut.Cursor = Cursors.Hand;
+                    ioOut.OnIODoubleClick += IoOut_DoubleClick;
+                }
+            }
+        }
+
+        private void IoOut_DoubleClick(string name, bool isOn)
+        {
+            var index = Convert.ToInt16(name.Substring(5));
+            MotionCard.WriteOutput(index, isOn ? IOValue.FALSE : IOValue.TRUE);
         }
 
         private void RefreshIOStatus(object sender, EventArgs e)
         {
+            _monitorValues = MotionCard.MonitorValues;
             foreach (var ioItem in _monitorValues)
             {
                 if (ioItem.IOType == Common.Helper.EnumHelper.IOType.INPUT)
@@ -39,7 +67,7 @@
                     if (ioInArray != null && ioInArray.Length == 1)
                     {
                         var ioIn = ioInArray[0] as IOIndicatorCtrl;
-                        ioIn.IsOn = ioItem.Value == IOValue.TRUE;
+                        ioIn.IsOn = ioItem.Value == IOValue.FALSE;
                     }
                 }
                 else
@@ -48,10 +76,12 @@
                     if (ioOutArray != null && ioOutArray.Length == 1)
                     {
                         var ioOut = ioOutArray[0] as IOIndicatorCtrl;
-                        ioOut.IsOn = ioItem.Value == IOValue.TRUE;
+                        ioOut.IsOn = ioItem.Value == IOValue.FALSE;
                     }
                 }
             }
+
+            this.Invalidate();
         }
     }
 }

--
Gitblit v1.8.0