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;
                });
                });
            }
        }
    }