예제 #1
0
파일: Task.cs 프로젝트: jtzhang163/TengDa
        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));
        }
예제 #2
0
파일: Task.cs 프로젝트: jtzhang163/TengDa
        public static void Run()
        {
            string msg = string.Empty;

            if (Current.TaskMode == TaskMode.自动任务)
            {
                ////烤箱只有一个空位时,不要搬运空夹具至烤箱

                //if (Task.TaskList.Where(t => t.FromClampStatus == ClampStatus.空夹具 && t.ToType == GetPutType.烤箱).ToList().Count(t => t.IsEnable) > 0)
                //{

                //}

                //List<Station> stations = Station.StationList.Where(s => s.IsAlive && s.GetPutType == GetPutType.烤箱 && s.FloorStatus == FloorStatus.无盘).ToList();
                //Task.TaskList.Where(t => t.FromClampStatus == ClampStatus.空夹具 && t.ToType == GetPutType.烤箱).ToList().
                //    ForEach(t => t.IsEnable = stations.Count > 1);



                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)
                                                      .OrderBy(s => s.Priority)
                                                      .OrderBy(s => s.GetPutTime)
                                                      .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.Priority)
                                                    .OrderBy(s => s.GetPutTime)
                                                    .ToList();

                        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.Where(s => s.CanPutEmptyClamp).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.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.FromClampStatus = ClampStatus.未知;
                            Current.Task.Status          = TaskStatus.完成;
                        }
                    }
                }

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

                        if (Current.Task.FromStation.DoorStatus == DoorStatus.打开)
                        {
                            Current.Task.Status = TaskStatus.可取;
                        }
                    }
                    else if (Current.Task.Status == TaskStatus.可取 && Current.Task.FromStation != null)
                    {
                        byte pos = byte.Parse(Current.Task.FromStation.RobotValues.Split(',')[0]);
                        if (Current.Robot.IsReadyGet)
                        {
                            if (Current.Robot.GetOrPut(pos))
                            {
                            }
                        }

                        if (Current.Robot.IsGettingOrPutting)
                        {
                            Current.Task.Status = TaskStatus.正取;
                        }
                    }
                    else if (Current.Task.Status == TaskStatus.正取 && Current.Task.FromStation != null)
                    {
                        //提前把放盘位门打开
                        if (Current.Task.ToStation.DoorStatus != DoorStatus.打开 && Current.Task.ToStation != null && Current.Task.ToStation.GetPutType == GetPutType.烤箱)
                        {
                            Current.Task.ToStation.OpenDoor();
                        }

                        if (Current.Robot.ClampStatus != ClampStatus.无夹具)
                        {
                            Current.Robot.ClampStatus            = Current.Task.FromClampStatus;
                            Current.Task.FromStation.ClampStatus = ClampStatus.无夹具;
                            if (Current.Task.FromStation.ClampId > 0)
                            {
                                Current.Robot.ClampId = Current.Task.FromStation.ClampId;
                            }
                        }

                        if (!Current.Robot.IsGettingOrPutting)
                        {
                            Current.Task.Status = TaskStatus.取完;
                        }
                    }
                    else if (Current.Task.Status == TaskStatus.取完 && Current.Task.ToStation != null)
                    {
                        if (Current.Task.ToStation.DoorStatus != DoorStatus.打开)
                        {
                            Current.Task.ToStation.OpenDoor();
                        }
                        else
                        {
                            Current.Task.Status = TaskStatus.可放;
                        }
                    }
                    else if (Current.Task.Status == TaskStatus.可放 && Current.Task.ToStation != null)
                    {
                        byte pos = byte.Parse(Current.Task.ToStation.RobotValues.Split(',')[1]);

                        if (Current.Robot.IsReadyPut)
                        {
                            if (Current.Robot.GetOrPut(pos))
                            {
                            }
                        }

                        if (Current.Robot.IsGettingOrPutting)
                        {
                            Current.Task.Status = TaskStatus.正放;
                        }
                    }
                    else if (Current.Task.Status == TaskStatus.正放 && Current.Task.ToStation != null)
                    {
                        if (Current.Robot.ClampStatus == ClampStatus.无夹具)
                        {
                            Current.Task.ToStation.ClampStatus   = Current.Task.FromClampStatus;
                            Current.Task.ToStation.FromStationId = Current.Task.FromStationId;

                            if (Current.Task.ToStation.ClampId < 1 && Current.Task.ToStation.GetPutType == GetPutType.料机 && Current.Task.FromClampStatus == ClampStatus.空夹具)
                            {
                                int oldClampId = -1;
                                if (Current.Task.FromStation != null)
                                {
                                    oldClampId = Current.Task.FromStation.ClampId;
                                }
                                if (oldClampId < 1)
                                {
                                    oldClampId = Current.Robot.ClampId;
                                }

                                int clampId = Clamp.Add(new Clamp(oldClampId).Code, out msg);
                                if (clampId > 0)
                                {
                                    Current.Task.ToStation.ClampId = clampId;
                                }
                                else
                                {
                                    LogHelper.WriteError(msg);
                                }
                            }
                            else
                            {
                                if (Current.Task.FromStation != null && Current.Task.FromStation.ClampId > 0)
                                {
                                    Current.Task.ToStation.ClampId = Current.Task.FromStation.ClampId;
                                }
                                else if (Current.Robot.ClampId > 0)
                                {
                                    Current.Task.ToStation.ClampId = Current.Robot.ClampId;
                                }
                            }
                            Current.Robot.ClampId = -1;
                            if (Current.Task.FromStation != null)
                            {
                                Current.Task.FromStation.ClampId = -1;
                            }
                        }

                        if (!Current.Robot.IsGettingOrPutting)
                        {
                            if (!TaskLog.Add(out msg))//记录
                            {
                                Error.Alert("保存搬运记录失败:" + msg);
                            }
                            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.ToStationId     = -1;
                    Current.Task.FromClampStatus = ClampStatus.未知;
                    Current.Task.Status          = TaskStatus.完成;

                    if (Current.Task.NextFromStationId > 0)
                    {
                        Current.Task.FromStationId     = Current.Task.NextFromStationId;
                        Current.Task.NextFromStationId = -1;
                        Current.Task.FromClampStatus   = Current.Task.FromStation.ClampStatus;
                        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)
                {
                    byte pos = byte.Parse(Current.Task.FromStation.RobotValues.Split(',')[0]);
                    if (Current.Robot.IsReadyGet)
                    {
                        if (Current.Robot.GetOrPut(pos))
                        {
                        }
                    }

                    if (Current.Robot.IsGettingOrPutting)
                    {
                        Current.Task.Status = TaskStatus.正取;
                    }
                }
                else if (Current.Task.Status == TaskStatus.正取 && Current.Task.FromStation != null)
                {
                    if (Current.Robot.ClampStatus != ClampStatus.无夹具)
                    {
                        Current.Robot.ClampStatus            = Current.Task.FromClampStatus;
                        Current.Task.FromStation.ClampStatus = ClampStatus.无夹具;
                        if (Current.Task.FromStation.ClampId > 0)
                        {
                            Current.Robot.ClampId = Current.Task.FromStation.ClampId;
                        }
                    }

                    if (!Current.Robot.IsGettingOrPutting)
                    {
                        Current.Task.Status = TaskStatus.取完;
                    }
                }
                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)
                {
                    byte pos = byte.Parse(Current.Task.ToStation.RobotValues.Split(',')[1]);

                    if (Current.Robot.IsReadyPut)
                    {
                        if (Current.Robot.GetOrPut(pos))
                        {
                        }
                    }

                    if (Current.Robot.IsGettingOrPutting)
                    {
                        Current.Task.Status = TaskStatus.正放;
                    }
                }
                else if (Current.Task.Status == TaskStatus.正放 && Current.Task.ToStation != null)
                {
                    if (Current.Robot.ClampStatus == ClampStatus.无夹具)
                    {
                        Current.Task.ToStation.ClampStatus   = Current.Task.FromClampStatus;
                        Current.Task.ToStation.FromStationId = Current.Task.FromStationId;

                        if (Current.Task.ToStation.ClampId < 1 && Current.Task.ToStation.GetPutType == GetPutType.料机 && Current.Task.FromClampStatus == ClampStatus.空夹具)
                        {
                            int oldClampId = -1;
                            if (Current.Task.FromStation != null)
                            {
                                oldClampId = Current.Task.FromStation.ClampId;
                            }
                            if (oldClampId < 1)
                            {
                                oldClampId = Current.Robot.ClampId;
                            }

                            int clampId = Clamp.Add(new Clamp(oldClampId).Code, out msg);
                            if (clampId > 0)
                            {
                                Current.Task.ToStation.ClampId = clampId;
                            }
                            else
                            {
                                LogHelper.WriteError(msg);
                            }
                        }
                        else
                        {
                            if (Current.Task.FromStation != null && Current.Task.FromStation.ClampId > 0)
                            {
                                Current.Task.ToStation.ClampId = Current.Task.FromStation.ClampId;
                            }
                            else if (Current.Robot.ClampId > 0)
                            {
                                Current.Task.ToStation.ClampId = Current.Robot.ClampId;
                            }
                        }
                        Current.Robot.ClampId = -1;
                        if (Current.Task.FromStation != null)
                        {
                            Current.Task.FromStation.ClampId = -1;
                        }
                    }

                    if (!Current.Robot.IsGettingOrPutting)
                    {
                        if (!TaskLog.Add(out msg))//记录
                        {
                            Error.Alert("保存搬运记录失败:" + msg);
                        }
                        Current.Task.Status = TaskStatus.完成;
                    }
                }
            }
        }