Esempio n. 1
0
        /// <summary>
        /// Creates a new variable.
        /// </summary>
        private DataItemState CreateTwoStateDiscreteItemVariable(NodeState parent, string path, string name,
                                                                 string trueState, string falseState)
        {
            TwoStateDiscreteState variable = new TwoStateDiscreteState(parent);

            variable.NodeId        = new NodeId(path, NamespaceIndex);
            variable.BrowseName    = new QualifiedName(path, NamespaceIndex);
            variable.DisplayName   = new LocalizedText("en", name);
            variable.WriteMask     = AttributeWriteMask.None;
            variable.UserWriteMask = AttributeWriteMask.None;

            variable.Create(
                SystemContext,
                null,
                variable.BrowseName,
                null,
                true);

            variable.SymbolicName    = name;
            variable.ReferenceTypeId = ReferenceTypes.Organizes;
            variable.DataType        = DataTypeIds.Boolean;
            variable.ValueRank       = ValueRanks.Scalar;
            variable.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Historizing     = false;
            variable.Value           = (bool)GetNewValue(variable);
            variable.StatusCode      = StatusCodes.Good;
            variable.Timestamp       = DateTime.UtcNow;

            variable.TrueState.Value           = trueState;
            variable.TrueState.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            variable.TrueState.UserAccessLevel = AccessLevels.CurrentReadOrWrite;

            variable.FalseState.Value           = falseState;
            variable.FalseState.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            variable.FalseState.UserAccessLevel = AccessLevels.CurrentReadOrWrite;

            if (parent != null)
            {
                parent.AddChild(variable);
            }

            return(variable);
        }
