Пример #1
0
 public override void InitialNotify(Telegram t, uint material)
 {
     try
     {
         TelegramCraneTO tel = t as TelegramCraneTO;
         base.InitialNotify(t, material);
         if (tel.Buffer_ID != 0)
         {
             BufferCommand = Warehouse.DBService.FindSimpleCraneCommandByID(tel.Buffer_ID);
             if (BufferCommand == null)
             {
                 throw new CraneException(String.Format("Unknown BufferCommand ({0})", tel.Buffer_ID));
             }
             BufferCommand.Status = SimpleCommand.EnumStatus.InPlc;
             Warehouse.DBService.UpdateSimpleCommand(BufferCommand);
             Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Command, String.Format("{0} buffer command ({1}) in PLC", Name, BufferCommand != null ? BufferCommand.ToString() : "null"));
         }
         else if (BufferCommand != null)
         {
             BufferCommand.Reason = SimpleCommand.EnumReason.MFCS;
             BufferCommand.Status = SimpleCommand.EnumStatus.Canceled;
             Warehouse.DBService.UpdateSimpleCommand(BufferCommand);
             OnSimpleCommandFinish(BufferCommand);
             BufferCommand = null;
             Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Command, String.Format("{0} buffer command ({1}) not in PLC.", Name, BufferCommand != null ? BufferCommand.ToString() : "null"));
         }
         if (tel.MFCS_ID != 0)
         {
             Command = Warehouse.DBService.FindSimpleCraneCommandByID(tel.MFCS_ID);
             if (Command == null)
             {
                 throw new CraneException(String.Format("Unknown Command ({0})", tel.Buffer_ID));
             }
             Command.Status = SimpleCommand.EnumStatus.InPlc;
             Warehouse.DBService.UpdateSimpleCommand(Command);
             Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Command, String.Format("{0} Command ({1}) in PLC", Name, Command != null ? Command.ToString() : "null"));
         }
         else if (Command != null)
         {
             Command.Reason = SimpleCommand.EnumReason.MFCS;
             Command.Status = SimpleCommand.EnumStatus.Canceled;
             Warehouse.DBService.UpdateSimpleCommand(Command);
             OnSimpleCommandFinish(Command);
             Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Command, String.Format("{0} Command ({1}) not in PLC", Name, Command != null ? Command.ToString() : "null"));
             Command = null;
         }
     }
     catch (Exception ex)
     {
         Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message);
         throw new CraneException(String.Format("{0} Crane.InitialNotify failed ({1},{2})", Name, t is TelegramCraneTO ? (t as TelegramCraneTO).MFCS_ID : 0, material));
     }
 }
Пример #2
0
        public void OnTelegramCraneTO(Telegram t)
        {
            TelegramCraneTO cmd = t as TelegramCraneTO;

            if (Command == null)
            {
                throw new CraneException(String.Format("{0} command=null at new notification MFCS_ID={1}", Name, cmd.MFCS_ID));
            }


            if (Command.ID != cmd.MFCS_ID)
            {
                throw new CraneException(String.Format("{0} CommandID({1} != cmd.MFCS_ID{2} ", Name, Command.ID, cmd.MFCS_ID));
            }

            Command_Status = cmd;

            if (Command.Status <= EnumSimpleCraneCommandStatus.InPlc)
            {
                Command.Status = EnumSimpleCraneCommandStatus.InPlc;
            }

            if (Command_Status.Confirmation == TelegramCraneTO.CONFIRMATION_OK)
            {
                if (Command.Status <= EnumSimpleCraneCommandStatus.PLCFinished)
                {
                    Command.Status = EnumSimpleCraneCommandStatus.PLCFinished;
                }
            }
            if (Command_Status.Confirmation == TelegramCraneTO.CONFIRMATION_CANCELBYMFCS ||
                Command_Status.Confirmation == TelegramCraneTO.CONFIRMATION_CANCELBYWAREHOUSE)
            {
                CommandCancelFault  = Command_Status.Fault;
                CommandCancelText   = Command_Status.Fault.ToString();
                CommandCancelByText = Command_Status.Confirmation.ToString();
                Command.Status      = EnumSimpleCraneCommandStatus.PLCCanceled;
                if (BufferCommand != null)
                {
                    BufferCommand.Status = EnumSimpleCraneCommandStatus.PLCCanceled;
                }
            }
        }
