Exemplo n.º 1
0
        public static bool Add(out string msg)
        {
            TaskLog taskLog = new TaskLog
            {
                FinishedTime  = DateTime.Now,
                FromStationId = Current.Task.FromStationId,
                ToStationId   = Current.Task.ToStationId,
                StartTime     = Current.Task.StartTime,
                TaskId        = Current.Task.TaskId,
                ClampStatus   = Current.Task.FromClampStatus,
                TaskMode      = Current.TaskMode
            };

            return(Add(new List <TaskLog>()
            {
                taskLog
            }, out msg));
        }
Exemplo n.º 2
0
        public static void Run()
        {
            lock (Current.Task)
            {
                try
                {
                    string msg = string.Empty;
                    if (Current.TaskMode == TaskMode.自动任务 && Current.RGV.IsReady)
                    {
                        if (Current.Task.Status == TaskStatus.完成)
                        {
                            if (CurrentTask.ToSwitchManuTaskMode)
                            {
                                Current.Task.StartTime       = TengDa.Common.DefaultTime;
                                Current.Task.TaskId          = -1;
                                Current.Task.FromStationId   = -1;
                                Current.Task.ToStationId     = -1;
                                Current.Task.FromClampStatus = ClampStatus.未知;

                                Current.TaskMode = TaskMode.手动任务;
                                CurrentTask.ToSwitchManuTaskMode = false;
                                return;
                            }

                            ///任务遍历
                            foreach (Task task in Task.CanGetPutTaskList.Where(t => t.IsEnable))
                            {
                                List <Station> fromStations = Station.CanGetPutStationList
                                                              .Where(s => s.ClampOri == task.ClampOri &&
                                                                     s.GetPutType == task.FromType && s.ClampStatus == task.FromClampStatus &&
                                                                     s.Status == StationStatus.可取 &&
                                                                     s.SampleStatus == task.FromSampleStatus &&
                                                                     s.SampleInfo == task.FromSampleInfo)
                                                              .OrderBy(s => s.GetPutTime)
                                                              .OrderBy(s => s.GetPriority(task))
                                                              .ToList();
                                List <Station> toStations = Station.CanGetPutStationList
                                                            .Where(s => s.ClampOri == task.ClampOri &&
                                                                   s.GetPutType == task.ToType && s.ClampStatus == task.ToClampStatus &&
                                                                   s.Status == StationStatus.可放 &&
                                                                   s.SampleStatus == task.ToSampleStatus)
                                                            .OrderBy(s => s.GetPutTime)
                                                            .OrderBy(s => s.GetPriority(task))
                                                            .ToList();

                                ////入炉前逻辑
                                ////取样的空位不能入其他夹具
                                //if (task.ToType == GetPutType.烤箱)
                                //{
                                //    toStations = toStations.Where(s => s.GetLabStation().FloorStatus != FloorStatus.待出).ToList();
                                //}

                                ////水分NG烤箱空位要回炉,无法上料
                                //if (task.FromType == GetPutType.上料机 && task.ToType == GetPutType.烤箱 && task.FromClampStatus == ClampStatus.满夹具)
                                //{
                                //    toStations = toStations.Where(s => s.GetLabStation().SampleStatus != SampleStatus.水分NG && s.GetLabStation().SampleStatus != SampleStatus.水分OK).ToList();
                                //}

                                ////测试水分出烤箱前逻辑
                                //if (task.FromType == GetPutType.烤箱 && task.ToType == GetPutType.下料机 && task.FromClampStatus == ClampStatus.满夹具)
                                //{
                                //    if (task.FromSampleInfo == SampleInfo.有样品 && task.FromSampleStatus == SampleStatus.待结果)
                                //    {
                                //        toStations = toStations.Where(s => s.GetBlanker().CanTestWatContent).ToList();
                                //    }
                                //}

                                ////下料取完水分返回烤箱逻辑
                                //if (task.FromType == GetPutType.下料机 && task.ToType == GetPutType.烤箱 && task.FromClampStatus == ClampStatus.满夹具)
                                //{
                                //    var fromStationsTmp = new List<Station>();
                                //    var toStationsTmp = new List<Station>();

                                //    var isAdded = false;
                                //    foreach (var fromStation in fromStations)
                                //    {
                                //        foreach (var toStation in toStations)
                                //        {
                                //            if (fromStation.FromStationId == toStation.Id && fromStation.SampleInfo == task.FromSampleInfo)
                                //            {
                                //                if (!isAdded)
                                //                {
                                //                    fromStationsTmp.Add(fromStation);
                                //                    toStationsTmp.Add(toStation);
                                //                    isAdded = true;
                                //                }
                                //            }
                                //        }
                                //    }
                                //    fromStations = fromStationsTmp;
                                //    toStations = toStationsTmp;
                                //}


                                if (fromStations.Count > 0 && toStations.Count > 0)
                                {
                                    if (task.FromClampStatus == ClampStatus.满夹具 && task.FromType == GetPutType.烤箱)
                                    {
                                        fromStations = fromStations.OrderBy(s => s.GetFillClampPriority).ToList();
                                    }
                                    if (task.FromClampStatus == ClampStatus.空夹具 && task.FromType == GetPutType.烤箱)
                                    {
                                        fromStations = fromStations.OrderBy(s => s.GetEmptyClampPriority).ToList();
                                    }
                                    if (task.FromClampStatus == ClampStatus.满夹具 && task.ToType == GetPutType.烤箱)
                                    {
                                        toStations = toStations.OrderBy(s => s.PutFillClampPriority).ToList();
                                    }
                                    if (task.FromClampStatus == ClampStatus.空夹具 && task.ToType == GetPutType.烤箱)
                                    {
                                        toStations = toStations.OrderBy(s => s.PutEmptyClampPriority).ToList();
                                    }

                                    Station fromStation = fromStations.First();
                                    Station toStation   = toStations.First();
                                    Current.Task.StartTime       = DateTime.Now;
                                    Current.Task.TaskId          = task.Id;
                                    Current.Task.FromStationId   = fromStation.Id;
                                    Current.Task.ClampId         = fromStation.ClampId;
                                    Current.Task.ToStationId     = toStation.Id;
                                    Current.Task.FromClampStatus = fromStation.ClampStatus;
                                    Current.Task.PreCycleOrder   = task.CycleOrder;
                                    Current.Task.Status          = TaskStatus.就绪;
                                    break;
                                }
                                else
                                {
                                    Current.Task.StartTime     = TengDa.Common.DefaultTime;
                                    Current.Task.TaskId        = -1;
                                    Current.Task.FromStationId = -1;
                                    Current.Task.ToStationId   = -1;
                                    //Current.Task.ClampId = -1;
                                    //防止任务复位导致ClampId丢失
                                    Current.Task.FromClampStatus = ClampStatus.未知;
                                    Current.Task.Status          = TaskStatus.完成;
                                }
                            }
                        }

                        else if (Current.Task.FromStationId > 0 && Current.Task.ToStationId > 0)
                        {
                            if (Current.Task.Status == TaskStatus.就绪)
                            {
                                if (Current.Task.FromStation.DoorStatus != DoorStatus.打开)
                                {
                                    Current.Task.FromStation.OpenDoor();
                                }
                                if (Current.Task.ToStation.DoorStatus != DoorStatus.打开)
                                {
                                    Current.Task.ToStation.OpenDoor();
                                }

                                if (Current.Task.FromStation.DoorStatus == DoorStatus.打开)
                                {
                                    Current.Task.Status = TaskStatus.可取;
                                }
                            }
                            else if (Current.Task.Status == TaskStatus.可取)
                            {
                                if (Current.RGV.Get(Current.Task.FromStation, Current.Task.ToStation))
                                {
                                    if (Current.RGV.Enter(out msg))
                                    {
                                        Current.Task.Status = TaskStatus.正取;
                                    }
                                }
                            }
                            else if (Current.Task.Status == TaskStatus.正取)
                            {
                                if (Current.RGV.IsTaskFinished && Current.RGV.IsForkAtOriginalPoint)
                                {
                                    Current.RGV.ClampStatus = Current.Task.FromClampStatus;
                                    Current.RGV.ClampId     = Current.Task.ClampId;
                                    Current.Task.Status     = TaskStatus.取完;

                                    if (Current.Task.FromStation.GetPutType == GetPutType.料机)
                                    {
                                        //上料计数逻辑
                                        Current.Yields.First(y => y.ClampOri == ClampOri.A).FeedingOK++;
                                        Current.Feeder.GetFinished();
                                    }

                                    if (Current.Task.FromStation.GetPutType == GetPutType.烤箱)
                                    {
                                        Current.Task.FromStation.Clamp.OutOvenTime = DateTime.Now;
                                        Current.Task.FromStation.Clamp.IsFinished  = true;
                                    }

                                    Current.Task.FromStation.ClampId = -1;
                                }
                            }
                            else if (Current.Task.Status == TaskStatus.取完)
                            {
                                if (Current.Task.ToStation.DoorStatus != DoorStatus.打开)
                                {
                                    Current.Task.ToStation.OpenDoor();
                                }

                                if (Current.Task.ToStation.DoorStatus == DoorStatus.打开)
                                {
                                    Current.Task.Status = TaskStatus.可放;
                                }
                            }
                            else if (Current.Task.Status == TaskStatus.可放)
                            {
                                if (Current.RGV.Put(Current.Task.FromStation, Current.Task.ToStation))
                                {
                                    if (Current.RGV.Enter(out msg))
                                    {
                                        Current.Task.Status = TaskStatus.正放;
                                    }
                                }
                            }
                            else if (Current.Task.Status == TaskStatus.正放)
                            {
                                if (Current.RGV.IsTaskFinished && Current.RGV.IsForkAtOriginalPoint)
                                {
                                    Current.Task.ToStation.ClampStatus   = Current.Task.FromClampStatus;
                                    Current.Task.ToStation.ClampId       = Current.Task.ClampId;
                                    Current.Task.ToStation.FromStationId = Current.Task.FromStationId;
                                    Current.Task.FromStation.ClampStatus = ClampStatus.无夹具;
                                    Current.RGV.ClampStatus = ClampStatus.无夹具;
                                    Current.RGV.ClampId     = -1;
                                    if (!TaskLog.Add(out msg))//记录
                                    {
                                        Error.Alert("保存搬运记录失败:" + msg);
                                    }

                                    if (Current.Task.ToStation.GetPutType == GetPutType.料机)
                                    {
                                        //下料计数逻辑
                                        Current.Yields.First(y => y.ClampOri == ClampOri.A).BlankingOK++;
                                        Current.Feeder.PutFinished();
                                    }

                                    if (Current.Task.FromStation.GetPutType == GetPutType.料机 && Current.Task.ToStation.GetPutType == GetPutType.烤箱)
                                    {
                                        Current.option.LastInOvenStationId = Current.Task.ToStation.Id.ToString();
                                    }

                                    Current.Task.Status = TaskStatus.完成;
                                }
                            }
                        }
                    }
                    else if (Current.TaskMode == TaskMode.手动任务)
                    {
                        if (Current.Task.Status == TaskStatus.完成)
                        {
                            Current.Task.StartTime     = TengDa.Common.DefaultTime;
                            Current.Task.TaskId        = -1;
                            Current.Task.FromStationId = -1;
                            //Current.Task.ClampId = -1;
                            //防止任务复位导致ClampId丢失
                            Current.Task.ToStationId     = -1;
                            Current.Task.FromClampStatus = ClampStatus.未知;
                            Current.Task.Status          = TaskStatus.完成;

                            if (Current.Task.NextFromStationId > 0 && Current.Task.NextToStationId > 0)
                            {
                                Current.Task.FromStationId     = Current.Task.NextFromStationId;
                                Current.Task.NextFromStationId = -1;
                                Current.Task.ToStationId       = Current.Task.NextToStationId;
                                Current.Task.NextToStationId   = -1;
                                Current.Task.FromClampStatus   = Current.Task.FromStation.ClampStatus;
                                Current.Task.ClampId           = Current.Task.FromStation.ClampId;
                                Current.Task.Status            = TaskStatus.就绪;
                            }
                        }
                        else if (Current.Task.Status == TaskStatus.就绪 && Current.Task.FromStation != null)
                        {
                            if (Current.Task.FromStation.DoorStatus != DoorStatus.打开)
                            {
                                Tip.Alert(Current.Task.FromStation.Name + "门未打开!");
                            }

                            if (Current.Task.FromStation.DoorStatus == DoorStatus.打开)
                            {
                                Current.Task.Status = TaskStatus.可取;
                            }
                        }
                        else if (Current.Task.Status == TaskStatus.可取 && Current.Task.FromStation != null)
                        {
                            if (Current.RGV.Get(Current.Task.FromStation, Current.Task.ToStation))
                            {
                                if (Current.RGV.Enter(out msg))
                                {
                                    Current.Task.Status = TaskStatus.正取;
                                }
                            }
                        }
                        else if (Current.Task.Status == TaskStatus.正取 && Current.Task.FromStation != null)
                        {
                            if (Current.RGV.IsTaskFinished && Current.RGV.IsForkAtOriginalPoint)
                            {
                                Current.RGV.ClampStatus = Current.Task.FromClampStatus;
                                Current.RGV.ClampId     = Current.Task.ClampId;
                                Current.Task.Status     = TaskStatus.取完;

                                if (Current.Task.FromStation.GetPutType == GetPutType.料机)
                                {
                                    //上料计数逻辑
                                    Current.Yields.First(y => y.ClampOri == ClampOri.A).FeedingOK++;
                                    Current.Feeder.GetFinished();
                                }

                                if (Current.Task.FromStation.GetPutType == GetPutType.烤箱)
                                {
                                    Current.Task.FromStation.Clamp.OutOvenTime = DateTime.Now;
                                    Current.Task.FromStation.Clamp.IsFinished  = true;
                                }

                                Current.Task.FromStation.ClampId = -1;
                            }
                        }
                        else if (Current.Task.Status == TaskStatus.取完)
                        {
                            if (Current.Task.NextToStationId > 0)
                            {
                                Current.Task.ToStationId     = Current.Task.NextToStationId;
                                Current.Task.NextToStationId = -1;
                            }
                            if (Current.Task.ToStation != null)
                            {
                                if (Current.Task.ToStation.DoorStatus != DoorStatus.打开)
                                {
                                    Tip.Alert(Current.Task.ToStation.Name + "门未打开!");
                                }
                                if (Current.Task.ToStation.DoorStatus == DoorStatus.打开)
                                {
                                    Current.Task.Status = TaskStatus.可放;
                                }
                            }
                        }
                        else if (Current.Task.Status == TaskStatus.可放 && Current.Task.ToStation != null)
                        {
                            if (Current.RGV.Put(Current.Task.FromStation, Current.Task.ToStation))
                            {
                                if (Current.RGV.Enter(out msg))
                                {
                                    Current.Task.Status = TaskStatus.正放;
                                }
                            }
                        }
                        else if (Current.Task.Status == TaskStatus.正放 && Current.Task.ToStation != null)
                        {
                            if (Current.RGV.IsTaskFinished && Current.RGV.IsForkAtOriginalPoint)
                            {
                                Current.Task.ToStation.ClampStatus   = Current.Task.FromClampStatus;
                                Current.Task.ToStation.ClampId       = Current.Task.ClampId;
                                Current.Task.ToStation.FromStationId = Current.Task.FromStationId;
                                Current.Task.FromStation.ClampStatus = ClampStatus.无夹具;
                                Current.RGV.ClampStatus = ClampStatus.无夹具;
                                Current.RGV.ClampId     = -1;
                                if (!TaskLog.Add(out msg))//记录
                                {
                                    Error.Alert("保存搬运记录失败:" + msg);
                                }

                                if (Current.Task.ToStation.GetPutType == GetPutType.料机)
                                {
                                    //下料计数逻辑
                                    Current.Yields.First(y => y.ClampOri == ClampOri.A).BlankingOK++;
                                    Current.Feeder.PutFinished();
                                }

                                if (Current.Task.FromStation.GetPutType == GetPutType.料机 && Current.Task.ToStation.GetPutType == GetPutType.烤箱)
                                {
                                    Current.option.LastInOvenStationId = Current.Task.ToStation.Id.ToString();
                                }

                                Current.Task.Status = TaskStatus.完成;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Error.Alert(ex);
                }
            }
        }