Пример #1
0
        // initialize
        public override void Initialize(BasicWarehouse w)
        {
            try
            {
                base.Initialize(w);
                if (CraneInfo != null)
                {
                    CraneInfo.Name = Name;
                    CraneInfo.Initialize();
                }

                if (HomePosition != null)
                {
                    LPHomePosition = LPosition.FromString(HomePosition);
                }

                if (OutRouteDef != null)
                {
                    if (OutRouteDef == null || OutRouteDef.XmlRoute == null)
                    {
                        throw new BasicWarehouseException(String.Format("{0} has no XmlRoute defined", Name));
                    }
                    OutConveyor                = new List <IConveyorIO>();
                    OutRouteDef.Node           = new List <RouteNode>();
                    OutRouteDef.FinalRouteCost = new List <Route>();
                    foreach (XmlRouteNode node in OutRouteDef.XmlRoute)
                    {
                        OutRouteDef.Node.Add(new RouteNode {
                            Next = Warehouse.FindConveyorBasic(node.Next), Cost = node.Cost
                        });
                        OutConveyor.Add(Warehouse.CheckForConveyorIO(node.Next));
                    }
                }
            }
            catch (Exception ex)
            {
                Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message);
                throw new CraneException(String.Format("{0} Crane.Initialize failed", Name));
            }
        }
Пример #2
0
 private SimpleCraneCommand GetCommandFromOccupiedState(int material, bool automatic)
 {
     try
     {
         SimpleCraneCommand res = null;
         // check if outbound
         var target = Warehouse.DBService.FindFirstCommand(material, automatic);
         if (target != null)
         {
             LPosition position = LPosition.FromString(target.Target);
             if (!position.IsWarehouse() || (!Crane.Shelve.Contains((short)position.Shelve)))
             {
                 res = Crane.FindBestOutput(target);
                 // if (res != null)
                 //    Warehouse.DBService.AddSimpleCommand(res);
             }
             else
             {
                 // Warehouse.DBService.AddSimpleCommand(
                 res = new SimpleCraneCommand
                 {
                     Unit       = Crane.Name,
                     Command_ID = target.ID,
                     Material   = material,
                     Task       = SimpleCommand.EnumTask.Drop,
                     Source     = target.Target,
                     Status     = SimpleCommand.EnumStatus.NotInDB,
                     Time       = DateTime.Now
                 }
             };
         }
         return(res);
     }
     catch (Exception ex)
     {
         Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message);
         throw new StrategyCraneException(String.Format("{0} GetCommandFromOccupiedState failed ({1})", Name, material));
     }
 }
