Beispiel #1
0
 protected void InitializePlace()
 {
     using (var dc = new MFCSEntities())
     {
         PlaceID = dc.PlaceIDs.Find(Name);
         Place   = dc.Places.Find(Name);
         if (PlaceID == null)
         {
             throw new SimpleTransportException(String.Format("For {0} is PlaceID not defined.", Name));
         }
     }
 }
Beispiel #2
0
 public void SaveCommands()
 {
     using (var dc = new MFCSEntities())
     {
         if (Command != null)
         {
             dc.SimpleCraneCommands.Attach(Command);
             dc.Entry <SimpleCraneCommand>(Command).State = System.Data.Entity.EntityState.Modified;
         }
         if (BufferCommand != null)
         {
             dc.SimpleCraneCommands.Attach(BufferCommand);
             dc.Entry <SimpleCraneCommand>(Command).State = System.Data.Entity.EntityState.Modified;
         }
         dc.SaveChanges();
     }
 }
Beispiel #3
0
        public void MFCS_PlaceBlock(IEnumerable <string> locs, int blocktype)
        {
            try
            {
                ServiceHostBase sh = OperationContext.Current.Host;
                if (!(sh is WarehouseServiceHost))
                {
                    throw new WCFServiceException("Host is wrong type.");
                }

                var warehouse = (sh as WarehouseServiceHost).Warehouse;
                try
                {
                    bool rebuildRoute = false;
                    using (MFCSEntities dc = new MFCSEntities())
                    {
                        foreach (var l in locs)
                        {
                            rebuildRoute |= l.StartsWith("T") || l.StartsWith("C");
                            dc.Database.ExecuteSqlCommand($"UPDATE PlaceID SET Blocked = 1 WHERE ID LIKE '{l}%'");
                            warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.WMS, $"MFCS_PlaceBlock called ({l})");
                        }
                        if (rebuildRoute)
                        {
                            warehouse.BuildRoutes(false);
                        }
                    }
                }
                catch (Exception e)
                {
                    warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception,
                                       string.Format("{0}.{1}: {2}, MFCS_PlaceBlock exception.",
                                                     this.GetType().Name, (new StackTrace()).GetFrame(0).GetMethod().Name, e.Message));
                    throw new FaultException(e.Message);
                }
            }
            catch (Exception ee)
            {
                throw new FaultException(ee.Message);
            }
        }
Beispiel #4
0
        private void AddCommandToPLC(SimpleCraneCommand cmd)
        {
            LPosition pos = LPosition.FromString(cmd.Source);

            if (!pos.IsWarehouse())
            {
                if (cmd.Task == EnumSimpleCraneCommandTask.Pick)
                {
                    pos = FindInTransport(cmd.Source).CraneAdress;
                }
                else if (cmd.Task == EnumSimpleCraneCommandTask.Drop)
                {
                    pos = FindOutTransport(cmd.Source).CraneAdress;
                }
                else if (cmd.Task == EnumSimpleCraneCommandTask.Goto)
                {
                    pos = FindInOutTransport(cmd.Source).CraneAdress;
                }
            }
            Communicator.AddSendTelegram(
                new Telegrams.TelegramCraneTO
            {
                Sender   = PLC_ID,
                MFCS_ID  = cmd.ID,
                Order    = (short)cmd.Task,
                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(cmd.Material)
                }
            });
            using (var dc = new MFCSEntities())
            {
                dc.SimpleCraneCommands.Attach(cmd);
                cmd.Status = EnumSimpleCraneCommandStatus.Written;
                dc.SaveChanges();
            }
        }
