领胜LDS 键盘AOI检测项目
wells.liu
2020-07-04 642cd31f0d1586a2a5ca6f9a3b3364725f4f1ecd
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
using Bro.Common.Base;
using Bro.Common.Helper;
using Bro.Common.Interface;
using Bro.Common.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static Bro.Common.Helper.EnumHelper;
 
namespace Bro.M071.Process
{
    public partial class M071Process
    {
        Timer _resetTimer = null;
        const int FULLRESETTIME = 5;
 
        MachineState machineState = MachineState.Unknown;
        MachineState MachineState
        {
            get => machineState;
            set
            {
                machineState = value;
 
                switch (machineState)
                {
                    case MachineState.Ready:
                        break;
                    case MachineState.Running:
                        break;
                    case MachineState.Alarm:
                        break;
                    case MachineState.Pause:
                        break;
                    default:
                        break;
                }
            }
        }
 
        [ProcessMethod("MotionCardBase", "Reset", "简单复位操作", InvokeType.TestInvoke)]
        public ProcessResponse Reset(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
        {
            //if (opConfig == null)
            //{
            //    var monitorSet = Config.MonitorSetCollection.FirstOrDefault(u => u.MethodCode == "Reset");
            //    if (monitorSet == null)
            //        throw new ProcessException("未配置默认复位操作");
 
            //    opConfig = monitorSet.OpConfig;
            //    if (opConfig == null)
            //        throw new ProcessException("未配置复位操作具体配置动作");
 
            //    if (invokeDevice == null)
            //    {
            //        invokeDevice = DeviceCollection.FirstOrDefault(u => u.Id == monitorSet.InvokeDevice);
            //        if (invokeDevice == null)
            //            throw new ProcessException("未配置复位操作执行设备");
            //    }
            //}
 
            MotionCardDefaultRun("Reset", ref opConfig, ref invokeDevice);
 
            if (_resetTimer == null)
            {
                _resetTimer = new Timer(FullReset, null, -1, -1);
            }
 
            if (opConfig.InputPara.Count > 0)
            {
                //大复位信号
                _resetTimer.Change(-1, opConfig.InputPara[0] == 1 ? FULLRESETTIME * 1000 : -1);
            }
 
            //if (invokeDevice is MotionCardBase motionCard)
            //{
            //    motionCard.Run(opConfig);
            //}
 
            return new ProcessResponse(true);
        }
 
        private void FullReset(object state)
        {
            FullReset(null, null, null);
        }
 
        [ProcessMethod("MotionCardOperationConfigCollection", "FullReset", "大复位操作", InvokeType.TestInvoke)]
        public ProcessResponse FullReset(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
        {
            //if (opConfig == null)
            //{
            //    var monitorSet = Config.MonitorSetCollection.FirstOrDefault(u => u.MethodCode == "FullReset");
            //    if (monitorSet == null)
            //        throw new ProcessException("未配置默认大复位操作");
 
            //    opConfig = monitorSet.OpConfig;
            //    if (opConfig == null)
            //        throw new ProcessException("未配置大复位操作具体配置动作");
 
            //    if (invokeDevice == null)
            //    {
            //        invokeDevice = DeviceCollection.FirstOrDefault(u => u.Id == monitorSet.InvokeDevice);
            //        if (invokeDevice == null)
            //            throw new ProcessException("未配置大复位操作执行设备");
            //    }
            //}
 
            //if (invokeDevice is MotionCardBase motionCard)
            //{
            //    motionCard.Run(opConfig);
            //}
 
            //MotionCardDefaultRun("FullReset", ref opConfig, ref invokeDevice);
 
            return new ProcessResponse(true);
        }
 
        /// <summary>
        /// 暂停标志  
        /// WaitHandle 暂停句柄  默认为非阻塞 可执行
        /// WaitResult 暂停标志 true 正常执行  false 暂停中
        /// </summary>
        ManualWaitConfirm _pauseHandle = new ManualWaitConfirm()
        {
            WaitHandle = new ManualResetEvent(true),
            WaitResult = true,
        };
 
        [ProcessMethod("", "PauseJob", "暂停流程", InvokeType.TestInvoke)]
        public ProcessResponse PauseJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
        {
            if (_pauseHandle.WaitResult)
            {
                #region 板卡暂停动作
                #endregion
 
                _pauseHandle.WaitHandle.Reset();
            }
            else
            {
                #region 板卡恢复动作
                #endregion
 
                _pauseHandle.WaitHandle.Set();
            }
 
            _pauseHandle.WaitResult = !_pauseHandle.WaitResult;
            return new ProcessResponse(_pauseHandle.WaitResult);
        }
 
        [ProcessMethod("MotionCardBase", "SwitchLightRed", "切换指示灯-红", InvokeType.TestInvoke)]
        public ProcessResponse SwitchLightRed(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
        {
            MotionCardDefaultRun("SwitchLightRed", ref opConfig, ref invokeDevice);
            return new ProcessResponse(true);
        }
 
        [ProcessMethod("MotionCardBase", "SwitchLightYellow", "切换指示灯-黄", InvokeType.TestInvoke)]
        public ProcessResponse SwitchLightYellow(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
        {
            return new ProcessResponse(true);
        }
 
        [ProcessMethod("MotionCardBase", "SwitchLightGreen", "切换指示灯-绿", InvokeType.TestInvoke)]
        public ProcessResponse SwitchLightGreen(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
        {
            return new ProcessResponse(true);
        }
 
        [ProcessMethod("MotionCardBase", "SwitchBeep", "切换蜂鸣器", InvokeType.TestInvoke)]
        public ProcessResponse SwitchBeep(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
        {
            return new ProcessResponse(true);
        }
 
        [ProcessMethod("MotionCardBase", "SwitchNormalLight", "切换日光灯", InvokeType.TestInvoke)]
        public ProcessResponse SwitchNormalLight(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
        {
            MotionCardDefaultRun("SwitchNormalLight", ref opConfig, ref invokeDevice);
 
            return new ProcessResponse(true);
        }
 
        private void MotionCardDefaultRun(string methodCode, ref IOperationConfig opConfig, ref IDevice invokeDevice)
        {
            IMonitorSet monitorSet = null;
            if (opConfig == null)
            {
                monitorSet = Config.MonitorSetCollection.FirstOrDefault(u => u.MethodCode == methodCode);
                if (monitorSet == null)
                    throw new ProcessException("未配置默认操作");
 
                opConfig = monitorSet.OpConfig;
                if (opConfig == null)
                    throw new ProcessException("未配置具体配置动作");
            }
 
            if (invokeDevice == null)
            {
                invokeDevice = DeviceCollection.FirstOrDefault(u => u.Id == monitorSet.InvokeDevice);
                if (invokeDevice == null)
                    throw new ProcessException("未配置操作执行设备");
            }
 
            if (invokeDevice is MotionCardBase motionCard)
            {
                motionCard.Run(opConfig);
            }
        }
    }
}