Introduction

The Simplex OPC UA Client SDK defines APIs which the Application Developer can use to communicate with an OPC UA Server.


Create OPC UA client

Class TOpcUaClient implements the functionality of the OPC UA client. The record  SpxClientConfig contains the OPC UA client parameters. For client-side callbacks, use the class inherited from SpxClientCallback.

 An example of how to create OPC UA client:

uses SysUtils, Simplex.Client, Simplex.Types;

TSimplexClientTest = class(SpxClientCallback)

var OpcUaClient: TOpcUaClient;

  ClientConfig: SpxClientConfig;

  SimplexClientTest: TsimplexClientTest;

begin

  try

    ClientConfig.EndpointUrl := 'opc.tcp://localhost:4848';

    ClientConfig.SessionTimeout := 300;

    ClientConfig.TraceLevel := tlWarning;

    ClientConfig.Callback := SimplexClientTest;

    OpcUaClient:= TOpcUaClient.Create(ClientConfig);

 

    if (not OpcUaClient.Connect()) then

    begin

      OpcUaClient.Free();

      Writeln(Format('Error connect to OPC UA server, EndpointUrl=%s',

        [ClientConfig.EndpointUrl]));

      Exit;

    end;

    Writeln(Format('Connect to OPC UA server - OK, EndpointUrl=%s',

      [ClientConfig.EndpointUrl]));

     OpcUaClient.Free();

  except

    on E: Exception do

      Writeln(E.ClassName, ': ', E.Message);

  end;

 

Init session

After connecting, you need to initialize session.

 To initialize session, use:

 function TOpcUaClient.InitSession(): SpxBoolean;


Read value

 This Service is used to read one or more Attributes of one or more Nodes. For constructed Attribute values whose elements are indexed, such as an array, this Service allows Clients to read the entire set of indexed values as a composite, to read individual elements or to read ranges of elements of the composite.

 The maxAge parameter is used to direct the Server to access the value from the underlying data source, such as a device, if its copy of the data is older than that which the maxAge specifies. If the Server cannot meet the requested maximum age, it returns its “best effort” value rather than rejecting the request.

 To read value, use:

 function TOpcUaClient.ReadValue(AMaxAge: SpxDouble; AtimestampsToReturn: SpxTimestampsToReturn; AReadValueIdList: SpxReadValueIdArray; out AValues: SpxDataValueArray): SpxBoolean;

 

An example of how to read value:

const

  FormatDT = 'yy.mm.dd hh:nn:ss.zzz';

var NodeId: SpxNodeId;

  ReadValues: SpxReadValueIdArray;

  Values: SpxDataValueArray;

NodeId.NamespaceIndex := 0;

NodeId.IdentifierType := SpxIdentifierType_Numeric;

NodeId.IdentifierNumeric := SpxNodeId_Server_ServerStatus_CurrentTime;

SetLength(ReadValues, 1);

ReadValues[0].NodeId := NodeId;

ReadValues[0].AttributeId := SpxAttributes_Value;

ReadValues[0].IndexRange := '';

ReadValues[0].DataEncoding.NamespaceIndex := 0;

ReadValues[0].DataEncoding.Name := '';

 

if (not OpcUaClient.ReadValue(0, SpxTimestampsToReturn_Both, ReadValues, Values)) then Exit;

if (Length(Values) = 0) then Exit;

Writeln(Format('ReadValue - OK, StatusCode = %u',

  [Ord(Values[0].StatusCode)]));

Writeln(Format('CurrentUtcTime = %s',

  [FormatDateTime(FormatDT, Values[0].Value.AsDateTime)]));

 

Read history

This Service is used to read historical values or Events of one or more Nodes. For constructed Attribute values whose elements are indexed, such as an array, this Service allows Clients to read the entire set of indexed values as a composite, to read individual elements or to read ranges of elements of the composite. Servers may make historical values available to Clients using this Service, although the historical values themselves are not visible in the AddressSpace.

The continuationPoint parameter in the HistoryRead is used to mark a point from which to continue the read if not all values could be returned in one response. The value is opaque for the Client and is only used to maintain the state information for the Server to continue from.

