Skip to content

Commit

Permalink
Version 2024.1
Browse files Browse the repository at this point in the history
  • Loading branch information
OPCLabs committed Feb 18, 2024
0 parents commit af0ddc7
Show file tree
Hide file tree
Showing 237 changed files with 173,862 additions and 0 deletions.
40 changes: 40 additions & 0 deletions DocExamples/AlarmsAndEvents/AlarmsAndEvents.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

unit AlarmsAndEvents;

interface

type
AEExamplesMenu = class
public
class procedure Main(); static;
end;

implementation
uses
Console,
_EasyAEClient;

class procedure AEExamplesMenu.Main();

var
actionArray: TArray<TNamedAction>;
cont: boolean;
begin
actionArray := TArray<TNamedAction>.Create(
TNamedAction.Create(@_EasyAEClient.PullNotification.Main, 'DocExamples.AlarmsAndEvents._EasyAEClient.PullNotification.Main'),
TNamedAction.Create(@_EasyAEClient.SubscribeEvents.Main, 'DocExamples.AlarmsAndEvents._EasyAEClient.SubscribeEvents.Main')
);
repeat
WriteLn;
cont := ConsoleDialog.SelectAndPerformAction('Select action to perform', 'Return', actionArray);
if cont then
begin
WriteLn('Press Enter to continue...');
ReadLn;
end;
until not cont;
end;

end.
35 changes: 35 additions & 0 deletions DocExamples/AlarmsAndEvents/_EasyAEClient.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// $Header: $
// Copyright (c) CODE Consulting and Development, s.r.o., Plzen. All rights reserved.

//
// Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

unit _EasyAEClient;

interface

type
PullNotification = class
class procedure Main;
end;

type
SubscribeEvents = class
class procedure Main;
end;

implementation
uses
IdGlobal,
MessagePump,
OpcLabs_EasyOpcClassic_TLB,
OpcLabs_EasyOpcClassicComponents_TLB,
OpcLabs_EasyOpcClassicCore_TLB,
System.SysUtils,
Variants,
WinApi.ActiveX;

{$I _EasyAEClient/PullNotification.Main.inc}
{$I _EasyAEClient/SubscribeEvents.Main.inc}

end.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// $Header: $
// Copyright (c) CODE Consulting and Development, s.r.o., Plzen. All rights reserved.

//#region Example
// This example shows how to subscribe to events and obtain the notification events by pulling them.
//
// Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

class procedure PullNotification.Main;
var
Client: OpcLabs_EasyOpcClassic_TLB._EasyAEClient;
EndTick: Cardinal;
EventArgs: _EasyAENotificationEventArgs;
Handle: Integer;
ServerDescriptor: _ServerDescriptor;
State: OleVariant;
SubscriptionParameters: _AESubscriptionParameters;
begin
ServerDescriptor := CoServerDescriptor.Create;
ServerDescriptor.ServerClass := 'OPCLabs.KitEventServer.2';

// Instantiate the client object
Client := CoEasyAEClient.Create;
// In order to use event pull, you must set a non-zero queue capacity upfront.
Client.PullNotificationQueueCapacity := 1000;

WriteLn('Subscribing events...');
SubscriptionParameters := CoAESubscriptionParameters.Create;
SubscriptionParameters.NotificationRate := 1000;
Handle := Client.SubscribeEvents(ServerDescriptor, SubscriptionParameters, true, State);

WriteLn('Processing event notifications for 1 minute...');
EndTick := Ticks + 60*1000;
while Ticks < EndTick do
begin
EventArgs := Client.PullNotification(2*1000);
if EventArgs <> nil then
// Handle the notification event
WriteLn(EventArgs.ToString);
end;

WriteLn('Unsubscribing events...');
Client.UnsubscribeEvents(Handle);

WriteLn('Finished.');
end;
//#endregion Example
62 changes: 62 additions & 0 deletions DocExamples/AlarmsAndEvents/_EasyAEClient/SubscribeEvents.Main.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// $Header: $
// Copyright (c) CODE Consulting and Development, s.r.o., Plzen. All rights reserved.

//#region Example
// This example shows how to subscribe to events and display the event message with each notification. It also shows how to
// unsubscribe afterwards.
//
// Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

type
TClientEventHandlers = class
// Notification event handler
procedure OnNotification(
ASender: TObject;
sender: OleVariant;
const eventArgs: _EasyAENotificationEventArgs);
end;

procedure TClientEventHandlers.OnNotification(
ASender: TObject;
sender: OleVariant;
const eventArgs: _EasyAENotificationEventArgs);
begin
if not eventArgs.Succeeded then
WriteLn(Format('*** Failure: %s', [eventArgs.ErrorMessageBrief]));
if eventArgs.EventData <> nil then
WriteLn(eventArgs.EventData.Message);
end;

class procedure SubscribeEvents.Main;
var
Client: TEasyAEClient;
ClientEventHandlers: TClientEventHandlers;
Handle: Integer;
ServerDescriptor: _ServerDescriptor;
State: OleVariant;
SubscriptionParameters: _AESubscriptionParameters;
begin
ServerDescriptor := CoServerDescriptor.Create;
ServerDescriptor.ServerClass := 'OPCLabs.KitEventServer.2';

// Instantiate the client object and hook events
Client := TEasyAEClient.Create(nil);
ClientEventHandlers := TClientEventHandlers.Create;
Client.OnNotification := ClientEventHandlers.OnNotification;

WriteLn('Subscribing events...');
SubscriptionParameters := CoAESubscriptionParameters.Create;
SubscriptionParameters.NotificationRate := 1000;
Handle := Client.SubscribeEvents(ServerDescriptor, SubscriptionParameters, true, State);

WriteLn('Processing event notifications for 1 minute...');
PumpSleep(60*1000);

WriteLn('Unsubscribing events...');
Client.UnsubscribeEvents(Handle);

WriteLn('Finished.');
FreeAndNil(Client);
FreeAndNil(ClientEventHandlers);
end;
//#endregion Example
Loading

0 comments on commit af0ddc7

Please sign in to comment.