public override void FinishCommand(Int32 id, SimpleCommand cmd, SimpleCommand.EnumStatus s) { try { if (cmd == null) { Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Program, String.Format("Conveyor.FinishCommand ({0},{1},{2}) ", id, "null", s)); } SimpleConveyorCommand cOld = null; if (cmd == null || cmd.ID != id) { if (id != 0) { cOld = Warehouse.DBService.FindSimpleConveyorCommandByID(id); } } if (cmd == null) { cmd = cOld; } if (cmd != null) { cmd.Status = s; Warehouse.DBService.UpdateSimpleCommand(cmd); if (cmd.Status == SimpleCommand.EnumStatus.Finished || cmd.Status == SimpleCommand.EnumStatus.Canceled) { OnSimpleCommandFinish(cmd); } Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Command, cmd.ToString()); } if (cOld != null && cOld.Status < SimpleCommand.EnumStatus.Canceled) { cOld.Status = SimpleCommand.EnumStatus.Canceled; cOld.Reason = SimpleCommand.EnumReason.MFCS; Warehouse.DBService.UpdateSimpleCommand(cOld); OnSimpleCommandFinish(cOld); Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Command, cOld.ToString()); } if (cmd != null && cOld == null && cmd.ID != id && id != 0) { throw new ConveyorException("Can't find command by Id"); } } catch (Exception ex) { Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message); throw new ConveyorException(String.Format("{0} Conveyor.FinishCommand failed ({1},{2},{3})", Name, id, cmd != null ? cmd.ToString() : "null", s)); } }
public override void CreateAndSendTOTelegram(SimpleCommand cmd) { try { if (!(cmd is SimpleConveyorCommand)) { throw new ConveyorException(String.Format("{0} is not SimpleCoveyorCommand", cmd.ToString())); } SimpleConveyorCommand Cmd = cmd as SimpleConveyorCommand; MaterialID matID = Warehouse.DBService.FindMaterialID((int)cmd.Material, true); short task; switch (Cmd.Task) { case SimpleCommand.EnumTask.Move: task = TelegramTransportTO.ORDER_MOVE; break; case SimpleCommand.EnumTask.Delete: task = TelegramTransportTO.ORDER_PALETTEDELETE; break; case SimpleCommand.EnumTask.Create: task = TelegramTransportTO.ORDER_PALETTECREATE; break; case SimpleCommand.EnumTask.Cancel: throw new NotImplementedException(); default: throw new ConveyorException(String.Format("{0} has unknown Order", Cmd.ToString())); } if (Warehouse.Conveyor.ContainsKey(Cmd.Source)) { Communicator.AddSendTelegram(new TelegramTransportTO { MFCS_ID = Cmd.ID, Sender = Communicator.MFCS_ID, Receiver = Communicator.PLC_ID, Order = task, Palette = new Palette { Barcode = (UInt32)Cmd.Material, Type = (short)matID.Size, Weight = (ushort)matID.Weight }, SenderTransport = Warehouse.FindConveyorBasic(Cmd.Source).ConveyorAddress, Source = Warehouse.FindConveyorBasic(Cmd.Source).ConveyorAddress, Target = Warehouse.FindConveyorBasic(Cmd.Target).ConveyorAddress }); cmd.Status = SimpleCommand.EnumStatus.Written; Warehouse.DBService.UpdateSimpleCommand(cmd); Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Command, 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 e) { Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, e.Message); throw new ConveyorException(String.Format("{0} Conveyor.CreateAndSendTOTelegram failed ({1}).", Name, cmd != null ? cmd.ToString() : "null")); } }
public string ConveyorCommandToString(SimpleConveyorCommand cmd) { return(cmd != null?String.Format("{0}: {1} {2} {3} {4}", cmd.ID, cmd.Task, cmd.Material, ResourceReader.GetString("To"), cmd.Target) : ""); }
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)); } }
public virtual void Strategy() { try { lock (_lock) { if (!Warehouse.StrategyActive) { return; } if (!Warehouse.SteeringCommands.Run) { return; } if (!CheckIfAllNotified()) { return; } // delete ActiveRoute if ((Place == null) || (Place.Material != ActiveMaterial)) { ActiveRoute = null; ActiveMaterial = null; } if (ConveyorNamesOnCommunicator == null) { ConveyorNamesOnCommunicator = FillAllConveyorNamesOnCommunicator(); } if (Command != null && Place != null && Command.Material != Place.Material) { Command = null; throw new ConveyorJunctionException(String.Format("Command {0} does not match Place {1},{2}", Command.ToString(), Place.Place1, Place.Material)); } if (Command == null) { SimpleCommand cmd = Warehouse.DBService.FindFirstFastConveyorSimpleCommand(ConveyorNamesOnCommunicator[CommunicatorName], Warehouse.SteeringCommands.AutomaticMode); // FastCommand could be connected to any Conveyor if (cmd != null) { Conveyor cb = Warehouse.Conveyor[cmd.Source]; cb.Command = cmd; CreateAndSendTOTelegram(cmd); } } if (ActiveRoute != null) { return; } if (Command == null && Place != null && Warehouse.Conveyor[Name].Remote() && Warehouse.Conveyor[Name].Automatic()) // Uros { if (!Warehouse.SteeringCommands.RemoteMode && !Warehouse.SteeringCommands.AutomaticMode) { Command = Warehouse.DBService.FindFirstSimpleConveyorCommand(Place.Material, Name, false); if (Command != null) { CreateAndSendTOTelegram(Command); } } else if (Warehouse.SteeringCommands.AutomaticMode) { CommandMaterial cmd = Warehouse.DBService.FindFirstCommand(Place.Material, Warehouse.SteeringCommands.RemoteMode); bool error = false; // check if dimension check failed if (!(this is ConveyorJunctionAndIOAndOutput) && Command_Status != null && (int)Command_Status.Palette.Barcode == Place.Material) { foreach (bool b in Command_Status.Palette.FaultCode) { if (b) { error = true; break; } } } // check for double barcode Place p = Warehouse.DBService.FindMaterial(Place.Material); // ((int)Command_Status.Palette.Barcode); if (p != null && p.Place1 != Name) { error = true; } // follow command if (cmd != null && !error) { var routes = from route in RouteDef.FinalRouteCost where route.Items.Last().Final.Compatible(cmd.Target) && Warehouse.AllowRoute(this, route) // && route.Items[0].Final is Conveyor select route; if (routes.Count() > 1) { routes = from route in RouteDef.FinalRouteCost where route.Items.Last().Final.Compatible(cmd.Target) && route.Items[0].Final is Conveyor && Warehouse.AllowRoute(this, route) && Warehouse.FreePlaces(route.Items[0].Next) > 0 select route; } // transport command handle if (routes.Count() > 0) { ActiveRoute = routes.ElementAt(Random.Next(routes.Count())); // -1 ActiveMaterial = cmd.Material; Warehouse.DBService.AddSimpleCommand( Command = new SimpleConveyorCommand { Command_ID = cmd.ID, Material = (int)cmd.Material, Source = ActiveRoute.Items[0].First.Name, Target = ActiveRoute.Items[0].Final.Name, Task = SimpleCommand.EnumTask.Move, Status = SimpleCommand.EnumStatus.NotActive, Time = DateTime.Now }); CreateAndSendTOTelegram(Command); } // crane command demand... else { routes = from route in RouteDef.FinalRouteCost where route.Items.Last().Final.Compatible(cmd.Target) && route.Items[0].Final is Crane select route; if (routes.Count() > 0) { ActiveRoute = routes.ElementAt(Random.Next(routes.Count())); // -1 ActiveMaterial = cmd.Material; } } } // default route to output else if (error) { var routes = from route in RouteDef.FinalRouteCost where route.Items[0].Next.Place == null && route.Items[0].Final is IConveyorDefault group route by new { Route = route.Items[0] } into Group select new { Node1 = Group.Key.Route, RouteCost = Group.Min((x) => x.Cost) }; if (routes.Count() > 0) { int?cmdid = null; if (cmd != null) { cmdid = cmd.ID; } var route = routes.ElementAt(Random.Next(routes.Count())); // -1 Warehouse.DBService.AddSimpleCommand( Command = new SimpleConveyorCommand { Command_ID = cmdid, Material = (int)Place.Material, Source = route.Node1.First.Name, Target = route.Node1.Final.Name, Task = SimpleCommand.EnumTask.Move, Status = SimpleCommand.EnumStatus.NotActive, Time = DateTime.Now }); CreateAndSendTOTelegram(Command); } } } } } } catch (Exception ex) { Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message); throw new ConveyorJunctionException(String.Format("{0} ConveyorJunction.Strategy failed ", Name)); } }