Пример #3
0
        public override void CreateAndSendTOTelegram(SimpleCommand cmd)
        {
            try
            {
                if (!(cmd is SimpleCraneCommand))
                {
                    throw new CraneException(String.Format("{0} is not SimpleCraneCommand.", cmd.ToString()));
                }

                SimpleCraneCommand Cmd = cmd as SimpleCraneCommand;

                MaterialID matID = null;
                if (Cmd.Material.HasValue)
                {
                    matID = Warehouse.DBService.FindMaterialID((int)Cmd.Material, true);
                }

                LPosition pos = LPosition.FromString(Cmd.Source);
                if (!pos.IsWarehouse())
                {
                    if (cmd.Task == SimpleCommand.EnumTask.Pick)
                    {
                        pos = FindInConveyor(cmd.Source).CraneAddress;
                    }
                    else if (cmd.Task == SimpleCommand.EnumTask.Drop)
                    {
                        pos = FindOutConveyor(cmd.Source).CraneAddress;
                    }
                    else if (cmd.Task == SimpleCommand.EnumTask.Move)
                    {
                        pos = FindInOutConveyor(cmd.Source).CraneAddress;
                    }
                    else if (cmd.Task == SimpleCommand.EnumTask.Cancel)
                    {
                        pos = CraneAddress;
                        if (!cmd.CancelID.HasValue)
                        {
                            throw new CraneException(String.Format("{0} Parameter null", cmd != null ? cmd.ToString() : "null"));
                        }
                    }
                    else if (cmd.Task >= SimpleCommand.EnumTask.Delete)
                    {
                        pos = CraneAddress;
                    }
                }
                if (matID == null && cmd.Task != SimpleCommand.EnumTask.Move && cmd.Task != SimpleCommand.EnumTask.Cancel)
                {
                    throw new CraneException(String.Format("Command validity fault ({0})", cmd.ToString()));
                }

                Communicator.AddSendTelegram(
                    new Telegrams.TelegramCraneTO
                {
                    Sender    = Communicator.MFCS_ID,
                    Receiver  = Communicator.PLC_ID,
                    MFCS_ID   = cmd.ID,
                    Order     = (short)cmd.Task,
                    Buffer_ID = (cmd.Task != SimpleCommand.EnumTask.Cancel) ? (matID != null ? matID.ID : 0) : cmd.CancelID.Value,
                    Position  = new Telegrams.Position {
                        R = (short)pos.Shelve, X = (short)pos.Travel, Y = (short)pos.Height, Z = (short)pos.Depth
                    },
                    Palette = new Telegrams.Palette {
                        Barcode = Convert.ToUInt32(matID != null ? matID.ID : 0), Type = (Int16)(matID != null ? matID.Size : 0), Weight = (UInt16)(matID != null ? matID.Weight : 0)
                    },
                    ID = PLC_ID
                });
                cmd.Status = SimpleCommand.EnumStatus.Written;
                Warehouse.DBService.UpdateSimpleCommand(cmd);
                Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Command, cmd.ToString());

                // check for blocked locations
                LPosition p = LPosition.FromString(cmd.Source);
                string    frontLoc;

                if (p.Shelve > 0 && p.Depth == 2)
                {
                    LPosition pOther = new LPosition {
                        Shelve = p.Shelve, Travel = p.Travel, Height = p.Height, Depth = 1
                    };
                    frontLoc = pOther.ToString();
                }
                else
                {
                    frontLoc = cmd.Source;
                }
                if (Warehouse.DBService.FindPlaceID(cmd.Source) != null &&
                    (Warehouse.DBService.FindPlaceID(cmd.Source).Blocked || Warehouse.DBService.FindPlaceID(frontLoc).Blocked))
                {
                    Warehouse.Segment[Segment].AlarmRequest(0);
                    Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Command, string.Format("Location blocked. Command: {0}", cmd.ToString()));
                }

                if (cmd.Command_ID.HasValue)
                {
                    Command command = Warehouse.DBService.FindCommandByID(cmd.Command_ID.Value);
                    if (command == null)
                    {
                        throw new ConveyorException($"Command {command.ToString()} null.");
                    }
                    if (command.Status < Database.Command.EnumCommandStatus.Active)
                    {
                        command.Status = Database.Command.EnumCommandStatus.Active;
                        Warehouse.DBService.UpdateCommand(command);
                        Warehouse.OnCommandFinish?.Invoke(command);
                    }
                }
            }
            catch (Exception ex)
            {
                Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message);
                throw new CraneException(String.Format("{0} Crane.CreateAndSendTOTelegram failed. ({1})", Name, cmd != null ? cmd.ToString() : "null"));
            }
        }
