From 6428fad15dbe79e30a48ffc9aabe31e03a45426c Mon Sep 17 00:00:00 2001
From: patrick <patrick.xu@broconcentric.com>
Date: 星期四, 05 十二月 2019 12:50:13 +0800
Subject: [PATCH] 1. 添加部分log信息 2. 修改部分机器人动作流程 3. 开放OperationConfig的InputData参数

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

diff --git a/src/A032.Process/AGVBindUnit.cs b/src/A032.Process/AGVBindUnit.cs
index 460c4f4..5d843f3 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,127 @@
 
         [Browsable(false)]
         [JsonIgnore]
+        public bool IsFullTrayTaskAssigned { get; set; }
+
+        [Browsable(false)]
+        [JsonIgnore]
+        public bool IsEmptyTrayTaskAssigned { get; set; }
+
+        //[Browsable(false)]
+        //[JsonIgnore]
+        //public ManualResetEvent FullTrayFullHandle { get; set; } = new ManualResetEvent(false);
+
+        //[Browsable(false)]
+        //[JsonIgnore]
+        //public ManualResetEvent FullTrayEmptyHandle { get; set; } = new ManualResetEvent(false);
+
         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)
+        object agvStatusLock = new object();
+        public bool SetAGVStatus(TaskStatus status)
         {
-            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
+            lock (agvStatusLock)
             {
-                InvokeTaskCheck();
+                switch (status)
+                {
+                    case TaskStatus.Available:
+                        break;
+                    case TaskStatus.Running:
+                        if (AGVStatus == TaskStatus.Available)
+                        {
+                            AGVStatus = status;
+                            return true;
+                        }
+                        else
+                        {
+                            return false;
+                        }
+                    case TaskStatus.Warning:
+                        break;
+                    default:
+                        break;
+                }
+
+                AGVStatus = status;
+                return true;
             }
         }
+        //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
@@ -251,9 +323,9 @@
             {
                 ProcessConfig config = scope.Resolve<ProcessConfig>();
 
-                config.RobotConfigCollection.ForEach(plc =>
+                config.RobotConfigCollection.ForEach(robot =>
                 {
-                    _hash[plc.ID] = plc.Name;
+                    _hash[robot.ID] = robot.Name;
                 });
             }
         }
@@ -267,9 +339,9 @@
             {
                 ProcessConfig config = scope.Resolve<ProcessConfig>();
 
-                config.CameraConfigCollection.ForEach(plc =>
+                config.CameraConfigCollection.ForEach(camera =>
                 {
-                    _hash[plc.ID] = plc.Name;
+                    _hash[camera.ID] = camera.Name;
                 });
             }
         }
@@ -288,7 +360,7 @@
                 config.PLCConfigCollection.ForEach(plc =>
                 {
                     _hash[plc.ID] = plc.Name;
-                });               
+                });
             }
         }
     }

--
Gitblit v1.8.0