From 642cd31f0d1586a2a5ca6f9a3b3364725f4f1ecd Mon Sep 17 00:00:00 2001
From: wells.liu <wells.liu@broconcentric.com>
Date: 星期六, 04 七月 2020 13:44:24 +0800
Subject: [PATCH] 暂存

---
 src/Bro.M071.Process/M071Process_MotionCard.cs |  217 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 217 insertions(+), 0 deletions(-)

diff --git a/src/Bro.M071.Process/M071Process_MotionCard.cs b/src/Bro.M071.Process/M071Process_MotionCard.cs
new file mode 100644
index 0000000..514b46d
--- /dev/null
+++ b/src/Bro.M071.Process/M071Process_MotionCard.cs
@@ -0,0 +1,217 @@
+锘縰sing 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 姝e父鎵ц  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);
+            }
+        }
+    }
+}

--
Gitblit v1.8.0