Пример #3
0
        // proces incoming TO telegram connected to command
        // proces incoming TO telegram connected to command
        private void WorkCommand(TelegramCraneTO tel, SimpleCraneCommand cmd, bool fastCommand)
        {
            try
            {
                if (tel.Confirmation == TelegramCraneTO.CONFIRMATION_OK)
                {
                    try
                    {
                        if (fastCommand && cmd.Task < SimpleCommand.EnumTask.Delete && fastCommand)
                        {
                            throw new CraneException(String.Format("Crane.WorkCommand {0} FastCommand{1} has wrong task {2}", Name, cmd.ID, cmd.Task));
                        }
                        if (cmd.Task == SimpleCommand.EnumTask.Pick)
                        {
                            Pick(tel.Palette.Barcode, cmd.Source);
                        }
                        else if (cmd.Task == SimpleCommand.EnumTask.Drop)
                        {
                            Drop(tel.Palette.Barcode, cmd.Source);
                        }
                        else if (cmd.Task == SimpleCommand.EnumTask.Create)
                        {
                            MaterialCreate(tel.Palette.Barcode);
                        }
                        else if (cmd.Task == SimpleCommand.EnumTask.Delete)
                        {
                            MaterialDelete(tel.Palette.Barcode);
                        }

                        FinishCommand(tel.MFCS_ID, cmd, SimpleCommand.EnumStatus.Finished);
                    }
                    catch
                    {
                        cmd.Reason = SimpleCommand.EnumReason.MFCS;
                        FinishCommand(tel.MFCS_ID, cmd, SimpleCommand.EnumStatus.Canceled);
                        throw;
                    }
                    finally
                    {
                        AssignCommandsAfterFinish();
                    }
                }
                else if (tel.Confirmation == TelegramCraneTO.CONFIRMATION_DIMENSIONCHECKERROR)
                {
                    cmd.Reason = SimpleCommand.EnumReason.DimensionCheck;
                    FinishCommand(tel.MFCS_ID, cmd, SimpleCommand.EnumStatus.Canceled);
                    Command Command = Warehouse.DBService.FindCommandByID(cmd.Command_ID.Value);
                    if (Command != null)
                    {
                        Command.Status = Database.Command.EnumCommandStatus.Canceled;
                        Warehouse.DBService.UpdateCommand(Command);
                        Warehouse.OnCommandFinish?.Invoke(Command);
                    }
                    else
                    {
                        throw new ConveyorBasicException(String.Format("{0} has no corresponding Command", cmd != null ? cmd.ToString() : "null"));
                    }
                }
                else if (tel.Confirmation == TelegramCraneTO.CONFIRMATION_CANCELBYWAREHOUSE ||
                         tel.Confirmation == TelegramCraneTO.CONFIRMATION_FAULT ||
                         tel.Confirmation == TelegramCraneTO.CONFIRMATION_CANCELBYMFCS)
                {
                    bool finish = false;
                    if (tel.Confirmation == TelegramCraneTO.CONFIRMATION_CANCELBYWAREHOUSE)
                    {
                        cmd.Reason = SimpleCommand.EnumReason.Warehouse;
                    }
                    else if (tel.Confirmation == TelegramCraneTO.CONFIRMATION_FAULT)
                    {
                        cmd.Reason = (Database.SimpleCommand.EnumReason)tel.Fault;
                        if (tel.Fault == TelegramCraneTO.FAULT_CANCEL_NOCMD)
                        {
                            FinishCommand(tel.Buffer_ID, null, SimpleCommand.EnumStatus.Canceled);
                            finish = true;
                        }
                    }
                    else if (tel.Confirmation == TelegramCraneTO.CONFIRMATION_CANCELBYMFCS)
                    {
                        cmd.Reason = SimpleCommand.EnumReason.MFCS;
                    }
                    if (finish)
                    {
                        FinishCommand(tel.MFCS_ID, cmd, SimpleCommand.EnumStatus.Finished);
                    }
                    else
                    {
                        FinishCommand(tel.MFCS_ID, cmd, SimpleCommand.EnumStatus.Canceled);
                    }
                    if (BufferCommand != null)
                    {
                        BufferCommand.Reason = SimpleCommand.EnumReason.MFCS;
                        FinishCommand(tel.MFCS_ID, BufferCommand, SimpleCommand.EnumStatus.Canceled);
                    }
                    AssignCommandsAfterFinish();
                    Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Command,
                                       String.Format("{0} Confirmation({1}), Fault({2})",
                                                     cmd.ToString(), tel.Confirmation, tel.Fault));
                    Warehouse.SteeringCommands.Run &= tel.Confirmation == TelegramCraneTO.CONFIRMATION_CANCELBYMFCS ||
                                                      tel.Confirmation == TelegramCraneTO.CONFIRMATION_CANCELBYWAREHOUSE ||
                                                      (tel.Confirmation == TelegramCraneTO.CONFIRMATION_FAULT &&
                                                       (tel.Fault == TelegramCraneTO.FAULT_CANCEL_NOCMD || tel.Fault > TelegramCraneTO.FAULT_REPEATORDER));
                }
                else if (cmd.Status <= SimpleCommand.EnumStatus.InPlc)
                {
                    cmd.Status = SimpleCommand.EnumStatus.InPlc;
                    Warehouse.DBService.UpdateSimpleCommand(Command);
                }
            }
            catch (Exception ex)
            {
                Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message);
                throw new CraneException(String.Format("{0} Crane.WorkCommand failed", Name));
            }
        }
