dOPC Client Toolkit
Close
ua.complextypes.TuaStructureObject
ua_complextypes_TuaStructureObject

Class to read and write any OPC UA Extension object.

TuaStructureObject = class(TuaObj);
class TuaStructureObject : public TuaObj;

The TuaStructureObject class allows you to read and write any OPC UA Extension object. Just create a TuaStructure object and assign the UAClient property to your TdOPCUAClient object. After that you can call the read method of the TuaStructureObject. The most important property of the TuaStructureObject is the Fields property. After successful read, you can enumerate the Fields. Not only is it possible to read objects, but you can also write to individual fields of an object as well.

program PDynReadWrite; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, ua.client, ua.complextypes; procedure ShowFields(ExObj: TuaStructureObject); var Field: TuaField; L : string; begin // The following code shows how easy it is to access the fields of a structure. // It is also possible to use Exobj.ToString instead (L := Exobj.ToString;) writeln(Exobj.TypeData.DisplayName.Text+' ('+Exobj.TypeData.Id+', '+Exobj.TypeData.NodeId.ToString+')'); // L := Exobj.ToString; // AddLine(L); for Field in Exobj.Fields do begin L := ' '+Field.FieldData.Name+': ' +Field.TypeData.DatatypeName+ '; //'+Field.TypeData.NodeId.ToString; if Field.ValueData <> nil then // in case we have read values as well L := L+' = '+ Field.ValueData.ToString; // show the value Writeln(L); end; if Exobj.Fields.Count <= 0 then writeln('Type is a structure, but the DataTypeDefinition attribute does not exist on the server side for this type'); end; var dOPCUAClient : TdOPCUaClient; ExObj : TuaStructureObject; begin dOPCUAClient := TdOPCUaClient.Create(nil); // create OPC UA client ExObj := TuaStructureObject.Create; // create structure object try dOPCUAClient.Url := 'opc.tcp://uademo.prosysopc.com:53530/OPCUA/SimulationServer'; dOPCUAClient.Active := true; // connect to server ExObj.UAClient := dOPCUAClient; // set OPC UA client property ExObj.Read('ns=0;i=2256',true); // now read the structure with values if ExObj.TypeData.IsStructure then // only if the nodeid is really a structure ShowFields(ExObj) else writeln('Node is not a structure it is a: '+ ExObj.TypeData.DatatypeName); readln; finally ExObj.Free; dOPCUAClient.Free; end; end.
Kassl GmbH Copyright © 2024. All rights reserved.