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?