-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit af0ddc7
Showing
237 changed files
with
173,862 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
47 changes: 47 additions & 0 deletions
47
DocExamples/AlarmsAndEvents/_EasyAEClient/PullNotification.Main.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
62
DocExamples/AlarmsAndEvents/_EasyAEClient/SubscribeEvents.Main.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.