To read value, use:

 function TOpcUaClient.ReadHistory(AIsReadModified: SpxBoolean; AStartTime, AEndTime: SpxDateTime; AnumValuesPerNode: SpxUInt32; AReturnBounds: SpxBoolean; ATimestampsToReturn: SpxTimestampsToReturn; AReleaseContinuationPoints: SpxBoolean; ANodesToRead: SpxHistoryReadValueIdArray; out AHistoryValues: SpxHistoryReadResultArray): SpxBoolean;

 

An example of how to read history:

var NodeId: SpxNodeId;

  NodesToRead: SpxHistoryReadValueIdArray;

  HistoryValues: SpxHistoryReadResultArray;

  I: integer;

NodeId.NamespaceIndex := 1;

NodeId.IdentifierType := SpxIdentifierType_String;

NodeId.IdentifierNumeric := 'MyFolder.MyVarStr';

SetLength(NodesToRead, 1);

NodesToRead[0].NodeId := NodeId;

NodesToRead[0].IndexRange := '';

NodesToRead[0].DataEncoding.NamespaceIndex := 0;

NodesToRead[0].DataEncoding.Name := '';

NodesToRead[0].ContinuationPoint := nil;

if (not OpcUaClient.ReadHistory(False, IncHour(Now, -3), Now, 1000, True, SpxTimestampsToReturn_Both, False, NodesToRead, HistoryValues)) then Exit;

if (Length(HistoryValues) = 0) then Exit;

Writeln(Format('ReadHistory - OK, StatusCode = %u',

     [Ord(HistoryValues[0].StatusCode)]));

for i := Low(HistoryValues[0].HistoryData) to High(HistoryValues[0].HistoryData) do

     Writeln(Format('HistoryValue[%d] = %s',

         [i, HistoryValues[0].HistoryData[i].Value.AsString]));

 

Write value

This Service is used to write values to one or more Attributes of one or more Nodes. For constructed Attribute values whose elements are indexed, such as an array, this Service allows Clients to write the entire set of indexed values as a composite, to write individual elements or to write ranges of elements of the composite.

To write value, use:

 function TOpcUaClient.WriteValue(AWriteValueList: SpxWriteValueArray; out AResults: SpxStatusCodeArray): SpxBoolean;

 

An example of how to write value:

var NodeId: SpxNodeId;

  WriteValues: SpxWriteValueArray;

  StatusCodes: SpxStatusCodeArray;

NodeId.NamespaceIndex := 1;

NodeId.IdentifierType := SpxIdentifierType_String;

NodeId.IdentifierNumeric := 'MyFolder.MyVarStr';

SetLength(WriteValues, 1);

WriteValues[0].NodeId := NodeId;

WriteValues[0].AttributeId := SpxAttributes_Value;

WriteValues[0].IndexRange := '';

WriteValues[0].Value.Value.ValueRank := SpxValueRanks_Scalar;

WriteValues[0].Value.Value.BuiltInType := SpxType_String;

WriteValues[0].Value.Value.AsString := 'value123';

WriteValues[0].Value.StatusCode := SpxStatusCode_Good;

WriteValues[0].Value.SourceTimestamp := Now;

WriteValues[0].Value.SourcePicoseconds := 0;

WriteValues[0].Value.ServerTimestamp := Now;

WriteValues[0].Value.ServerPicoseconds := 0;

if (not OpcUaClient.WriteValue(WriteValues, StatusCodes)) then Exit;

if (Length(StatusCodes) = 0) then Exit;

Writeln(Format('WriteValue - OK, StatusCode = %u',

     [Ord(StatusCodes[0])]));

 

Call method

Methods represent the function calls of Objects. TMethods are invoked and return only after completion (successful or unsuccessful). Execution times for methods may vary, depending on the function that they perform.

Because Methods may control some aspect of plant operations, method invocation may depend on environmental or other conditions. This may be especially true when attempting to re-invoke a method immediately after it has completed execution. Conditions that are required to invoke the method might not yet have returned to the state that permits the method to start again.

