Opc.Ua.Client.Session.ReadAvailableEncodings C# (CSharp) Method

ReadAvailableEncodings() public method

Returns the available encodings for a node
public ReadAvailableEncodings ( NodeId variableId ) : ReferenceDescriptionCollection
variableId NodeId The variable node.
return ReferenceDescriptionCollection
        public ReferenceDescriptionCollection ReadAvailableEncodings(NodeId variableId)
        {
            VariableNode variable = NodeCache.Find(variableId) as VariableNode;

            if (variable == null)
            {
                throw ServiceResultException.Create(StatusCodes.BadNodeIdInvalid, "NodeId does not refer to a valid variable node.");
            }

            // no encodings available if there was a problem reading the data type for the node.
            if (NodeId.IsNull(variable.DataType))
            {
                return new ReferenceDescriptionCollection();
            }

            // no encodings for non-structures.
            if (!TypeTree.IsTypeOf(variable.DataType, DataTypes.Structure))
            {
                return new ReferenceDescriptionCollection();
            }

            // look for cached values.
            IList<INode> encodings = NodeCache.Find(variableId, ReferenceTypeIds.HasEncoding, false, true);

            if (encodings.Count > 0)
            {
                ReferenceDescriptionCollection references = new ReferenceDescriptionCollection();

                foreach (INode encoding in encodings)
                {
                    ReferenceDescription reference = new ReferenceDescription();

                    reference.ReferenceTypeId = ReferenceTypeIds.HasEncoding;
                    reference.IsForward       = true;
                    reference.NodeId          = encoding.NodeId;
                    reference.NodeClass       = encoding.NodeClass;
                    reference.BrowseName      = encoding.BrowseName;
                    reference.DisplayName     = encoding.DisplayName;
                    reference.TypeDefinition  = encoding.TypeDefinitionId;
                
                    references.Add(reference);
                }

                return references;
            }

            Browser browser = new Browser(this);
                        
            browser.BrowseDirection = BrowseDirection.Forward;
            browser.ReferenceTypeId = ReferenceTypeIds.HasEncoding;
            browser.IncludeSubtypes = false;
            browser.NodeClassMask   = 0;
                        
            return browser.Browse(variable.DataType);
        }

Usage Example

Example #1
0
        /// <summary>
        /// Prompts the user to specify the browse options.
        /// </summary>
        public bool ShowDialog(Session session, NodeId variableId)
        {
            if (session == null)    throw new ArgumentNullException("session");
            if (variableId == null) throw new ArgumentNullException("variableId");
            
            m_session   = session;
            m_encodings = session.ReadAvailableEncodings(variableId);

            foreach (ReferenceDescription encoding in m_encodings)
            {
                EncodingCB.Items.Add(encoding.ToString());
            }

            if (EncodingCB.Items.Count > 0)
            {
                EncodingCB.SelectedIndex = 0;
            }

            if (ShowDialog() != DialogResult.OK)
            {
                return false;
            }

            return true;
        }