// -----------------------------------------------------------------------------
// WriteItem - Write OPCUA Item
// -----------------------------------------------------------------------------
function TOPCClient.WriteItem(
Name:
String; ItemValue: Variant): Boolean;
Var
I : Integer;
ItemFound : Boolean;
label
GoToWriteToOPCServer;
begin
ItemFound := False;
Result := FALSE;
try
for I := 0
to Length(OPCServerItemArray)-1
do begin
if (AnsiMatchStr(
Name, OPCServerItemArray[I].ItemName))
then begin
ItemFound := True;
WriteToOPCServerArray[WriteIndex].ItemName :=
Name;
WriteToOPCServerArray[WriteIndex].Value := ItemValue;
WriteToOPCServerArray[WriteIndex].Source := OPCServerItemArray[I].Source;
WriteIndex := WriteIndex+1;
Result := True;
GoTo GoToWriteToOPCServer;
end;
end;
if not(ItemFound)
then begin
Meldung(0,'
TOPCClient.WriteItem: ' +
Name + '
(is not found)');
end;
GoToWriteToOPCServer:
if (WriteIndex = NoVarToWrite)
then begin
WriteMultipleIdx := WriteIndex;
WriteIndex:= 0;
WriteMultipleItems;
end else if (WriteIndex > NoVarToWrite)
then begin
Meldung(0,'
TOPCClient.WriteItem - Exception: The write array is too long!'+ '
WriteIndex = '+ IntToStr(WriteIndex));
end;
except
on E:
Exception do begin
Meldung(0,'
TOPCClient.WriteItem - Exception: ' + E.
Message + '
info: ' +
Name + '
WriteIndex: ' + IntToStr(WriteIndex) + '
I = ' + IntToStr(I));
end;
end;
end;
// -----------------------------------------------------------------------------
// WriteMultipleItem - Write OPCUA Item
// -----------------------------------------------------------------------------
Procedure TOPCClient.WriteMultipleItems;
Var
I : Integer;
Results : OleVariant;
ExpandedText : WideString;
begin
SetLength(WriteValueArguments,WriteMultipleIdx);
try
if (connected)
then begin
for I := 0
to WriteMultipleIdx-1
do begin
WriteValueArguments[I] := CoUAWriteValueArguments.Create;
WriteValueArguments[I].EndpointDescriptor.UrlString := Url_String;
ExpandedText := '
nsu='+ nsu + '
;s=' + S0 + '
.' + WriteToOPCServerArray[I].Source + '
.' + WriteToOPCServerArray[I].ItemName;
WriteValueArguments[I].NodeDescriptor.NodeId.ExpandedText := ExpandedText;
WriteValueArguments[I].Value := WriteToOPCServerArray[I].Value;
end;
WriteArguments := VarArrayCreate([0, WriteMultipleIdx-1], varVariant);
for I := 0
to WriteMultipleIdx-1
do begin
WriteArguments[I] := WriteValueArguments[I];
end;
TVarData(Results).VType := varArray
or varVariant;
TVarData(Results).VArray := PVarArray(OPCUAClientMultiWrite.WriteMultipleValues(
PSafeArray(TVarData(WriteArguments).VArray)));
end else begin
Meldung(0,'
TOPCClient.WriteAllItems: not connected to the OPC UA Server');
end;
except
on E:
Exception do begin
Meldung(0,'
TOPCClient.WriteMultipleItems - Exception: ' + E.
Message);
end;
end;
end;