Beispiel #5
0
        public void MFCS_Submit(IEnumerable <DTOCommand> cmds)
        {
            try
            {
                ServiceHostBase sh = OperationContext.Current.Host;
                if (!(sh is WarehouseServiceHost))
                {
                    throw new WCFServiceException("Host is wrong type.");
                }

                var warehouse = (sh as WarehouseServiceHost).Warehouse;

                try
                {
                    using (MFCSEntities dc = new MFCSEntities())
                    {
                        foreach (var c in cmds)
                        {
                            if (c.Status != (int)Command.EnumCommandStatus.Canceled)
                            {
                                MaterialID matID = dc.MaterialIDs.Find((int)c.TU_ID);
                                if (matID == null)
                                {
                                    dc.MaterialIDs.Add(new MaterialID {
                                        ID = c.TU_ID, Size = 1, Weight = 1
                                    });
                                }
                                dc.Commands.Add(new CommandMaterial
                                {
                                    WMS_ID   = c.Order_ID,
                                    Source   = c.Source,
                                    Target   = c.Target,
                                    Info     = "WMS",
                                    Material = c.TU_ID,
                                    Priority = 0,
                                    Status   = (Command.EnumCommandStatus)c.Status,
                                    Task     = Command.EnumCommandTask.Move,
                                    Time     = DateTime.Now,
                                    Reason   = Command.EnumCommandReason.OK
                                });
                                warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.WMS, $"MFCS_AddMoveCommands called {c.ToString()}");
                            }
                            else
                            {
                                if (c.Order_ID >= 0)
                                {
                                    Command cc = dc.Commands.FirstOrDefault(p => p.WMS_ID == c.Order_ID);
                                    if (cc != null)
                                    {
                                        dc.Commands.Add(new CommandCommand
                                        {
                                            WMS_ID    = -1,
                                            Task      = Command.EnumCommandTask.CancelCommand,
                                            CommandID = cc.ID,
                                            Priority  = 0,
                                            Status    = Command.EnumCommandStatus.NotActive,
                                            Time      = DateTime.Now
                                        });
                                    }
                                }
                            }
                        }
                        dc.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception,
                                       string.Format("{0}.{1}: {2}, MFCS_Submit exception.",
                                                     this.GetType().Name, (new StackTrace()).GetFrame(0).GetMethod().Name, e.Message));
                    throw new FaultException(e.Message);
                }
            }
            catch (Exception ee)
            {
                throw new FaultException(ee.Message);
            }
        }
Beispiel #6
0
        public void OnOtherTelegrams(Telegram t)
        {
            try
            {
                if (t is TelegramPalletRemoved)
                {
                    using (MFCSEntities dc = new MFCSEntities())
                    {
                        string loc;
                        int    idx = (t as TelegramPalletRemoved).Location;
                        //                        int idxp = ((int)((idx - 1) / 4) + 1) * 10 + (idx - 1) % 4 + 1;
                        int idxp = idx;
                        if (idx % 10 == 0) // button pressed at the end of ramp
                        {
                            using (WMSToMFCSClient client = new WMSToMFCSClient())
                            {
                                idx = idx / 10;
                                loc = $"W:32:{idx:D2}";
                                bool canDelete;
                                try
                                {
                                    canDelete = false; // !client.OrderForRampActive(loc);
                                }
                                catch
                                {
                                    canDelete = true;
                                }
                                if (canDelete && dc.Places.Any(p => p.Place1.StartsWith(loc))) // ramp is full, remove pallets
                                {
                                    var pallets = (from p in dc.Places
                                                   where p.Place1.StartsWith(loc)
                                                   select p).ToList();
                                    foreach (var pal in pallets)
                                    {
                                        DBService.MaterialDelete(pal.Place1, pal.Material);
                                        OnMaterialMove?.Invoke(pal, EnumMovementTask.Delete);
                                        //DBService.MaterialMove(pal.Material, pal.Place1, "W:out");
                                        //Place pl = new Place { Material = pal.Material, Place1 = "W:out", Time = DateTime.Now };
                                        //OnMaterialMove?.Invoke(pl, EnumMovementTask.Move);
                                    }
                                }
//                                else // release ramp
//                                    client.DestinationEmptied(loc);
                            }
                        }
                        else // sensor detected removal
                        {
                            loc = $"W:32:{idxp:D3}:1:1";
                            Place place = dc.Places.Where(p => p.Place1 == loc).OrderBy(pp => pp.Time).FirstOrDefault();
                            {
                                DBService.MaterialDelete(place.Place1, place.Material);
                                OnMaterialMove?.Invoke(place, EnumMovementTask.Delete);
                                //DBService.MaterialMove(place.Material, loc, "W:out");
                                //Place pl = new Place { Material = place.Material, Place1 = "W:out", Time = DateTime.Now };
                                //OnMaterialMove?.Invoke(pl, EnumMovementTask.Move);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message);
                AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, String.Format("{0} BasicWarehouse.OnOtherTelegrams failed", Name));
            }
        }