Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

Trying to determine the type of a variable while browsing (ie. Is it a boolean, double, int, etc.)

More
12 Jun 2015 09:35 - 12 Jun 2015 09:35 #3212 by support
The node type is not returned by the browsing itself. You need to combine the browsing with reading the attributes of the node - those that determine its type. That is mainly the UAAttributeId.DataType attribute, and in some cases (for arrays), also the UAAttributeId.ValueRank and UAAttributeId.ArrayDimensions.

In addition, not all UA types have their direct .NET equivalents (and specifically, in QuickOPC this currently applies to all UA custom datatypes).

Leaving the "problematic" cases aside, you should be able to obtain the corresponding .NET data type by using the UADataType.FindDataType method as you did, but not with the NodeId of the node itself, but instead, the NodeId returned by reading its UAAttributeId.DataType attribute.

Best regards
Last edit: 12 Jun 2015 09:35 by support.

Please Log in or Create an account to join the conversation.

More
11 Jun 2015 18:05 #3209 by pmitton
Hello again.

I've been attempting to use the browsing tools to determine the value types (or is it more appropriately DataType)
of the the various nodes discovered while browsing. Below I've included a sample of the browsing code, and an example
of how I've been parsing the data into a text file.
private static async void BrowseAndReadFromNodesByDataNodes([NotNull] string baseNodeId)
        {
	    UANodeElementCollection nodeElementCollection = _client.BrowseDataNodes("opc.tcp://10.10.223.158:4840", baseNodeId);
            foreach (var nodeElement in nodeElementCollection)
            {
                if (nodeElement.ReferenceTypeId == UAReferenceTypeIds.Organizes)
                {
                    await AppenedNodeInformation(nodeElement);
                    AppendNodeInformationToCollection(nodeElement);
                    BrowseAndReadFromDataNodes(nodeElement.NodeId);
                }
                else if (nodeElement.ReferenceTypeId == UAReferenceTypeIds.HasComponent)
                {
                    await AppenedNodeInformation(nodeElement);
                    AppendNodeInformationToCollection(nodeElement);
                }
                else
                {
                    await AppenedNodeInformation(nodeElement);
                    AppendNodeInformationToCollection(nodeElement);
                }
            }
	}
private static async Task AppenedNodeInformation(UANodeElement element)
        {
            // Set a variable to the My Documents path. 
            string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
 
            // Create a stringbuilder and write the new user input to it.
            StringBuilder sb = new StringBuilder();
            var descriptor = element.ToUANodeDescriptor();
            Type typeDesc;
            var result = UADataType.FindDataType(descriptor.NodeId, out typeDesc);
            if (typeDesc == null) typeDesc = Type.GetType("string");
            try
            {
                sb.AppendLine(string.Format("{0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} ", descriptor.NodeId.Identifier, descriptor.NodeId.NamespaceUriString, typeDesc, element.TypeDefinition, element.ReferenceTypeId, element.NodeClass, descriptor.ArgumentString, element.NodeClass.GetTypeCode()));
            }
            catch (NullReferenceException ex)
            {
 
                sb.AppendLine(string.Format("Null reference at {0}", element.NodeId));
            }
 
            using (StreamWriter outfile = new StreamWriter(mydocpath + @"\NodeIds.txt", true))
            {
                await outfile.WriteAsync(sb.ToString());
            }
        }

I've been appending the information to a text file and exploring specific nodes to get feel for the process.
Eventually I'll be creating a configuration file with the desired subscription arguments we need.

I can detect and browse the nodes with no problems, but I can't seem to determine the underlying type of the node.
All I seem able to determine is if a node is an AnalogItemType or a TwoStateDiscrete. I can't tell if it is an
integer, or a double.

How can I browse the node and determine the underlying value type that will be returned when I subscribe to that
node in the future?

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.052 seconds