This Service provides for passing input and output arguments to/from a method.

To call method, use:

function TOpcUaClient.CallMethod(AMethodsToCall: SpxCallMethodRequestArray; out Aresults: SpxCallMethodResultArray): SpxBoolean;

 

An example of how to call method:

var NodeId: SpxNodeId;

  MethodsToCall: SpxCallMethodRequestArray;

  MethodResults: SpxCallMethodResultArray;

  i: integer;

NodeId.NamespaceIndex := 1;

NodeId.IdentifierType := SpxIdentifierType_String;

NodeId.IdentifierNumeric := 'MyFolder.MyMethod';

SetLength(MethodsToCall, 1);

MethodsToCall[0].MethodId :=  NodeId;

MethodsToCall[0].ObjectId.NamespaceIndex := 1;

MethodsToCall[0].ObjectId.IdentifierType := SpxIdentifierType_Numeric;

MethodsToCall[0].ObjectId.IdentifierNumeric := 0;

SetLength(MethodsToCall[0].InputArguments, 2);

MethodsToCall[0].InputArguments[0].ValueRank := SpxValueRanks_Scalar;

MethodsToCall[0].InputArguments[0].BuiltInType := SpxType_String;

MethodsToCall[0].InputArguments[0].AsString := 'One';

MethodsToCall[0].InputArguments[1].ValueRank := SpxValueRanks_Scalar;

MethodsToCall[0].InputArguments[1].BuiltInType := SpxType_String;

MethodsToCall[0].InputArguments[1].AsString := 'Two';

if (not OpcUaClient.CallMethod(MethodsToCall, MethodResults)) then Exit;

if (Length(MethodResults) = 0) then Exit;

Writeln(Format('CallMethod - OK, StatusCode = %u',

     [Ord(MethodResults[0].StatusCode)]));

for i := Low(MethodResults[0].OutputArguments) to High(MethodResults[0].OutputArguments) do

     Writeln(Format('MethodOutputArgument[%d] = %s',

         [i, MethodResults[0].OutputArguments[i].AsString]));


Browse

Clients use the Browse Service to navigate through the AddressSpace or through a View which is a subset of the AddressSpace.

This Service is used to discover the References of a specified Node. The browse can be further limited by the use of a View. This Browse Service also supports a primitive filtering capability.

To browse, use:

 function TOpcUaClient.Browse(AMaxReferencesPerNode:SpxUInt32; ABrowseDescriptions: SpxBrowseDescriptionArray; out ABrowseResultList: SpxBrowseResultArray): SpxBoolean;

 

An example of how to browse:

var BrowseDescriptions: SpxBrowseDescriptionArray;

  BrowseResults: SpxBrowseResultArray;

  i: integer;

SetLength(BrowseDescriptions, 1);

BrowseDescriptions[0].NodeId.NamespaceIndex := 0;

BrowseDescriptions[0].NodeId.IdentifierType := SpxIdentifierType_Numeric;

BrowseDescriptions[0].NodeId.IdentifierNumeric :=   SpxNodeId_RootFolder;

BrowseDescriptions[0].BrowseDirection := SpxBrowseDirection_Forward;

BrowseDescriptions[0].ReferenceTypeId.NamespaceIndex := 0;

BrowseDescriptions[0].ReferenceTypeId.IdentifierType := SpxIdentifierType_Numeric;

BrowseDescriptions[0].ReferenceTypeId.IdentifierNumeric := SpxNodeId_HierarchicalReferences;

BrowseDescriptions[0].IncludeSubtypes := True;

BrowseDescriptions[0].NodeClassMask := SpxUInt32(SpxNodeClass_Unspecified);

BrowseDescriptions[0].ResultMask := SpxUInt32(SpxBrowseResultMask_All);

if (not OpcUaClient.Browse(1000, BrowseDescriptions, BrowseResults)) then Exit;

if (Length(BrowseResults) = 0) then Exit;