Пример #4
0
        public void OnTelegramCraneTO(Telegram t)
        {
            try
            {
                TelegramCraneTO tel = t as TelegramCraneTO;
                Command_Status = tel;

                // check if material exists
                if (tel.Order != TelegramCraneTO.ORDER_DELETEPALETTE)
                {
                    CreateOrUpdateMaterialID(tel.Palette);
                }

                // check if this is move command
                if (tel.Order < 50)
                {
                    if (tel.Confirmation == TelegramCraneTO.CONFIRMATION_INITIALNOTIFY)
                    {
                        InitialNotify(t, tel.Palette.Barcode);
                    }
                    else if (Command != null && Command.ID == tel.MFCS_ID)
                    {
                        WorkCommand(tel, Command, false);
                    }
                    else if (BufferCommand != null && BufferCommand.ID == tel.MFCS_ID)
                    {
                        // without confirmation of Command
                        Command       = BufferCommand;
                        BufferCommand = null;
                        Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Program, String.Format("{0} goes from buffer directly in execution", Command.ToString()));
                        WorkCommand(tel, Command, false);
                    }
                    else
                    {
                        Command = Warehouse.DBService.FindSimpleCraneCommandByID(tel.MFCS_ID);
                        if (Command == null)
                        {
                            throw new CraneException(String.Format("Crane.OnTelegramCraneTO {0}, tel.MFCS ({1}) does not match any move active command.", Name, tel.MFCS_ID));
                        }
                        Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Program, String.Format("{0} goes from database directly in execution", Command.ToString()));
                        WorkCommand(tel, Command, false);
                    }
                }
                else
                {
                    // fast command
                    if (Command_Status.MFCS_ID != 0 && (FastCommand == null || FastCommand.ID != Command_Status.MFCS_ID))
                    {
                        FastCommand = Warehouse.DBService.FindSimpleCraneCommandByID(tel.MFCS_ID);
                    }

                    if ((FastCommand != null) && (FastCommand.ID == tel.MFCS_ID))
                    {
                        WorkCommand(tel, FastCommand, true);
                    }
                    else
                    {
                        Warehouse.SteeringCommands.Run = false;
                        throw new CraneException(String.Format("Crane.OnTelegramCraneTO {0}, tel.MFCS ({1}) does not match any fast active command.", Name, tel.MFCS_ID));
                    }
                }
                OnStrategy?.Invoke();
                if (Command != null && CraneInfo != null)
                {
                    CraneInfo.LastCommand = Command.ToSmallString();
                }
                if (BufferCommand != null && CraneInfo != null)
                {
                    CraneInfo.LastBufferCommand = BufferCommand.ToString();
                }
                DirectVMNotify();
            }
            catch (Exception e)
            {
                Warehouse.SteeringCommands.Run = false;
                Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, e.Message);
                Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, String.Format("{0} OnTelegramCraneTO failed.", Name));
            }
        }