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 dobegin
L := ' '+Field.FieldData.Name+': ' +Field.TypeData.DatatypeName+ '; //'+Field.TypeData.NodeId.ToString;
if Field.ValueData <> nilthen// 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 objecttry
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 valuesif 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.