Writeln(Format('Browse - OK, StatusCode = %u',

     [Ord(BrowseResults[0].StatusCode)]));

for i := Low(BrowseResults[0].References) to High(BrowseResults[0].References) do

     Writeln(Format('BrowseDisplayName[%d] = %s',

         [i, BrowseResults[0].References[i].DisplayName.Text]));

 

Browse next

This Service is used to request the next set of Browse or BrowseNext response information that is too large to be sent in a single response. “Too large” in this context means that the Server is not able to return a larger response or that the number of results to return exceeds the maximum number of results to return that was specified by the Client in the original Browse request.

To browse next, use:

 function TOpcUaClient.BrowseNext(AReleaseContinuationPoints: SpxBoolean; AContinuationPoints: SpxByteArrayArray; out ABrowseResultList: SpxBrowseResultArray): SpxBoolean;

 

An example of how to browse next:

var BrowseDescriptions: SpxBrowseDescriptionArray;

  BrowseResults: SpxBrowseResultArray;

  ContinuationPoints: SpxByteArrayArray;

  i: integer;

ContinuationPoints := nil;

SetLength(BrowseDescriptions, 1);

BrowseDescriptions[0].NodeId.NamespaceIndex := 0;

BrowseDescriptions[0].NodeId.IdentifierType := SpxIdentifierType_Numeric;

BrowseDescriptions[0].NodeId.IdentifierNumeric :=   SpxNodeId_RootFolder;

BrowseDescriptions[0].BrowseDirection := SpxBrowseDirection_Forward;

BrowseDescriptions[0].ReferenceTypeId.NamespaceIndex := 0;

BrowseDescriptions[0].ReferenceTypeId.IdentifierType := SpxIdentifierType_Numeric;

BrowseDescriptions[0].ReferenceTypeId.IdentifierNumeric := SpxNodeId_HierarchicalReferences;

BrowseDescriptions[0].IncludeSubtypes := True;

BrowseDescriptions[0].NodeClassMask := SpxUInt32(SpxNodeClass_Unspecified);

BrowseDescriptions[0].ResultMask := SpxUInt32(SpxBrowseResultMask_All);

while True do

begin

  if (Length(ContinuationPoints) = 0) then

  begin

    if (not OpcUaClient.Browse(1000, BrowseDescriptions, BrowseResults)) then Exit;

  end

  else begin

    if (not OpcUaClient.BrowseNext(False, ContinuationPoints, BrowseResults)) then Exit;

  end;

  if (Length(BrowseResults) = 0) then Exit;

  Writeln(Format('Browse - OK, StatusCode = %u',

    [Ord(BrowseResults[0].StatusCode)]));

  for i := Low(BrowseResults[0].References) to High(BrowseResults[0].References) do

    Writeln(Format('BrowseDisplayName[%d] = %s',

      [i, BrowseResults[0].References[i].DisplayName.Text]));

 

  // continue browse (if more than 1000 references)

  if (Length(BrowseResults[0].ContinuationPoint) > 0) then

  begin

    SetLength(ContinuationPoints, 1);

    ContinuationPoints[0] := BrowseResults[0].ContinuationPoint;

  end

  else Break;

end;

 

Create subscription

This Service is used to create a Subscription. Subscriptions monitor a set of MonitoredItems for Notifications and return them to the Client in response to Publish requests.

Illegal request values for parameters that can be revised do not generate errors. Instead the server will choose default values and indicate them in the corresponding revised parameter.

To create subscription, use:

 function TOpcUaClient.CreateSubscription(APublishingEnabled: SpxBoolean; ASubscription: SpxSubscription; out ASubcriptionId: SpxUInt32; out AsubscriptionResult: SpxSubscriptionResult): SpxBoolean;

 

An example of how to create subscription:

var Subscription: SpxSubscription;

  SubscriptionResult: SpxSubscriptionResult;

  SubcriptionId: SpxUInt32;

Subscription.RequestedPublishingInterval := 2000;

Subscription.RequestedLifetimeCount := 200;

Subscription.RequestedMaxKeepAliveCount := 20;

