From ff18fa3c007656bd37cad91fac9a9cb03f4070b8 Mon Sep 17 00:00:00 2001
From: patrick <patrick.xu@broconcentric.com>
Date: 星期日, 20 十月 2019 14:13:16 +0800
Subject: [PATCH] 1. 修改SeerAGV驱动通信代码 2. 修改机器人通信部分代码 3. 取消原有流程任务队列模式,使用即时方法调用。

---
 src/A032.Process/AGVBindUnit.cs |  137 +++++++++++++++++++++++++++++----------------
 1 files changed, 87 insertions(+), 50 deletions(-)

diff --git a/src/A032.Process/AGVBindUnit.cs b/src/A032.Process/AGVBindUnit.cs
index 460c4f4..507d8c8 100644
--- a/src/A032.Process/AGVBindUnit.cs
+++ b/src/A032.Process/AGVBindUnit.cs
@@ -33,7 +33,7 @@
     {
         public TaskAvailableLevel Level { get; set; } = TaskAvailableLevel.Robot;
 
-        public Func<IOperationConfig, IDevice, ProcessResponse> MethodFunc { get; set; }
+        public string MethodName { get; set; }
 
         public IOperationConfig OpConfig { get; set; }
 
@@ -43,10 +43,10 @@
 
         public AGVTaskModel() { }
 
-        public AGVTaskModel(TaskAvailableLevel level, Func<IOperationConfig, IDevice, ProcessResponse> methodFunc, IOperationConfig opConfig = null, IDevice device = null)
+        public AGVTaskModel(TaskAvailableLevel level, string methodName, IOperationConfig opConfig = null, IDevice device = null)
         {
             Level = level;
-            MethodFunc = methodFunc;
+            MethodName = methodName;
             OpConfig = opConfig ?? new OperationConfigBase();
             Device = device;
         }
@@ -57,7 +57,7 @@
         #region 鍙紪杈戦」鐩�
         [Category("璁惧缁戝畾")]
         [Description("缁戝畾Id")]
-        [ReadOnly(true)]
+        [Browsable(false)]
         public string Id { get; set; } = Guid.NewGuid().ToString();
 
         [Category("璁惧缁戝畾")]
@@ -92,7 +92,7 @@
 
         [Browsable(false)]
         [JsonIgnore]
-        public Action<AGVBindUnit> OnMethodInvoke { get; set; }
+        public Action<AGVTaskModel> OnMethodInvoke { get; set; }
 
         public string AGVDest { get; set; } = "";
 
@@ -105,7 +105,7 @@
             set
             {
                 agvStatus = value;
-                InvokeTaskCheck();
+                //InvokeTaskCheck();
             }
         }
 
@@ -118,7 +118,7 @@
             set
             {
                 robotStatus = value;
-                InvokeTaskCheck();
+                //InvokeTaskCheck();
             }
         }
 
@@ -153,9 +153,10 @@
         [Browsable(false)]
         [JsonIgnore]
         public CameraBase Camera { get; set; } = null;
-        [Browsable(false)]
-        [JsonIgnore]
-        public ObservableCollection<AGVTaskModel> TaskList { get; set; } = new ObservableCollection<AGVTaskModel>();
+
+        //[Browsable(false)]
+        //[JsonIgnore]
+        //public ObservableCollection<AGVTaskModel> TaskList { get; set; } = new ObservableCollection<AGVTaskModel>();
 
         [Browsable(false)]
         [JsonIgnore]
@@ -175,56 +176,92 @@
 
         [Browsable(false)]
         [JsonIgnore]
+        public bool IsFullTrayTaskAssigned { get; set; }
+
+        [Browsable(false)]
+        [JsonIgnore]
+        public bool IsEmptyTrayTaskAssigned { get; set; }
+
+        [Browsable(false)]
+        [JsonIgnore]
         public ManualResetEvent RobotIOHandle { get; set; } = new ManualResetEvent(false);
 
         public AGVBindUnit()
         {
-            TaskList.CollectionChanged += TaskList_CollectionChanged;
+            //TaskList.CollectionChanged += TaskList_CollectionChanged;
         }
 
-        private void TaskList_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
-        {
-            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
-            {
-                InvokeTaskCheck();
-            }
-        }
+        //private void TaskList_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
+        //{
+        //    if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
+        //    {
+        //        InvokeTaskCheck();
+        //    }
+        //}
 
-        private void InvokeTaskCheck()
-        {
-            for (int i = 0; i < TaskList.Count; i++)
-            {
-                var task = TaskList[i];
+        //private void InvokeTaskCheck()
+        //{
+        //    lock (taskLock)
+        //    {
+        //        for (int i = 0; i < TaskList.Count; i++)
+        //        {
+        //            var task = TaskList[i];
 
-                bool isAgvOK = false;
-                bool isRobotOK = false;
+        //            bool isAgvOK = false;
+        //            bool isRobotOK = false;
 
-                if ((task.Level & TaskAvailableLevel.AGV) == TaskAvailableLevel.AGV)
-                {
-                    isAgvOK = AGVStatus == TaskStatus.Available;
-                }
-                else
-                {
-                    isAgvOK = true;
-                }
+        //            if ((task.Level & TaskAvailableLevel.AGV) == TaskAvailableLevel.AGV)
+        //            {
+        //                isAgvOK = AGVStatus == TaskStatus.Available;
+        //            }
+        //            else
+        //            {
+        //                isAgvOK = true;
+        //            }
 
-                if ((task.Level & TaskAvailableLevel.Robot) == TaskAvailableLevel.Robot)
-                {
-                    isRobotOK = RobotStatus == TaskStatus.Available;
-                }
-                else
-                {
-                    isRobotOK = true;
-                }
+        //            if ((task.Level & TaskAvailableLevel.Robot) == TaskAvailableLevel.Robot)
+        //            {
+        //                isRobotOK = RobotStatus == TaskStatus.Available;
+        //            }
+        //            else
+        //            {
+        //                isRobotOK = true;
+        //            }
 
-                if (isRobotOK && isAgvOK)
-                {
-                    OnMethodInvoke?.Invoke(this);
-                    TaskList.RemoveAt(i);
-                    break;
-                }
-            }
-        }
+        //            if (isRobotOK && isAgvOK)
+        //            {
+        //                OnMethodInvoke?.Invoke(TaskList[i]);
+        //                TaskList.RemoveAt(i);
+        //                break;
+        //            }
+        //        }
+        //    }
+        //}
+
+        //object taskLock = new object();
+        //public void AddTask(AGVTaskModel task)
+        //{
+        //    lock (taskLock)
+        //    {
+        //        TaskList.Add(task);
+        //    }
+        //}
+
+        //public void ClearTask()
+        //{
+        //    lock (taskLock)
+        //    {
+        //        TaskList.Clear();
+        //    }
+        //}
+
+        //public AGVTaskModel GetTask(int index)
+        //{
+        //    lock (taskLock)
+        //    {
+        //        return TaskList[index];
+        //    }
+        //}
     }
 
     public class AGVDeviceConverter : ComboBoxItemTypeConvert
@@ -288,7 +325,7 @@
                 config.PLCConfigCollection.ForEach(plc =>
                 {
                     _hash[plc.ID] = plc.Name;
-                });               
+                });
             }
         }
     }

--
Gitblit v1.8.0