From 6ca2f993973295e4da82634761da0e5c00e0ef8e Mon Sep 17 00:00:00 2001
From: xcd <834800634@qq.com>
Date: 星期二, 14 七月 2020 08:54:27 +0800
Subject: [PATCH] Merge branch 'master' of http://gitblit.broconcentric.com:8088/r/M071

---
 src/Bro.M071.Process/M071Process_MotionCard.cs |   81 +++++++++++++++++++++++++++++++---------
 1 files changed, 62 insertions(+), 19 deletions(-)

diff --git a/src/Bro.M071.Process/M071Process_MotionCard.cs b/src/Bro.M071.Process/M071Process_MotionCard.cs
index 70bb5c8..2821708 100644
--- a/src/Bro.M071.Process/M071Process_MotionCard.cs
+++ b/src/Bro.M071.Process/M071Process_MotionCard.cs
@@ -26,6 +26,9 @@
             get => machineState;
             set
             {
+                if (machineState == value)
+                    return;
+
                 machineState = value;
 
                 switch (machineState)
@@ -40,9 +43,10 @@
 
                         Task.Run(() =>
                         {
-                            lock (machineStateLock)
+
+                            while (MachineState == MachineState.Ready)
                             {
-                                while (MachineState == MachineState.Ready)
+                                lock (machineStateLock)
                                 {
                                     SwitchLightGreen(true);
                                     Thread.Sleep(1000);
@@ -79,9 +83,9 @@
                         }
                         Task.Run(() =>
                         {
-                            lock (machineStateLock)
+                            while (MachineState == MachineState.Pause)
                             {
-                                while (MachineState == MachineState.Pause)
+                                lock (machineStateLock)
                                 {
                                     SwitchLightYellow(true);
                                     SwitchLightGreen(true);
@@ -102,10 +106,11 @@
                         }
                         Task.Run(() =>
                         {
-                            lock (machineStateLock)
+                            while (MachineState == MachineState.Resetting)
                             {
-                                while (MachineState == MachineState.Resetting)
+                                lock (machineStateLock)
                                 {
+
                                     SwitchLightYellow(true);
                                     Thread.Sleep(1000);
                                     SwitchLightYellow(false);
@@ -185,6 +190,16 @@
             }
         }
 
+        [ProcessMethod("MotionCardBase", "GotoReadyPosition", "杩愬姩鍒伴澶囦綅缃�", InvokeType.TestInvoke)]
+        public ProcessResponse GotoReadyPosition(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
+        {
+            MotionCardDefaultRun("GotoReadyPosition", ref opConfig, ref invokeDevice);
+
+            LogAsync(DateTime.Now, "杩愬姩鍒伴澶囦綅缃畬鎴�", "");
+
+            return new ProcessResponse(true);
+        }
+
         [ProcessMethod("MotionCardBase", "Reset", "绠�鍗曞浣嶆搷浣�", InvokeType.TestInvoke)]
         public ProcessResponse Reset(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
         {
@@ -206,9 +221,23 @@
             //    }
             //}
 
+            if (ResetTimer == null)
+            {
+                ResetTimer = new Timer(FullReset, null, -1, -1);
+            }
+
+            if (opConfig?.InputPara != null && opConfig.InputPara.Count > 0)
+            {
+                //澶у浣嶄俊鍙�
+                ResetTimer.Change(opConfig.InputPara[0] == 1 ? FULLRESETTIME * 1000 : -1, -1);
+
+                if (opConfig.InputPara[0] == 0)
+                    return new ProcessResponse(true);
+            }
+
             if (!IsAllowedWork)
             {
-                LogAsync(DateTime.Now, $"{(IsSafetyDoorTrigged ? "瀹夊叏闂�" : "")}{(IsSafetyBeamTrigged ? " 瀹夊叏鍏夌嚎" : "")}{(isEmergencyStopped ? " 鎬ュ仠鎸夐挳" : "")}瑙﹀彂涓紝澶嶄綅澶辫触", "");
+                LogAsync(DateTime.Now, $"{SafetyMsg}锛屽浣嶅け璐�", "");
                 return new ProcessResponse(false);
             }
 
@@ -224,16 +253,13 @@
                 MachineState = MachineState.Alarm;
             }
 
-            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 (opConfig.InputPara?.Count > 0)
+            //{
+            //    //澶у浣嶄俊鍙�
+            //    ResetTimer.Change(-1, opConfig.InputPara[0] == 1 ? FULLRESETTIME * 1000 : -1);
+            //}
 
             //if (invokeDevice is MotionCardBase motionCard)
             //{
@@ -299,6 +325,8 @@
             RaisedAlarm("");
             MachineState = MachineState.Ready;
 
+            GotoReadyPosition(null, null, null);
+
             return new ProcessResponse(true);
         }
 
@@ -330,9 +358,17 @@
                 throw new ProcessException("鏈幏鍙栨澘鍗¤澶�");
 
             bool? isToPause = null; //true 鏆傚仠 false 缁х画
-            if (opConfig.InputPara != null && opConfig.InputPara.Count > 0)
+            //if (opConfig.InputPara != null && opConfig.InputPara.Count > 0)
+            //{
+            //    isToPause = opConfig.InputPara[0] == 1;
+            //}
+            if (opConfig.InputPara[0] == 10)
             {
-                isToPause = opConfig.InputPara[0] == 1;
+                isToPause = false;
+            }
+            else if (opConfig.InputPara[0] == 11)
+            {
+                isToPause = true;
             }
 
             if (isToPause == null)
@@ -597,6 +633,10 @@
         {
             get => !(IsSafetyBeamTrigged || IsSafetyDoorTrigged || IsEmergencyStopped);
         }
+        string SafetyMsg
+        {
+            get => $"{(IsSafetyBeamTrigged ? "瀹夊叏鍏夊箷" : "")}{(IsSafetyDoorTrigged ? " 瀹夊叏闂�" : "")}{(IsEmergencyStopped ? " 鎬ュ仠鎸夐挳" : "")}瑙﹀彂涓�";
+        }
 
         #region 瀹夊叏闂� & 瀹夊叏鍏夌嚎
         bool isSafetyDoorTrigged = false;
@@ -633,6 +673,9 @@
         [ProcessMethod("", "SafetyBeamSignal", "瀹夊叏鍏夊箷淇″彿鐩戞帶锛屾甯窸N锛孫FF鏃舵姤璀�", InvokeType.TestInvoke)]
         public ProcessResponse SafetyBeamSignal(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
         {
+            if (MachineState != MachineState.Running && MachineState != MachineState.Alarm)
+                return new ProcessResponse(true);
+
             if (opConfig.InputPara == null || opConfig.InputPara.Count == 0)
                 throw new ProcessException("瀹夊叏鍏夊箷鐩戞帶鏈厤缃緭鍏ヤ俊鍙�");
 
@@ -674,7 +717,7 @@
             if (opConfig.InputPara == null || opConfig.InputPara.Count == 0)
                 throw new ProcessException("鎬ュ仠鎸夐挳鏈厤缃緭鍏ヤ俊鍙�");
 
-            IsEmergencyStopped = opConfig.InputPara[0] == 1;
+            IsEmergencyStopped = opConfig.InputPara[0] == 0;
 
             if (IsEmergencyStopped)
             {

--
Gitblit v1.8.0