示例#1
0
 // make all nceseary changes after drop command
 public void Drop(UInt32 material, string target)
 {
     try
     {
         LPosition pos = LPosition.FromString(target);
         if (pos.IsWarehouse())
         {
             Warehouse.DBService.MaterialMove((int)material, Name, target);
             Warehouse.OnMaterialMove?.Invoke(new Place {
                 Material = (int)material, Place1 = target
             }, EnumMovementTask.Move);
             Place = null;
         }
         else
         {
             ConveyorBasic cIO = FindOutConveyor(target) as ConveyorBasic;
             Move(material, this, cIO); // this will be done automatically
         }
     }
     catch (Exception ex)
     {
         Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message);
         throw new CraneException(String.Format("{0} Crane.Drop failed ({1},{2})", Name, material, target));
     }
 }
示例#2
0
 // make all neceseary changes after pick command
 public void Pick(UInt32 material, string source)
 {
     try
     {
         LPosition pos = LPosition.FromString(source);
         if (pos.IsWarehouse())
         {
             Warehouse.DBService.MaterialMove((int)material, source, Name);
             Warehouse.OnMaterialMove?.Invoke(new Place {
                 Material = (int)material, Place1 = Name
             }, EnumMovementTask.Move);
             Place = Warehouse.DBService.FindPlace(Name);
         }
         else
         {
             IConveyorIO cIO = FindInConveyor(source);
             Move(material, cIO as ConveyorBasic, this);
         }
     }
     catch (Exception ex)
     {
         Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message);
         throw new CraneException(String.Format("{0} Crane.Pick failed ({1},{2})", Name, material, source));
     }
 }
示例#3
0
 public bool Compatible(string target)
 {
     try
     {
         LPosition pos = LPosition.FromString(target);
         if (pos.IsWarehouse())
         {
             if (this is Crane)
             {
                 return((this as Crane).Shelve.Contains((short)pos.Shelve));
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(this.Name == target);
         }
     }
     catch (Exception ex)
     {
         Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message);
         throw new CraneException(String.Format("{0} ConveyorJunction failed ({1})", Name, target));
     }
 }
示例#4
0
        public FLocation GetLocation(string device)
        {
            LPosition pos = LPosition.FromString(device);

            return(pos.IsWarehouse()
                ?
                   new FLocation {
                X = 6020 + (pos.Travel - 1) * 1055,
                Y = 310 + (pos.Height - 1) * 2458,
                Z = 0
            }
                :
                   Warehouse.FindConveyorBasic(device).FLocation);
        }
示例#5
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));
     }
 }
示例#6
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"));
            }
        }
示例#7
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));
            }
        }