Esempio n. 1
0
        public void SendCommand(JawMoveInfo toMoveInfo)
        {
            this.Commor.Write("D450", (ushort)toMoveInfo.Col);
            this.Commor.Write("D451", (ushort)toMoveInfo.Row);
            this.Commor.Write("D452", (ushort)toMoveInfo.Floor);

            var d400 = toMoveInfo.Type == TaskType.料 ? 1 : 2;

            this.Commor.Write("D400", (ushort)d400);
            LogHelper.WriteInfo(string.Format("------ 给PLC发送{4}信号 D400:{3},D450:{0},D451:{1},D452:{2}-----", toMoveInfo.Col, toMoveInfo.Row, toMoveInfo.Floor, d400, toMoveInfo.Type));
        }
Esempio n. 2
0
        public static void TaskExec(object obj)
        {
            if (!IsRunning)
            {
                return;
            }

            if (Arthur.App.Current.Option.RemainingMinutes <= 0)
            {
                return;
            }

            try
            {
                if (Current.Task.Status == Model.TaskStatus.完成)
                {
                    if (Current.App.TaskMode == ViewModel.TaskMode.自动任务)
                    {
                        foreach (var type in Factory.TaskFactory.TaskTypes)
                        {
                            if (type == TaskType.料 && Current.Option.Tray13_Id < 1)
                            {
                                continue;
                            }
                            else if (type == TaskType.料 && Current.Option.Tray21_Id > 0)
                            {
                                continue;
                            }

                            if (Current.Option.IsTaskReady)
                            {
                                var storages = Factory.TaskFactory.CanGetOrPutStorages(type);
                                if (storages.Count > 0)
                                {
                                    StorageViewModel storage = storages.OrderBy(o => o.GetPriority(type, Current.Option.TaskPriorityType)).First();

                                    Current.Task.StorageId  = storage.Id;
                                    Current.Task.Type       = type;
                                    Current.Task.StartTime  = DateTime.Now;
                                    Current.Task.ProcTrayId = type == Model.TaskType.料 ? Current.Option.Tray13_Id : storage.ProcTrayId;
                                    Current.Task.Status     = Model.TaskStatus.就绪;

                                    LogHelper.WriteInfo(string.Format("=== 生成自动任务 类型:{0},料仓:{1},流程托盘ID:{2},托盘条码:{3} ===",
                                                                      Current.Task.Type, storage.Name, Current.Task.ProcTrayId, GetObject.GetById <ProcTray>(Current.Task.ProcTrayId).Code));

                                    break;
                                }
                            }
                        }
                    }
                }
                else if (Current.Task.Status == Model.TaskStatus.就绪)
                {
                    var storage    = GetObject.GetById <StorageViewModel>(Current.Task.StorageId);
                    var toMoveInfo = JawMoveInfo.Create(Current.Task.Type, storage);

                    //若指令已经发给PLC
                    if (Current.Option.JawMoveInfo.Equals(toMoveInfo))
                    {
                        Current.Option.JawProcTrayId = Current.Task.ProcTrayId;
                        Current.Task.Status          = Model.TaskStatus.准备搬;
                        return;
                    }

                    Current.MainMachine.SendCommand(toMoveInfo);
                }
                else if (Current.Task.Status == Model.TaskStatus.准备搬)
                {
                    //若指令已经发给PLC
                    if (Current.Option.IsJawHasTray)
                    {
                        Current.Task.Status = Model.TaskStatus.搬运中;
                        return;
                    }
                }
                else if (Current.Task.Status == Model.TaskStatus.搬运中)
                {
                    if (Current.Option.IsTaskFinished)
                    {
                        var storage = GetObject.GetById <StorageViewModel>(Current.Task.StorageId);
                        if (Current.Task.Type == Model.TaskType.料)
                        {
                            storage.ProcTrayId = Current.Task.ProcTrayId;
                            storage.ProcTray.StartStillTime = DateTime.Now;
                        }
                        else
                        {
                            Current.Option.Tray21_Id = Current.Task.ProcTrayId;
                            if (storage.ProcTrayId > 0)
                            {
                                storage.ProcTray.StillTimeSpan = Convert.ToInt32((DateTime.Now - storage.ProcTray.StartStillTime).TotalMinutes);
                                storage.ProcTrayId             = 0;
                            }
                        }
                        Current.Option.JawProcTrayId = 0;
                        Current.Task.Status          = Model.TaskStatus.回位中;
                    }
                }
                else if (Current.Task.Status == Model.TaskStatus.回位中)
                {
                    if (Current.Option.IsTaskReady)
                    {
                        Current.Task.PreType = Current.Task.Type;
                        if (Current.Task.Type == Model.TaskType.料)
                        {
                            Current.Option.LastFeedTaskStorageColumn = GetObject.GetById <StorageViewModel>(Current.Task.StorageId).Column;
                        }
                        Current.Task.Status = Model.TaskStatus.完成;
                        new TaskManage().AddTaskLog();
                    }
                }
            }
            catch (Exception ex)
            {
                Running.StopRunAndShowMsg("执行任务出现异常:" + ex.Message);
                LogHelper.WriteError(ex);
            }
        }