Subscription.MaxNotificationsPerPublish := 20000;

Subscription.Priority := 0;

if (not OpcUaClient.CreateSubscription(True, Subscription, SubcriptionId, SubscriptionResult)) then Exit;

Writeln(Format('CreateSubscription - OK, SubscriptionId = %d, RevisedPublishingInterval=%f, RevisedLifetimeCount=%d, RevisedMaxKeepAliveCount=%d',

     [SubcriptionId, SubscriptionResult.RevisedPublishingInterval, SubscriptionResult.RevisedLifetimeCount, SubscriptionResult.RevisedMaxKeepAliveCount]));

 

Modify subscription

This Service is used to modify a Subscription.

Illegal request values for parameters that can be revised do not generate errors. Instead the server will choose default values and indicate them in the corresponding revised parameter.

To modify subscription, use:

 function TOpcUaClient.ModifySubscriptiont(ASubcriptionId: SpxUInt32; ASubscription: SpxSubscription; out ASubscriptionResult: SpxSubscriptionResult): SpxBoolean;

 

An example of how to modify subscription:

var Subscription: SpxSubscription;

  SubscriptionResult: SpxSubscriptionResult;

  SubcriptionId: SpxUInt32;

Subscription.RequestedPublishingInterval := 3000;

Subscription.RequestedLifetimeCount := 300;

Subscription.RequestedMaxKeepAliveCount := 30;

Subscription.MaxNotificationsPerPublish := 30000;

Subscription.Priority := 1;

if (not OpcUaClient.ModifySubscriptiont(SubcriptionId, Subscription, SubscriptionResult)) then Exit;

Writeln(Format('ModifySubscriptiont — OK, RevisedPublishingInterval=%f, RevisedLifetimeCount=%d, RevisedMaxKeepAliveCount=%d',

     [SubscriptionResult.RevisedPublishingInterval, SubscriptionResult.RevisedLifetimeCount, SubscriptionResult.RevisedMaxKeepAliveCount]));

 

Delete subscription

This Service is invoked to delete one or more Subscriptions.

Successful completion of this Service causes all MonitoredItems that use the Subscription to be deleted. If this is the last Subscription assigned to the Client issuing the request, then all Publish requests queued by that Client are de-queued and a negative response is returned for each.

To delete subscription, use:

function TOpcUaClient.DeleteSubscriptions(ASubcriptionIds: SpxUInt32Array; out AResults: SpxStatusCodeArray): SpxBoolean;

function TOpcUaClient.DeleteAllSubscriptions: SpxBoolean;

 

An example of how to delete subscription:

var SubcriptionId: SpxUInt32;

  SubcriptionIds: SpxUInt32Array;

  StatusCodes: SpxStatusCodeArray;

SetLength(SubcriptionIds, 1);

SubcriptionIds[0] := SubcriptionId;

if (not OpcUaClient.DeleteSubscriptions(SubcriptionIds, StatusCodes)) then Exit;

if (Length(StatusCodes) = 0) then Exit;

Writeln(Format('DeleteSubscriptions- OK, StatusCode = %u',

     [Ord(StatusCodes[0])]));

 

Create monitored items

This Service is used to create and add one or more MonitoredItems to a Subscription. A MonitoredItem is deleted automatically by the Server when the Subscription is deleted. Deleting a MonitoredItem causes its entire set of triggered item links to be deleted, but has no effect on the MonitoredItems referenced by the triggered items.

Illegal request values for parameters that can be revised do not generate errors. Instead the server will choose default values and indicate them in the corresponding revised parameter.

To create monitored items, use:

 function TOpcUaClient.CreateMonitoredItems(ASubcriptionId: SpxUInt32; AMonitoredItems: SpxMonitoredItemArray; out AMonitoredItemResult: SpxMonitoredItemResultArray): SpxBoolean; overload;

function TOpcUaClient.CreateMonitoredItems(ASubcriptionId: SpxUInt32; ATimestampsToReturn: SpxTimestampsToReturn; AMonitoredItems: SpxMonitoredItemArray; out AMonitoredItemResult: SpxMonitoredItemResultArray): SpxBoolean; overload;

