Example #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));
        }
Example #2
0
        public static void Run()
        {
            if (Current.TaskMode == TaskMode.自动任务)
            {
                //烤箱只有一个空位时,不要搬运空夹具至烤箱
                List <ClampOri> ClampOris = new List <ClampOri> {
                    ClampOri.A, ClampOri.B
                };
                foreach (ClampOri clampOri in ClampOris)
                {
                    List <Station> stations = Station.StationList.Where(s =>
                                                                        s.ClampOri == clampOri &&
                                                                        s.IsAlive &&
                                                                        s.GetPutType == GetPutType.烤箱 &&
                                                                        s.FloorStatus == FloorStatus.无盘).ToList();

                    Task.TaskList.Where(t => t.FromClampStatus == ClampStatus.空夹具 && t.ToType == GetPutType.烤箱 && t.ClampOri == clampOri).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.可取 &&
                                                             task.IsSuitSampleStatus(s))
                                                      .OrderBy(s => s.Distance(Current.rgv))
                                                      .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.可放 &&
                                                           task.IsSuitSampleStatus(s))
                                                    .OrderBy(s => s.Priority)
                                                    //.OrderBy(s => s.Distance(Current.rgv))
                                                    .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.就绪)
                    {
                        int d3410 = int.Parse(Current.Task.FromStation.RgvValues.Split(',')[0]);
                        int d3411 = int.Parse(Current.Task.FromStation.RgvValues.Split(',')[1]);
                        if (Current.rgv.IsReadyGet)
                        {
                            if (Current.rgv.Move(d3410, d3411, isGet: true))
                            {
                                Current.Task.Status = TaskStatus.可取;
                            }
                        }
                    }
                    else if (Current.Task.Status == TaskStatus.可取 && Current.Task.FromStation != null)
                    {
                        if (Current.Task.FromStation.DoorStatus != DoorStatus.打开)
                        {
                            Current.Task.FromStation.OpenDoor();
                        }

                        if (Current.Task.ToStation.DoorStatus != DoorStatus.打开 && Current.Task.ToStation != null && Current.Task.ToStation.GetPutType == GetPutType.烤箱 && Current.rgv.IsGettingOrPutting)
                        {
                            Current.Task.ToStation.OpenDoor();
                        }

                        if (Current.Task.FromStation.DoorStatus == DoorStatus.打开 && Current.Task.FromStation.ClampStatus != ClampStatus.无夹具)
                        {
                            Current.rgv.StartGetPut();
                        }

                        if (Current.Task.FromStation.ClampStatus == ClampStatus.无夹具)
                        {
                            Current.rgv.ClampStatus = Current.Task.FromClampStatus;
                            Current.rgv.Location    = Current.Task.FromStation.Location;
                            if (Current.Task.FromStation.ClampId > 0)
                            {
                                Current.rgv.ClampId = Current.Task.FromStation.ClampId;
                                Current.Task.FromStation.ClampId = -1;
                            }

                            if (!Current.rgv.IsGettingOrPutting)
                            {
                                Current.Task.Status = TaskStatus.取完;
                            }
                        }
                    }
                    else if (Current.Task.Status == TaskStatus.取完 && Current.Task.ToStation != null)
                    {
                        int d3410 = int.Parse(Current.Task.ToStation.RgvValues.Split(',')[0]);
                        int d3411 = int.Parse(Current.Task.ToStation.RgvValues.Split(',')[1]);

                        if (Current.rgv.IsReadyPut)
                        {
                            if (Current.rgv.Move(d3410, d3411, isGet: false))
                            {
                                Current.Task.Status = TaskStatus.可放;
                            }
                        }
                    }
                    else if (Current.Task.Status == TaskStatus.可放 && Current.Task.ToStation != null)
                    {
                        if (Current.Task.ToStation.DoorStatus != DoorStatus.打开)
                        {
                            Current.Task.ToStation.OpenDoor();
                        }

                        if (Current.Task.ToStation.DoorStatus == DoorStatus.打开 && !Current.rgv.IsGettingOrPutting && Current.Task.ToStation.ClampStatus == ClampStatus.无夹具)
                        {
                            Current.rgv.StartGetPut();
                        }

                        if (Current.Task.ToStation.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.空夹具)
                            {
                                string msg     = string.Empty;
                                int    clampId = Clamp.Add(new Clamp(Current.rgv.ClampId).Code, out msg);
                                if (clampId > 0)
                                {
                                    Current.Task.ToStation.ClampId = clampId;
                                }
                                else
                                {
                                    LogHelper.WriteError(msg);
                                }
                            }
                            else if (Current.rgv.ClampId > 0)
                            {
                                Current.Task.ToStation.ClampId = Current.rgv.ClampId;
                            }

                            Current.rgv.ClampId     = -1;
                            Current.rgv.ClampStatus = ClampStatus.无夹具;
                            Current.rgv.Location    = Current.Task.ToStation.Location;
                        }

                        if (Current.rgv.CanCheckGetPutClampIsOk)
                        {
                            Current.rgv.ClampStatus = ClampStatus.无夹具;
                            if (Current.Task.ToStation.ClampStatus == ClampStatus.无夹具)
                            {
                                //放盘无效报警
                                Current.rgv.PutClampIsNotOkAlarm();
                            }
                        }

                        if (!Current.rgv.IsGettingOrPutting && Current.Task.ToStation.ClampStatus != ClampStatus.无夹具)
                        {
                            string msg = string.Empty;
                            if (TaskLog.Add(out msg))//记录
                            {
                                Current.Task.Status = TaskStatus.完成;
                            }
                            else
                            {
                                Error.Alert("保存搬运记录失败:" + msg);
                            }
                        }
                    }
                }
            }
            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.打开)
                    {
                        int d3410 = int.Parse(Current.Task.FromStation.RgvValues.Split(',')[0]);
                        int d3411 = int.Parse(Current.Task.FromStation.RgvValues.Split(',')[1]);
                        if (Current.rgv.IsReadyGet)
                        {
                            if (Current.rgv.Move(d3410, d3411, isGet: true))
                            {
                                if (Current.Task.FromStation.DoorStatus == DoorStatus.打开)
                                {
                                    Current.Task.Status = TaskStatus.可取;
                                }
                            }
                        }
                    }
                }
                else if (Current.Task.Status == TaskStatus.可取 && Current.Task.FromStation != null)
                {
                    if (Current.Task.FromStation.DoorStatus == DoorStatus.打开 && Current.Task.FromStation.ClampStatus != ClampStatus.无夹具)
                    {
                        Current.rgv.StartGetPut();
                    }

                    if (Current.Task.FromStation.ClampStatus == ClampStatus.无夹具)
                    {
                        Current.rgv.ClampStatus = Current.Task.FromClampStatus;
                        Current.rgv.Location    = Current.Task.FromStation.Location;
                        if (Current.Task.FromStation.ClampId > 0)
                        {
                            Current.rgv.ClampId = Current.Task.FromStation.ClampId;
                            Current.Task.FromStation.ClampId = -1;
                        }

                        if (!Current.rgv.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.打开)
                        {
                            int d3410 = int.Parse(Current.Task.ToStation.RgvValues.Split(',')[0]);
                            int d3411 = int.Parse(Current.Task.ToStation.RgvValues.Split(',')[1]);

                            if (Current.rgv.IsReadyPut)
                            {
                                if (Current.rgv.Move(d3410, d3411, isGet: false))
                                {
                                    if (Current.Task.ToStation.DoorStatus == DoorStatus.打开)
                                    {
                                        Current.Task.Status = TaskStatus.可放;
                                    }
                                }
                            }
                        }
                    }
                }
                else if (Current.Task.Status == TaskStatus.可放 && Current.Task.ToStation != null)
                {
                    if (Current.Task.ToStation.DoorStatus == DoorStatus.打开 && !Current.rgv.IsGettingOrPutting && Current.Task.ToStation.ClampStatus == ClampStatus.无夹具)
                    {
                        Current.rgv.StartGetPut();
                    }

                    if (Current.Task.ToStation.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.空夹具)
                        {
                            string msg     = string.Empty;
                            int    clampId = Clamp.Add(new Clamp(Current.rgv.ClampId).Code, out msg);
                            if (clampId > 0)
                            {
                                Current.Task.ToStation.ClampId = clampId;
                            }
                            else
                            {
                                LogHelper.WriteError(msg);
                            }
                        }
                        else if (Current.rgv.ClampId > 0)
                        {
                            Current.Task.ToStation.ClampId = Current.rgv.ClampId;
                        }
                        Current.rgv.ClampId = -1;

                        Current.rgv.ClampStatus = ClampStatus.无夹具;
                        Current.rgv.Location    = Current.Task.ToStation.Location;
                    }

                    if (Current.rgv.CanCheckGetPutClampIsOk)
                    {
                        Current.rgv.ClampStatus = ClampStatus.无夹具;
                        if (Current.Task.ToStation.ClampStatus == ClampStatus.无夹具)
                        {
                            //放盘无效报警
                            Current.rgv.PutClampIsNotOkAlarm();
                        }
                    }

                    if (!Current.rgv.IsGettingOrPutting && Current.Task.ToStation.ClampStatus != ClampStatus.无夹具)
                    {
                        string msg = string.Empty;
                        if (TaskLog.Add(out msg))//记录
                        {
                            Current.Task.Status = TaskStatus.完成;
                        }
                        else
                        {
                            Error.Alert("保存搬运记录失败:" + msg);
                        }
                    }
                }
            }
        }