示例#1
0
        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"));
            }
        }
示例#2
0
        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));
            }
        }