dOPC Client Toolkit
Close
ua.complextypes.TuaDataTypesDictionary
ua_complextypes_TuaDataTypesDictionary

Contains dictionary of OPC UA data types.

TuaDataTypesDictionary = class(TObjectDictionary<string, TuaDatatypeItem>);
class TuaDataTypesDictionary : public TObjectDictionary<string, TuaDatatypeItem>;

The dictionary is empty at startup. 

If you need information about an OPC UA server data type, then you must use the ReadAllNodeDatatypes method to fill the dictionary 

with all the data types used by the given node id. The main use of this dictionary is to get information about structure data types (extension objects). 

 

The unit has a global variable called uaDatatypeDictionary, so you don't need to create an instance of TUaDataTypesDictionary.

program ReadDataType; uses Sysutils, Generics.Collections, ua.client, ua.datatypes, ua.complextypes; procedure ShowDatatypeInDict(OPCClient: TdOPCUAClient); var DDItems : TArray<TuaDictDatatypeItem>; DItem : TuaDictDatatypeItem; BuildInType : TuaDatatypeItem; begin DDItems := uaDatatypeDictionary.ToArray; // reads all datatype from dictionary into a array for DItem in DDItems do // for all data types in dictionary begin BuildInType := uaDatatypeDictionary.GetBuiltInDatatype(DItem.value.NodeId); Writeln(DItem.Value.DatatypeName+' ('+DItem.Key+'); ' +BuildInType.DatatypeName+' ('+BuildInType.NodeId.ToString+')'); end; end; var OPCClient: TdOPCUAClient; DType : TuaDatatypeItem; Field : uaStructureField; i : integer; begin OPCClient := TdOPCUAClient.Create(nil); OPCClient.Url := ' opc.tcp://opcuademo.sterfive.com:26543'; try OPCClient.Active := true; // Read all the data type information from the variable ServerStatus (ns=0;i=2256). DType := uaDatatypeDictionary.ReadAllNodeDatatypes(OPCClient,'ns=0;i=2256'); Writeln('Name: ', Dtype.DatatypeName); Writeln('Node id: ', Dtype.NodeId.ToString); Writeln('Id: ', Dtype.Id); Writeln('Is base type: ', Dtype.IsBuildInType); Writeln('Is structure: ', Dtype.IsStructure); Writeln('Has fields: ',DType.FieldCount > 0); Writeln; // Now write all the field information that exists. for i := 0 to DType.FieldCount-1 do begin Field := DType.Fields[i]; Writeln(Field.Name); //Writeln(Field.ToString); // shows all information about the field end; Writeln; // Now write all existing datatypes from the directory ShowDatatypeInDict(OPCClient); except on E: Exception do writeln(E.Message); end; Writeln('Press Enter to exit'); Readln; OPCClient.Free; end.
Kassl GmbH Copyright © 2024. All rights reserved.