// This example shows how change the update rate of an existing OPC XML-DA subscription.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in Object Pascal (Delphi) on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-OP .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.
type
TChangeItemSubscription_ClientEventHandlers = class
// Item changed event handler
procedure OnItemChanged(
ASender: TObject;
sender: OleVariant;
const eventArgs: _EasyDAItemChangedEventArgs);
end;
procedure TChangeItemSubscription_ClientEventHandlers.OnItemChanged(
ASender: TObject;
sender: OleVariant;
const eventArgs: _EasyDAItemChangedEventArgs);
begin
if Not eventArgs.Succeeded then
begin
WriteLn('*** Failure: ', eventArgs.ErrorMessageBrief);
Exit;
end;
WriteLn(eventArgs.Vtq.ToString)
end;
class procedure ChangeItemSubscription.MainXml;
var
Arguments: OleVariant;
Client: TEasyDAClient;
ClientEventHandlers: TChangeItemSubscription_ClientEventHandlers;
HandleArray: OleVariant;
ItemSubscriptionArguments1: _EasyDAItemSubscriptionArguments;
begin
ItemSubscriptionArguments1 := CoEasyDAItemSubscriptionArguments.Create;
ItemSubscriptionArguments1.ServerDescriptor.UrlString := 'http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx';
ItemSubscriptionArguments1.ItemDescriptor.ItemID := 'Dynamic/Analog Types/Int';
ItemSubscriptionArguments1.GroupParameters.RequestedUpdateRate := 2000;
Arguments := VarArrayCreate([0, 0], varVariant);
Arguments[0] := ItemSubscriptionArguments1;
// Instantiate the client object and hook events
Client := TEasyDAClient.Create(nil);
ClientEventHandlers := TChangeItemSubscription_ClientEventHandlers.Create;
Client.OnItemChanged := ClientEventHandlers.OnItemChanged;
WriteLn('Subscribing...');
TVarData(HandleArray).VType := varArray or varVariant;
TVarData(HandleArray).VArray := PVarArray(
Client.SubscribeMultipleItems(Arguments));
WriteLn('Waiting for 20 seconds...');
PumpSleep(20*1000);
WriteLn('Changing subscription...');
Client.ChangeItemSubscription(HandleArray[0], 500);
WriteLn('Waiting for 10 seconds...');
PumpSleep(10*1000);
WriteLn('Unsubscribing...');
Client.UnsubscribeAllItems;
WriteLn('Waiting for 10 seconds...');
PumpSleep(10*1000);
VarClear(HandleArray);
VarClear(Arguments);
FreeAndNil(Client);
FreeAndNil(ClientEventHandlers);
end;
// This example shows how change the update rate of an existing OPC XML-DA subscription.
//
// Some related documentation: http://php.net/manual/en/function.com-event-sink.php . Pay attention to the comment that says
// "Be careful how you use this feature; if you are doing something similar to the example below, then it doesn't really make
// sense to run it in a web server context.". What they are trying to say is that processing a web request should be
// a short-lived code, which does not fit well with the idea of being subscribed to events and received them over longer time.
// It is possible to write such code, but it is only useful when processing the request is allowed to take relatively long. Or,
// when you are using PHP from command-line, or otherwise - not to serve a web page directly.
//
// Subscribing to QuickOPC-COM events in the context of PHP Web application, while not imposing the limitations to the request
// processing time, has to be "worked around", e.g. using the "event pull" mechanism.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in PHP on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PHP .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.
class DEasyDAClientEvents {
function ItemChanged($varSender, $varE)
{
if ($varE->Succeeded)
{
print $varE->Vtq->ToString();
print "\n";
}
else
{
printf("*** Failure: %s\n", $varE->ErrorMessageBrief);
}
}
}
$ItemSubscriptionArguments1 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.EasyDAItemSubscriptionArguments");
$ItemSubscriptionArguments1->ServerDescriptor->UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx";
$ItemSubscriptionArguments1->ItemDescriptor->ItemID = "Dynamic/Analog Types/Int";
$ItemSubscriptionArguments1->GroupParameters->RequestedUpdateRate = 2000;
$arguments[0] = $ItemSubscriptionArguments1;
// Instantiate the client object.
$Client = new COM("OpcLabs.EasyOpc.DataAccess.EasyDAClient");
$Events = new DEasyDAClientEvents();
com_event_sink($Client, $Events, "DEasyDAClientEvents");
print "Subscribing...\n";
$handles = $Client->SubscribeMultipleItems($arguments);
print "Waiting for 20 seconds...\n";
$startTime = time(); do { com_message_pump(1000); } while (time() < $startTime + 20);
print "Changing subscription...";
$Client->ChangeItemSubscription($handles[0], 500);
print "Waiting for 10 seconds...\n";
$startTime = time(); do { com_message_pump(1000); } while (time() < $startTime + 10);
print "Unsubscribing...\n";
$Client->UnsubscribeAllItems;
print "Waiting for 10 seconds...\n";
$startTime = time(); do { com_message_pump(1000); } while (time() < $startTime + 10);
Rem This example shows how change the update rate of an existing OPC XML-DA subscription.
Rem
REM Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
REM OPC client and subscriber examples in Visual Basic on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VB .
REM Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
REM a commercial license in order to use Online Forums, and we reply to every post.
' The client object, with events
'Public WithEvents Client1 As EasyDAClient
Private Sub ChangeItemSubscription_MainXml_Command_Click()
OutputText = ""
Dim ItemSubscriptionArguments1 As New EasyDAItemSubscriptionArguments
ItemSubscriptionArguments1.serverDescriptor.UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
ItemSubscriptionArguments1.ItemDescriptor.ItemId = "Dynamic/Analog Types/Int"
ItemSubscriptionArguments1.GroupParameters.RequestedUpdateRate = 2000
Dim arguments(0) As Variant
Set arguments(0) = ItemSubscriptionArguments1
' Instantiate the client object and hook events
Set Client1 = New EasyDAClient
OutputText = OutputText & "Subscribing..." & vbCrLf
Dim handles() As Variant
handles = Client1.SubscribeMultipleItems(arguments)
OutputText = OutputText & "Waiting for 20 seconds..." & vbCrLf
Pause 20000
OutputText = OutputText & "Changing subscription..." & vbCrLf
Call Client1.ChangeItemSubscription(handles(0), 500)
OutputText = OutputText & "Waiting for 10 seconds..." & vbCrLf
Pause 10000
OutputText = OutputText & "Unsubscribing..." & vbCrLf
Client1.UnsubscribeAllItems
OutputText = OutputText & "Waiting for 10 seconds..." & vbCrLf
Pause 10000
Set Client1 = Nothing
End Sub
Public Sub Client1_ItemChanged(ByVal sender As Variant, ByVal eventArgs As EasyDAItemChangedEventArgs)
If Not eventArgs.Succeeded Then
OutputText = OutputText & "*** Failure: " & eventArgs.ErrorMessageBrief & vbCrLf
Exit Sub
End If
OutputText = OutputText & eventArgs.vtq & vbCrLf
End Sub
Rem This example shows how change the update rate of an existing OPC XML-DA subscription.
Rem
Rem Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
Rem OPC client and subscriber examples in VBScript on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBScript .
Rem Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
Rem a commercial license in order to use Online Forums, and we reply to every post.
Option Explicit
Dim ItemSubscriptionArguments1: Set ItemSubscriptionArguments1 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.EasyDAItemSubscriptionArguments")
ItemSubscriptionArguments1.ServerDescriptor.UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
ItemSubscriptionArguments1.ItemDescriptor.ItemID = "Dynamic/Analog Types/Int"
ItemSubscriptionArguments1.GroupParameters.RequestedUpdateRate = 2000
Dim arguments(0)
Set arguments(0) = ItemSubscriptionArguments1
Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")
WScript.ConnectObject Client, "Client_"
WScript.Echo "Subscribing..."
Dim handles: handles = Client.SubscribeMultipleItems(arguments)
WScript.Echo "Waiting for 20 seconds..."
WScript.Sleep 20*1000
WScript.Echo "Changing subscription..."
Client.ChangeItemSubscription handles(0), 500
WScript.Echo "Waiting for 10 seconds..."
WScript.Sleep 10*1000
WScript.Echo "Unsubscribing..."
Client.UnsubscribeAllItems
WScript.Echo "Waiting for 10 seconds..."
WScript.Sleep 10*1000
WScript.DisconnectObject Client
Set Client = Nothing
' Item changed event handler
Sub Client_ItemChanged(Sender, e)
If Not (e.Succeeded) Then
WScript.Echo "*** Failure: " & e.ErrorMessageBrief
Exit Sub
End If
WScript.Echo e.Vtq
End Sub