Esempio n. 2
0
        /// <summary>
        /// Updates a variable from a tag.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="tag">The tag.</param>
        /// <param name="variable">The variable to update.</param>
        private void UpdateVariable(ISystemContext context, UnderlyingSystemTag tag, BaseVariableState variable)
        {
            variable.Description = tag.Description;
            variable.Value       = tag.Value;
            variable.Timestamp   = tag.Timestamp;

            switch (tag.DataType)
            {
            case UnderlyingSystemDataType.Integer1: { variable.DataType = DataTypes.SByte;  break; }

            case UnderlyingSystemDataType.Integer2: { variable.DataType = DataTypes.Int16;  break; }

            case UnderlyingSystemDataType.Integer4: { variable.DataType = DataTypes.Int32;  break; }

            case UnderlyingSystemDataType.Real4:    { variable.DataType = DataTypes.Float;  break; }

            case UnderlyingSystemDataType.String:   { variable.DataType = DataTypes.String; break; }
            }

            variable.ValueRank       = ValueRanks.Scalar;
            variable.ArrayDimensions = null;

            if (tag.IsWriteable)
            {
                variable.AccessLevel     = AccessLevels.CurrentReadOrWrite;
                variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            }
            else
            {
                variable.AccessLevel     = AccessLevels.CurrentRead;
                variable.UserAccessLevel = AccessLevels.CurrentRead;
            }

            variable.MinimumSamplingInterval = MinimumSamplingIntervals.Continuous;
            variable.Historizing             = false;

            switch (tag.TagType)
            {
            case UnderlyingSystemTagType.Analog:
            {
                AnalogItemState node = variable as AnalogItemState;

                if (tag.EuRange != null)
                {
                    if (tag.EuRange.Length >= 2 && node.EURange != null)
                    {
                        Range range = new Range(tag.EuRange[0], tag.EuRange[1]);
                        node.EURange.Value     = range;
                        node.EURange.Timestamp = tag.Block.Timestamp;
                    }

                    if (tag.EuRange.Length >= 4 && node.InstrumentRange != null)
                    {
                        Range range = new Range(tag.EuRange[2], tag.EuRange[3]);
                        node.InstrumentRange.Value     = range;
                        node.InstrumentRange.Timestamp = tag.Block.Timestamp;
                    }
                }

                if (!String.IsNullOrEmpty(tag.EngineeringUnits) && node.EngineeringUnits != null)
                {
                    EUInformation info = new EUInformation();
                    info.DisplayName                = tag.EngineeringUnits;
                    info.NamespaceUri               = Namespaces.HistoricalAccess;
                    node.EngineeringUnits.Value     = info;
                    node.EngineeringUnits.Timestamp = tag.Block.Timestamp;
                }

                break;
            }

            case UnderlyingSystemTagType.Digital:
            {
                TwoStateDiscreteState node = variable as TwoStateDiscreteState;

                if (tag.Labels != null && node.TrueState != null && node.FalseState != null)
                {
                    if (tag.Labels.Length >= 2)
                    {
                        node.TrueState.Value      = new LocalizedText(tag.Labels[0]);
                        node.TrueState.Timestamp  = tag.Block.Timestamp;
                        node.FalseState.Value     = new LocalizedText(tag.Labels[1]);
                        node.FalseState.Timestamp = tag.Block.Timestamp;
                    }
                }

                break;
            }

            case UnderlyingSystemTagType.Enumerated:
            {
                MultiStateDiscreteState node = variable as MultiStateDiscreteState;

                if (tag.Labels != null)
                {
                    LocalizedText[] strings = new LocalizedText[tag.Labels.Length];

                    for (int ii = 0; ii < tag.Labels.Length; ii++)
                    {
                        strings[ii] = new LocalizedText(tag.Labels[ii]);
                    }

                    node.EnumStrings.Value     = strings;
                    node.EnumStrings.Timestamp = tag.Block.Timestamp;
                }

                break;
            }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a variable from a tag.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="tag">The tag.</param>
        /// <returns>The variable that represents the tag.</returns>
        private BaseVariableState CreateVariable(ISystemContext context, UnderlyingSystemTag tag)
        {
            // create the variable type based on the tag type.
            BaseDataVariableState variable = null;

            switch (tag.TagType)
            {
            case UnderlyingSystemTagType.Analog:
            {
                AnalogItemState node = new AnalogItemState(this);

                if (tag.EngineeringUnits != null)
                {
                    node.EngineeringUnits = new PropertyState <EUInformation>(node);
                }

                if (tag.EuRange.Length >= 4)
                {
                    node.InstrumentRange = new PropertyState <Range>(node);
                }

                variable = node;
                break;
            }

            case UnderlyingSystemTagType.Digital:
            {
                TwoStateDiscreteState node = new TwoStateDiscreteState(this);
                variable = node;
                break;
            }

            case UnderlyingSystemTagType.Enumerated:
            {
                MultiStateDiscreteState node = new MultiStateDiscreteState(this);

                if (tag.Labels != null)
                {
                    node.EnumStrings = new PropertyState <LocalizedText[]>(node);
                }

                variable = node;
                break;
            }

            default:
            {
                DataItemState node = new DataItemState(this);
                variable = node;
                break;
            }
            }

            // set the symbolic name and reference types.
            variable.SymbolicName    = tag.Name;
            variable.ReferenceTypeId = ReferenceTypeIds.HasComponent;

            // initialize the variable from the type model.
            variable.Create(
                context,
                null,
                new QualifiedName(tag.Name, this.BrowseName.NamespaceIndex),
                null,
                true);

            // update the variable values.
            UpdateVariable(context, tag, variable);

            return(variable);
        }
Esempio n. 4
0
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return null;
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
                case DsatsDemo.BrowseNames.RPM:
                {
                    if (createOrReplace)
                    {
                        if (RPM == null)
                        {
                            if (replacement == null)
                            {
                                RPM = new AnalogItemState<float>(this);
                            }
                            else
                            {
                                RPM = (AnalogItemState<float>)replacement;
                            }
                        }
                    }

                    instance = RPM;
                    break;
                }

                case DsatsDemo.BrowseNames.Torque:
                {
                    if (createOrReplace)
                    {
                        if (Torque == null)
                        {
                            if (replacement == null)
                            {
                                Torque = new AnalogItemState<float>(this);
                            }
                            else
                            {
                                Torque = (AnalogItemState<float>)replacement;
                            }
                        }
                    }

                    instance = Torque;
                    break;
                }

                case DsatsDemo.BrowseNames.Amperes:
                {
                    if (createOrReplace)
                    {
                        if (Amperes == null)
                        {
                            if (replacement == null)
                            {
                                Amperes = new AnalogItemState<float>(this);
                            }
                            else
                            {
                                Amperes = (AnalogItemState<float>)replacement;
                            }
                        }
                    }

                    instance = Amperes;
                    break;
                }

                case DsatsDemo.BrowseNames.BrakeStatus:
                {
                    if (createOrReplace)
                    {
                        if (BrakeStatus == null)
                        {
                            if (replacement == null)
                            {
                                BrakeStatus = new TwoStateDiscreteState(this);
                            }
                            else
                            {
                                BrakeStatus = (TwoStateDiscreteState)replacement;
                            }
                        }
                    }

                    instance = BrakeStatus;
                    break;
                }

                case DsatsDemo.BrowseNames.Orientation:
                {
                    if (createOrReplace)
                    {
                        if (Orientation == null)
                        {
                            if (replacement == null)
                            {
                                Orientation = new AnalogItemState<float>(this);
                            }
                            else
                            {
                                Orientation = (AnalogItemState<float>)replacement;
                            }
                        }
                    }

                    instance = Orientation;
                    break;
                }

                case DsatsDemo.BrowseNames.IsRotatingClockwise:
                {
                    if (createOrReplace)
                    {
                        if (IsRotatingClockwise == null)
                        {
                            if (replacement == null)
                            {
                                IsRotatingClockwise = new TwoStateDiscreteState(this);
                            }
                            else
                            {
                                IsRotatingClockwise = (TwoStateDiscreteState)replacement;
                            }
                        }
                    }

                    instance = IsRotatingClockwise;
                    break;
                }
            }

            if (instance != null)
            {
                return instance;
            }

            return base.FindChild(context, browseName, createOrReplace, replacement);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a variable from a tag.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="tag">The tag.</param>
        /// <returns>The variable that represents the tag.</returns>
        private BaseVariableState CreateVariable(ISystemContext context, UnderlyingSystemTag tag)
        {
            // create the variable type based on the tag type.
            BaseDataVariableState variable = null;

            switch (tag.TagType)
            {
                case UnderlyingSystemTagType.Analog:
                {
                    AnalogItemState node = new AnalogItemState(this);

                    if (tag.EngineeringUnits != null)
                    {
                        node.EngineeringUnits = new PropertyState<EUInformation>(node);
                    }

                    if (tag.EuRange.Length >= 4)
                    {
                        node.InstrumentRange = new PropertyState<Range>(node);
                    }

                    variable = node;
                    break;
                }

                case UnderlyingSystemTagType.Digital:
                {
                    TwoStateDiscreteState node = new TwoStateDiscreteState(this);
                    variable = node;
                    break;
                }

                case UnderlyingSystemTagType.Enumerated:
                {
                    MultiStateDiscreteState node = new MultiStateDiscreteState(this);

                    if (tag.Labels != null)
                    {
                        node.EnumStrings = new PropertyState<LocalizedText[]>(node);
                    }

                    variable = node;
                    break;
                }

                default:
                {
                    DataItemState node = new DataItemState(this);
                    variable = node;
                    break;
                }
            }

            // set the symbolic name and reference types.
            variable.SymbolicName = tag.Name;
            variable.ReferenceTypeId = ReferenceTypeIds.HasComponent;

            // initialize the variable from the type model.
            variable.Create(
                context,
                null,
                new QualifiedName(tag.Name, this.BrowseName.NamespaceIndex),
                null,
                true);

            // update the variable values.
            UpdateVariable(context, tag, variable);
            
            return variable;
        }
Esempio n. 6
0
        /// <summary>
        /// Creates a new variable.
        /// </summary>
        private DataItemState CreateTwoStateDiscreteItemVariable(NodeState parent, string path, string name, string trueState, string falseState)
        {
            TwoStateDiscreteState variable = new TwoStateDiscreteState(parent);

            variable.NodeId = new NodeId(path, NamespaceIndex);
            variable.BrowseName = new QualifiedName(path, NamespaceIndex);
            variable.DisplayName = new LocalizedText("en", name);
            variable.WriteMask = AttributeWriteMask.None;
            variable.UserWriteMask = AttributeWriteMask.None;

            variable.Create(
                SystemContext,
                null,
                variable.BrowseName,
                null,
                true);

            variable.SymbolicName = name;
            variable.ReferenceTypeId = ReferenceTypes.Organizes;
            variable.DataType = DataTypeIds.Boolean;
            variable.ValueRank = ValueRanks.Scalar;
            variable.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Historizing = false;
            variable.Value = (bool)GetNewValue(variable);
            variable.StatusCode = StatusCodes.Good;
            variable.Timestamp = DateTime.UtcNow;

            variable.TrueState.Value = trueState;
            variable.TrueState.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.TrueState.UserAccessLevel = AccessLevels.CurrentReadOrWrite;

            variable.FalseState.Value = falseState;
            variable.FalseState.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.FalseState.UserAccessLevel = AccessLevels.CurrentReadOrWrite;

            if (parent != null)
            {
                parent.AddChild(variable);
            }

            return variable;
        }