Esempio n. 1
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"));
            }
        }
Esempio n. 2
0
        public string this[string propertyName]
        {
            get
            {
                try
                {
                    LPosition p;
                    string    frontLoc;

                    if (_warehouse.DBService != null)
                    {
                        string validationResult = String.Empty;
                        if (ValidationEnabled)
                        {
                            switch (propertyName)
                            {
                            case "TaskTU":
                                if (TaskTU >= EnumCommandTUTask.InfoMaterial)
                                {
                                    validationResult = ResourceReader.GetString("ERR_TASK");
                                }
                                break;

                            case "MaterialStr":
                                if (TaskTU == EnumCommandTUTask.Move ||
                                    TaskTU == EnumCommandTUTask.CreateMaterial ||
                                    (TaskTU == EnumCommandTUTask.DeleteMaterial && Material != null))
                                {
                                    if (!Material.HasValue || Material <= 0)
                                    {
                                        validationResult = ResourceReader.GetString("ERR_MATERIALNOTVALID");
                                    }
                                    else if (TaskTU != EnumCommandTUTask.CreateMaterial && _warehouse.DBService.FindMaterial(Material.Value) == null)
                                    {
                                        validationResult = ResourceReader.GetString("ERR_MATERIALNOTEXISTS");
                                    }
                                    else if (TaskTU == EnumCommandTUTask.CreateMaterial && _warehouse.DBService.FindMaterial(Material.Value) != null)
                                    {
                                        validationResult = ResourceReader.GetString("ERR_MATERIALEXISTS");
                                    }
                                }
                                break;

                            case "Source":
                                if (_warehouse.DBService.FindPlaceID(Source) == null)
                                {
                                    validationResult = ResourceReader.GetString("ERR_LOCATION");
                                }
                                else if (TaskTU == EnumCommandTUTask.Move && _warehouse.DBService.FindPlaceID(Target) != null &&
                                         !(_warehouse.WCFClient as WCFUIClient).NotifyUIClient.RouteExists(Source, Target, false))
                                {
                                    validationResult = ResourceReader.GetString("ERR_ROUTE");
                                }
                                else
                                {
                                    p        = LPosition.FromString(Source);
                                    frontLoc = Source;
                                    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();
                                    }
                                    if (_warehouse.DBService.FindPlaceID(Source).Blocked || _warehouse.DBService.FindPlaceID(frontLoc).Blocked)
                                    {
                                        validationResult = ResourceReader.GetString("ERR_BLOCKED");
                                    }
                                }
                                break;

                            case "Target":
                                if (_warehouse.DBService.FindPlaceID(Target) == null)
                                {
                                    validationResult = ResourceReader.GetString("ERR_LOCATION");
                                }
                                else if (TaskTU == EnumCommandTUTask.Move && _warehouse.DBService.FindPlaceID(Source) != null &&
                                         !(_warehouse.WCFClient as WCFUIClient).NotifyUIClient.RouteExists(Source, Target, false))
                                {
                                    validationResult = ResourceReader.GetString("ERR_ROUTE");
                                }
                                else
                                {
                                    p        = LPosition.FromString(Target);
                                    frontLoc = Target;
                                    if (p.Shelve > 0 && p.Depth == 2)
                                    {
                                        frontLoc = frontLoc.Substring(0, frontLoc.Length - 1) + '1';
                                    }
                                    if (_warehouse.DBService.FindPlaceID(Target).Blocked || _warehouse.DBService.FindPlaceID(frontLoc).Blocked)
                                    {
                                        validationResult = ResourceReader.GetString("ERR_BLOCKED");
                                    }
                                    else
                                    {
                                        var mat = Material.HasValue ? _warehouse.DBService.FindMaterialID(Material.Value, false) : null;
                                        var pid = _warehouse.DBService.FindPlaceID(Target);
                                        if (Target.StartsWith("W") && mat != null && pid != null && mat.ID / 10000 > pid.Size)
                                        {
                                            validationResult = ResourceReader.GetString("ERR_LOCATIONCLASS");
                                        }
                                    }
                                }
                                break;

                            case "Priority":
                                if (Priority < 0 || Priority > 100)
                                {
                                    validationResult = ResourceReader.GetString("ERR_PRIORITY");
                                }
                                break;
                            }
                        }
                        Validator.AddOrUpdate(propertyName, validationResult == String.Empty);
                        AllPropertiesValid = Validator.IsValid();
                        return(validationResult);
                    }
                    Validator.AddOrUpdate(propertyName, false);
                    AllPropertiesValid = Validator.IsValid();
                    return(ResourceReader.GetString("ERR_NULL"));
                }
                catch (Exception e)
                {
                    _warehouse.AddEvent(Database.Event.EnumSeverity.Error, Database.Event.EnumType.Exception,
                                        string.Format("{0}.{1}: {2}", this.GetType().Name, (new StackTrace()).GetFrame(0).GetMethod().Name, e.Message));
                    Validator.AddOrUpdate(propertyName, false);
                    AllPropertiesValid = Validator.IsValid();
                    return(ResourceReader.GetString("ERR_EXCEPTION"));
                }
            }
        }