function TOpcUaClient.CreateMonitoredItems(ASubcriptionId: SpxUInt32; ATimestampsToReturn: SpxTimestampsToReturn; AFilter: SpxDataChangeFilter; AmonitoredItems: SpxMonitoredItemArray; out AmonitoredItemResult: SpxMonitoredItemResultArray): SpxBoolean; overload;

function TOpcUaClient.CreateMonitoredItems(ASubcriptionId: SpxUInt32; ATimestampsToReturn: SpxTimestampsToReturn; AFilter: SpxAggregateFilter; AmonitoredItems: SpxMonitoredItemArray; out AMonitoredItemResult: SpxMonitoredItemResultArray): SpxBoolean; overload;

function TopcUaClient.CreateMonitoredItems(ASubcriptionId: SpxUInt32; ATimestampsToReturn: SpxTimestampsToReturn; AFilter: SpxFilterParams; AmonitoredItems: SpxMonitoredItemArray; out AmonitoredItemResult: SpxMonitoredItemResultArray): SpxBoolean; overload;

 

An example of how to create monitored items:

const VariableClientHandle = 1;

var NodeId: SpxNodeId;

  SubcriptionId: SpxUInt32;

  MonitoredItems: SpxMonitoredItemArray;

  MonitoredItemResult: SpxMonitoredItemResultArray;

NodeId.NamespaceIndex := 0;

NodeId.IdentifierType := SpxIdentifierType_Numeric;

NodeId.IdentifierNumeric := SpxNodeId_Server_ServerStatus_CurrentTime;

SetLength(MonitoredItems, 1);

MonitoredItems[0].NodeId := NodeId;

MonitoredItems[0].AttributeId := SpxAttributes_Value;

MonitoredItems[0].IndexRange := '';

MonitoredItems[0].DataEncoding.NamespaceIndex := 0;

MonitoredItems[0].DataEncoding.Name := '';

MonitoredItems[0].MonitoringMode := SpxMonitoringMode_Reporting;

MonitoredItems[0].ClientHandle := VariableClientHandle;

MonitoredItems[0].SamplingInterval := 500;

MonitoredItems[0].QueueSize := 1000;

MonitoredItems[0].DiscardOldest := True;

if (not OpcUaClient.CreateMonitoredItems(SubcriptionId, SpxTimestampsToReturn_Both, MonitoredItems, MonitoredItemResult)) then Exit;

if (Length(MonitoredItemResult) = 0) then Exit;

Writeln(Format('CreateMonitoredItems - OK, StatusCode=%u, MonitoredItemId=%d, SamplingInterval=%f, QueueSize=%d',

     [MonitoredItemResult[0].StatusCode, MonitoredItemResult[0].MonitoredItemId, MonitoredItemResult[0].SamplingInterval, MonitoredItemResult[0].QueueSize]));

 

Modify monitored items

This Service is used to modify MonitoredItems of a Subscription. Changes to the sampling interval and filter take effect at the beginning of the next sampling interval (the next time the sampling timer expires).

Illegal request values for parameters that can be revised do not generate errors. Instead the server will choose default values and indicate them in the corresponding revised parameter.

To modify monitored items, use:

 function TOpcUaClient.ModifyMonitoredItems(ASubcriptionId: SpxUInt32; AMonitoredItems: SpxModifyMonitoredItemArray; out AMonitoredItemResult: SpxModifyMonitoredItemResultArray): SpxBoolean; overload;

function TOpcUaClient.ModifyMonitoredItems(ASubcriptionId: SpxUInt32; ATimestampsToReturn: SpxTimestampsToReturn; AMonitoredItems: SpxModifyMonitoredItemArray; out AMonitoredItemResult: SpxModifyMonitoredItemResultArray): SpxBoolean; overload;

