dOPC Client Toolkit

Writes one Attribute of one Node.

function WriteNodeAttribute(NodeId: string; Attribute: integer; Value: uaDataValue): uaStatuscode; overload;
__fastcall uaStatuscode WriteNodeAttribute(AnsiString NodeId, int Attribute, uaDataValue Value);

This method can be used to write one Attribute of one Node. It returns a uaStatuscode.

The Node you want to write.
Defines which attributes we want to write. For further information look also at: TuaAttributes
Defines the value you want to write, see also example below (can contain Value, Servertimestamp, Sourcetimestamp and Quality).
returns a uaStatuscode (look also at: uaStatusCodeToString)
program Project11; {$APPTYPE CONSOLE} {$R *.res} uses ua.client, ua.datatypes, ua.buildintypes, ua.statuscodes; var OPCClient: TdOPCUAClient; WriteVal : uaDatavalue; Ret : uaStatuscode; SetVal : uaInt32; begin OPCClient := TdOPCUAClient.Create(nil); OPCClient.Url := 'opc.tcp://'; SetVal := 32; WriteVal := uaDatavalue.Create; WriteVal.Value := uaVariant.Create(SetVal); // Also possible: // // WriteVal := uaDatavalue.Create(uaVariant.Create(SetVal)); // or // WriteVal := uaDatavalue.Create(bit_Int32); // also possible // WriteVal.Value.SetValue(32); // // Also possible if supported by the UA server // WriteVal.SourceTimestamp := Now; // Set Source Time // WriteVal.ServerTimestamp := Now; // Set Server Time // WriteVal.StatusCode := Statuscodes.Bad_NoCommunication; // Set Quality OPCClient.Active := true; Ret := OPCClient.WriteNodeAttribute('ns=2;s=Demo.Static.Scalar.Int32',TuaAttributes.Value, WriteVal); if not Ret.IsGood then writeln('Error write node:', Statuscodes.ToString(Ret)) else writeln('Succesfully written :-)'); WriteVal.Free; Writeln('Press Enter to exit'); Readln; OPCClient.Free; end.
Kassl GmbH Copyright © 2022. All rights reserved.