Пример #4
0
        public void CreateMaterial(UInt32 material, string place, int?mfcs_id, bool ignoreMaterialExsists, bool ignorePlaceExsists)
        {
            try
            {
                SimpleCommand c = null;

                DBService.FindMaterialID((int)material, true);
                Place   pm  = DBService.FindMaterial((int)material);
                Place   pp  = DBService.FindPlace(place);
                PlaceID pid = DBService.FindPlaceID(place);

                //if(pm != null && pm.Place1 == "W:out")
                //{
                //    DBService.MaterialDelete(pm.Place1, (int)material);
                //    pm = null;
                //}

                if (!ignoreMaterialExsists && pm != null) // material exists
                {
                    if (mfcs_id.HasValue)
                    {
                        Command cmd = DBService.FindCommandByID(mfcs_id.Value);
                        cmd.Reason = Command.EnumCommandReason.MFCS;
                        cmd.Status = Command.EnumCommandStatus.Canceled;
                        DBService.UpdateCommand(cmd);
                        OnCommandFinish?.Invoke(cmd);
                    }
                }
                else if (!ignorePlaceExsists && pp != null && pid.Size != 999) // place is full
                {
                    if (mfcs_id.HasValue)
                    {
                        Command cmd = DBService.FindCommandByID(mfcs_id.Value);
                        cmd.Reason = Command.EnumCommandReason.LocationFull;
                        cmd.Status = Command.EnumCommandStatus.Canceled;
                        DBService.UpdateCommand(cmd);
                        OnCommandFinish?.Invoke(cmd);
                    }
                }
                else
                {
                    LPosition loc = LPosition.FromString(place);
                    if (!loc.IsWarehouse())
                    {
                        ConveyorBasic cb = FindConveyorBasic(place);
                        if (cb is Conveyor)
                        {
                            DBService.AddSimpleCommand(c = new SimpleConveyorCommand
                            {
                                Command_ID = mfcs_id,
                                Material   = (int)material,
                                Source     = place,
                                Status     = SimpleCommand.EnumStatus.NotActive,
                                Target     = place,
                                Task       = SimpleCommand.EnumTask.Create,
                                Time       = DateTime.Now
                            });
                        }
                        else if (cb is Crane)
                        {
                            DBService.AddSimpleCommand(c = new SimpleCraneCommand
                            {
                                Command_ID = mfcs_id,
                                Material   = (int)material,
                                Source     = place,
                                Status     = SimpleCommand.EnumStatus.NotActive,
                                Task       = SimpleCommand.EnumTask.Create,
                                Time       = DateTime.Now,
                                Unit       = cb.Name
                            });
                        }
                    }
                    else
                    {
                        DBService.MaterialCreate(place, (int)material, true);
                        OnMaterialMove?.Invoke(new Place {
                            Place1 = place, Material = (int)material
                        }, EnumMovementTask.Create);
                        if (mfcs_id.HasValue)
                        {
                            Command cmd = DBService.FindCommandByID(mfcs_id.Value);
                            cmd.Status = Command.EnumCommandStatus.Finished;
                            DBService.UpdateCommand(cmd);
                            OnCommandFinish?.Invoke(cmd);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, String.Format("BasicWarehouse.CreateMaterial material({0}),place({1}) failed. Reason :{2}", material, place, ex.Message));
            }
        }
Пример #5
0
        public string this[string propertyName]
        {
            get
            {
                try
                {
                    LPosition p;
                    string    frontLoc;

                    if (_warehouse.DBService != null)
                    {
                        string validationResult = String.Empty;
                        if (ValidationEnabled)
                        {
                            switch (propertyName)
                            {
                            case "TaskTU":
                                if (TaskTU >= EnumCommandTUTask.InfoMaterial)
                                {
                                    validationResult = ResourceReader.GetString("ERR_TASK");
                                }
                                break;

                            case "MaterialStr":
                                if (TaskTU == EnumCommandTUTask.Move ||
                                    TaskTU == EnumCommandTUTask.CreateMaterial ||
                                    (TaskTU == EnumCommandTUTask.DeleteMaterial && Material != null))
                                {
                                    if (!Material.HasValue || Material <= 0)
                                    {
                                        validationResult = ResourceReader.GetString("ERR_MATERIALNOTVALID");
                                    }
                                    else if (TaskTU != EnumCommandTUTask.CreateMaterial && _warehouse.DBService.FindMaterial(Material.Value) == null)
                                    {
                                        validationResult = ResourceReader.GetString("ERR_MATERIALNOTEXISTS");
                                    }
                                    else if (TaskTU == EnumCommandTUTask.CreateMaterial && _warehouse.DBService.FindMaterial(Material.Value) != null)
                                    {
                                        validationResult = ResourceReader.GetString("ERR_MATERIALEXISTS");
                                    }
                                }
                                break;

                            case "Source":
                                if (_warehouse.DBService.FindPlaceID(Source) == null)
                                {
                                    validationResult = ResourceReader.GetString("ERR_LOCATION");
                                }
                                else if (TaskTU == EnumCommandTUTask.Move && _warehouse.DBService.FindPlaceID(Target) != null &&
                                         !(_warehouse.WCFClient as WCFUIClient).NotifyUIClient.RouteExists(Source, Target, false))
                                {
                                    validationResult = ResourceReader.GetString("ERR_ROUTE");
                                }
                                else
                                {
                                    p        = LPosition.FromString(Source);
                                    frontLoc = Source;
                                    if (p.Shelve > 0 && p.Depth == 2)
                                    {
                                        LPosition pOther = new LPosition {
                                            Shelve = p.Shelve, Travel = p.Travel, Height = p.Height, Depth = 1
                                        };
                                        frontLoc = pOther.ToString();
                                    }
                                    if (_warehouse.DBService.FindPlaceID(Source).Blocked || _warehouse.DBService.FindPlaceID(frontLoc).Blocked)
                                    {
                                        validationResult = ResourceReader.GetString("ERR_BLOCKED");
                                    }
                                }
                                break;

                            case "Target":
                                if (_warehouse.DBService.FindPlaceID(Target) == null)
                                {
                                    validationResult = ResourceReader.GetString("ERR_LOCATION");
                                }
                                else if (TaskTU == EnumCommandTUTask.Move && _warehouse.DBService.FindPlaceID(Source) != null &&
                                         !(_warehouse.WCFClient as WCFUIClient).NotifyUIClient.RouteExists(Source, Target, false))
                                {
                                    validationResult = ResourceReader.GetString("ERR_ROUTE");
                                }
                                else
                                {
                                    p        = LPosition.FromString(Target);
                                    frontLoc = Target;
                                    if (p.Shelve > 0 && p.Depth == 2)
                                    {
                                        frontLoc = frontLoc.Substring(0, frontLoc.Length - 1) + '1';
                                    }
                                    if (_warehouse.DBService.FindPlaceID(Target).Blocked || _warehouse.DBService.FindPlaceID(frontLoc).Blocked)
                                    {
                                        validationResult = ResourceReader.GetString("ERR_BLOCKED");
                                    }
                                    else
                                    {
                                        var mat = Material.HasValue ? _warehouse.DBService.FindMaterialID(Material.Value, false) : null;
                                        var pid = _warehouse.DBService.FindPlaceID(Target);
                                        if (Target.StartsWith("W") && mat != null && pid != null && mat.ID / 10000 > pid.Size)
                                        {
                                            validationResult = ResourceReader.GetString("ERR_LOCATIONCLASS");
                                        }
                                    }
                                }
                                break;

                            case "Priority":
                                if (Priority < 0 || Priority > 100)
                                {
                                    validationResult = ResourceReader.GetString("ERR_PRIORITY");
                                }
                                break;
                            }
                        }
                        Validator.AddOrUpdate(propertyName, validationResult == String.Empty);
                        AllPropertiesValid = Validator.IsValid();
                        return(validationResult);
                    }
                    Validator.AddOrUpdate(propertyName, false);
                    AllPropertiesValid = Validator.IsValid();
                    return(ResourceReader.GetString("ERR_NULL"));
                }
                catch (Exception e)
                {
                    _warehouse.AddEvent(Database.Event.EnumSeverity.Error, Database.Event.EnumType.Exception,
                                        string.Format("{0}.{1}: {2}", this.GetType().Name, (new StackTrace()).GetFrame(0).GetMethod().Name, e.Message));
                    Validator.AddOrUpdate(propertyName, false);
                    AllPropertiesValid = Validator.IsValid();
                    return(ResourceReader.GetString("ERR_EXCEPTION"));
                }
            }
        }
Пример #6
0
 private int Distance(Telegrams.Position p1, LPosition p2)
 {
     return(Math.Abs(p1.X - p2.Travel) + Math.Abs(p1.Y - p2.Height));
 }
Пример #7
0
        public override void Strategy()
        {
            if (Crane.PLC_Status != null)
            {
                Crane.FastCommand = null;
            }

            if (!Warehouse.StrategyActive)
            {
                return;
            }
            if (!Crane.Communicator.Online())
            {
                return;
            }
            if (!Crane.CheckIfAllNotified())
            {
                return;
            }

            try
            {
                PickAction = null;
                Command    = Crane.Command;

                BufferCommand = Crane.BufferCommand;
                bool remote = Warehouse.SteeringCommands.RemoteMode;

                if (Crane.FastCommand == null)
                {
                    Crane.FastCommand = Warehouse.DBService.FindFirstFastSimpleCraneCommand(Crane.Name, Warehouse.SteeringCommands.AutomaticMode);
                }

                WriteCommandToPLC(Crane.FastCommand, true);

                if (!Warehouse.SteeringCommands.Run)
                {
                    return;
                }
                if ((!Crane.Remote() || Crane.LongTermBlock()))
                {
                    return;
                }
                if (!Crane.Automatic())
                {
                    return;
                }

                GetNewCommand(remote, null);
                GetNewCommand(remote, null);

                // make double cycles
                if (PickAction != null)
                {
                    PrefferedInput = LPosition.FromString(PickAction.Source).IsWarehouse();
                }

                WriteCommandToPLC(Command);
                WriteCommandToPLC(BufferCommand);

                BannedPlaces.Clear();
            }
            catch (Exception e)
            {
                Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, e.Message);
                throw new StrategyCraneException(String.Format("{0} Strategy failed.", Name));
            }
        }