function TOpcUaClient.ModifyMonitoredItems(ASubcriptionId: SpxUInt32; ATimestampsToReturn: SpxTimestampsToReturn; AFilter: SpxDataChangeFilter; AMonitoredItems: SpxModifyMonitoredItemArray; out AmonitoredItemResult: SpxModifyMonitoredItemResultArray): SpxBoolean; overload;

function TOpcUaClient.ModifyMonitoredItems(ASubcriptionId: SpxUInt32; ATimestampsToReturn: SpxTimestampsToReturn; AFilter: SpxAggregateFilter; AMonitoredItems: SpxModifyMonitoredItemArray; out AmonitoredItemResult: SpxModifyMonitoredItemResultArray): SpxBoolean; overload;

function TOpcUaClient.ModifyMonitoredItems(ASubcriptionId: SpxUInt32; ATimestampsToReturn: SpxTimestampsToReturn; AFilter: SpxFilterParams; AMonitoredItems: SpxModifyMonitoredItemArray; out AmonitoredItemResult: SpxModifyMonitoredItemResultArray): SpxBoolean; overload;

 

An example of how to modify monitored items:

const VariableClientHandle = 1;

var NodeId: SpxNodeId;

  SubcriptionId: SpxUInt32;

  MonitoredItems: SpxMonitoredItemArray;

  MonitoredItemResult: SpxMonitoredItemResultArray;

SetLength(ModifyItems, 1);

ModifyItems[0].MonitoredItemId := MonitoredItemId;

ModifyItems[0].ClientHandle := VariableClientHandle;

ModifyItems[0].SamplingInterval := 600;

ModifyItems[0].DiscardOldest := True;

if (not OpcUaClient.ModifyMonitoredItems(SubcriptionId, SpxTimestampsToReturn_Both, ModifyItems, ModifyItemResult)) then Exit;

if (Length(ModifyItemResult) = 0) then Exit;

Writeln(Format('ModifyMonitoredItems - OK, StatusCode=%u, SamplingInterval=%f, QueueSize=%d',

     [ModifyItemResult[0].StatusCode, ModifyItemResult[0].SamplingInterval, ModifyItemResult[0].QueueSize]));

 

Set monitoring mode

This Service is used to set the monitoring mode for one or more MonitoredItems of a Subscription. Setting the mode to Disabled causes all queued Notifications to be deleted.

To set monitoring mode, use:

function TOpcUaClient.SetMonitoringMode(ASubcriptionId: SpxUInt32; AMonitoringMode: SpxMonitoringMode; AMonitoredItemIds: SpxUInt32Array; out AResults: SpxStatusCodeArray): SpxBoolean;

 

An example of how to set monitoring mode:

var SubcriptionId, MonitoredItemId: SpxUInt32;

  MonitoredItemIds: SpxUInt32Array;

  StatusCodes: SpxStatusCodeArray;

SetLength(MonitoredItemIds, 1);

MonitoredItemIds[0] := MonitoredItemId;

if (not OpcUaClient.SetMonitoringMode(SubcriptionId, SpxMonitoringMode_Reporting, MonitoredItemIds, StatusCodes)) then Exit;

if (Length(StatusCodes) = 0) then Exit;

Writeln(Format('SetMonitoringMode - OK, StatusCode=%u',

     [StatusCodes[0]]));

 

Delete monitored items

This Service is used to remove one or more MonitoredItems of a Subscription. When a MonitoredItem is deleted, its triggered item links are also deleted.

To delete monitored items, use:

function TopcUaClient.DeleteMonitoredItems(ASubcriptionId: SpxUInt32; AMonitoredItemIds: SpxUInt32Array; out AResults: SpxStatusCodeArray): SpxBoolean;

 

An example of how to delete monitored items:

var SubcriptionId: SpxUInt32;

  MonitoredItemIds: SpxUInt32Array;

  StatusCodes: SpxStatusCodeArray;

if (not OpcUaClient.DeleteMonitoredItems(SubcriptionId, MonitoredItemIds, StatusCodes)) then Exit;

if (Length(StatusCodes) = 0) then Exit;

Writeln(Format('DeleteMonitoredItems - OK, StatusCode=%u',

     [StatusCodes[0]]));