领胜LDS 键盘AOI检测项目
wells
2020-07-12 5bf1b91009a182188d6d2245aa71653801eea60b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
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
{
    public partial class CtrlMotionCardIOStatus : UserControl
    {
        public List<IOItem> _monitorValues { get; set; }
 
        public CtrlMotionCardIOStatus()
        {
            InitializeComponent();
            InitIOEvent();
        }
        private IDevice Device { get; set; }
 
        protected MotionCardBase MotionCard
        {
            get => Device as MotionCardBase;
        }
 
        public CtrlMotionCardIOStatus(IDevice device)
        {
            InitializeComponent();
            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)
                {
                    var ioInArray = groupBoxIOIn.Controls.Find("ioIn" + ioItem.IONum, false);
                    if (ioInArray != null && ioInArray.Length == 1)
                    {
                        var ioIn = ioInArray[0] as IOIndicatorCtrl;
 
                        ioIn.IsOn = ioItem.Value == IOValue.TRUE;
                    }
                }
                else
                {
                    var ioOutArray = groupBoxIOOut.Controls.Find("ioOut" + ioItem.IONum, false);
                    if (ioOutArray != null && ioOutArray.Length == 1)
                    {
                        var ioOut = ioOutArray[0] as IOIndicatorCtrl;
 
                        if (MotionCard.IConfig.IsOutputReversed)
                        {
                            ioOut.IsOn = ioItem.Value == IOValue.TRUE;
                        }
                        else
                        {
                            ioOut.IsOn = ioItem.Value == IOValue.FALSE;
                        }
                    }
                }
            }
 
            this.Invalidate();
        }
    }
}