Quickstarts.DataAccessServer.UnderlyingSystemBlock.CreateTag C# (CSharp) Method

CreateTag() public method

Creates the tag.
public CreateTag ( string tagName, UnderlyingSystemDataType dataType, UnderlyingSystemTagType tagType, string engineeringUnits, bool writeable ) : void
tagName string Name of the tag.
dataType UnderlyingSystemDataType Type of the data.
tagType UnderlyingSystemTagType Type of the tag.
engineeringUnits string The engineering units.
writeable bool if set to true the tag is writeable.
return void
        public void CreateTag(
            string tagName, 
            UnderlyingSystemDataType dataType, 
            UnderlyingSystemTagType tagType, 
            string engineeringUnits,
            bool writeable)
        {
            // create tag.
            UnderlyingSystemTag tag = new UnderlyingSystemTag();

            tag.Block = this;
            tag.Name = tagName;
            tag.Description = null;
            tag.EngineeringUnits = engineeringUnits;
            tag.DataType = dataType;
            tag.TagType = tagType;
            tag.IsWriteable = writeable;
            tag.Labels = null;
            tag.EuRange = null;

            switch (tagType)
            {
                case UnderlyingSystemTagType.Analog:
                {
                    tag.Description = "An analog value.";
                    tag.TagType = UnderlyingSystemTagType.Analog;
                    tag.EuRange = new double[] { 100, 0 };
                    break;
                }

                case UnderlyingSystemTagType.Digital:
                {
                    tag.Description = "A digital value.";
                    tag.TagType = UnderlyingSystemTagType.Digital;
                    tag.Labels = new string[] { "Online", "Offline" };
                    break;
                }

                case UnderlyingSystemTagType.Enumerated:
                {
                    tag.Description = "An enumerated value.";
                    tag.TagType = UnderlyingSystemTagType.Enumerated;
                    tag.Labels = new string[] { "Red", "Yellow", "Green" };
                    break;
                }

                default:
                {
                    tag.Description = "A generic value.";
                    break;
                }
            }

            // set an initial value.
            switch (tag.DataType)
            {
                case UnderlyingSystemDataType.Integer1: { tag.Value = (sbyte)0; break; }
                case UnderlyingSystemDataType.Integer2: { tag.Value = (short)0; break; }
                case UnderlyingSystemDataType.Integer4: { tag.Value = (int)0; break; }
                case UnderlyingSystemDataType.Real4: { tag.Value = (float)0; break; }
                case UnderlyingSystemDataType.String: { tag.Value = String.Empty; break; }
            }

            lock (m_tags)
            {
                m_tags.Add(tag);
                m_timestamp = DateTime.UtcNow;
            }
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Finds a block.
        /// </summary>
        /// <param name="blockId">The block identifier.</param>
        /// <returns>The block.</returns>
        public UnderlyingSystemBlock FindBlock(string blockId)
        {
            UnderlyingSystemBlock block = null;

            lock (m_lock)
            {
                // check for invalid name.
                if (String.IsNullOrEmpty(blockId))
                {
                    return(null);
                }

                // look for cached block.
                if (m_blocks.TryGetValue(blockId, out block))
                {
                    return(block);
                }

                // lookup block in database.
                string blockType = null;
                int    length    = blockId.Length;

                for (int ii = 0; ii < s_BlockDatabase.Length; ii++)
                {
                    blockType = s_BlockDatabase[ii];

                    if (length >= blockType.Length || blockType[length] != '/')
                    {
                        continue;
                    }

                    if (blockType.StartsWith(blockId))
                    {
                        blockType = blockType.Substring(length + 1);
                        break;
                    }

                    blockType = null;
                }

                // block not found.
                if (blockType == null)
                {
                    return(null);
                }

                // create a new block.
                block = new UnderlyingSystemBlock();

                // create the block.
                block.Id        = blockId;
                block.Name      = blockId;
                block.BlockType = blockType;

                m_blocks.Add(blockId, block);

                // add the tags based on the block type.
                // note that the block and tag types used here are types defined by the underlying system.
                // the node manager will need to map these types to UA defined types.
                switch (block.BlockType)
                {
                case "FlowSensor":
                {
                    block.CreateTag("Measurement", UnderlyingSystemDataType.Real4, UnderlyingSystemTagType.Analog, "liters/sec", false);
                    block.CreateTag("Online", UnderlyingSystemDataType.Integer1, UnderlyingSystemTagType.Digital, null, false);
                    break;
                }

                case "LevelSensor":
                {
                    block.CreateTag("Measurement", UnderlyingSystemDataType.Real4, UnderlyingSystemTagType.Analog, "liters", false);
                    block.CreateTag("Online", UnderlyingSystemDataType.Integer1, UnderlyingSystemTagType.Digital, null, false);
                    break;
                }

                case "Controller":
                {
                    block.CreateTag("SetPoint", UnderlyingSystemDataType.Real4, UnderlyingSystemTagType.Normal, null, true);
                    block.CreateTag("Measurement", UnderlyingSystemDataType.Real4, UnderlyingSystemTagType.Normal, null, false);
                    block.CreateTag("Output", UnderlyingSystemDataType.Real4, UnderlyingSystemTagType.Normal, null, false);
                    block.CreateTag("Status", UnderlyingSystemDataType.Integer4, UnderlyingSystemTagType.Enumerated, null, false);
                    break;
                }

                case "CustomController":
                {
                    block.CreateTag("Input1", UnderlyingSystemDataType.Real4, UnderlyingSystemTagType.Normal, null, true);
                    block.CreateTag("Input2", UnderlyingSystemDataType.Real4, UnderlyingSystemTagType.Normal, null, true);
                    block.CreateTag("Input3", UnderlyingSystemDataType.Real4, UnderlyingSystemTagType.Normal, null, true);
                    block.CreateTag("Output", UnderlyingSystemDataType.Real4, UnderlyingSystemTagType.Normal, null, false);
                    break;
                }
                }
            }

            // return the new block.
            return(block);
        }
All Usage Examples Of Quickstarts.DataAccessServer.UnderlyingSystemBlock::CreateTag