// This example shows how to read 4 items at once, and display their values, timestamps and qualities.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// 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.
using System;
using System.Diagnostics;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;
namespace DocExamples.DataAccess._EasyDAClient
{
partial class ReadMultipleItems
{
public static void Main1()
{
// Instantiate the client object.
var client = new EasyDAClient();
DAVtqResult[] vtqResults = client.ReadMultipleItems("OPCLabs.KitServer.2",
new DAItemDescriptor[]
{
"Simulation.Random", "Trends.Ramp (1 min)", "Trends.Sine (1 min)", "Simulation.Register_I4"
});
for (int i = 0; i < vtqResults.Length; i++)
{
Debug.Assert(vtqResults[i] != null);
if (vtqResults[i].Succeeded)
Console.WriteLine("vtqResults[{0}].Vtq: {1}", i, vtqResults[i].Vtq);
else
Console.WriteLine("vtqResults[{0}] *** Failure: {1}", i, vtqResults[i].ErrorMessageBrief);
}
}
}
}
# This example shows how to read 4 items at once, and display their values, timestamps and qualities.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in PowerShell on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PowerShell .
# 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.
#requires -Version 5.1
using namespace OpcLabs.EasyOpc.DataAccess
# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassicCore.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassic.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassicComponents.dll"
# Instantiate the client object.
$client = New-Object EasyDAClient
$vtqResults = [IEasyDAClientExtension]::ReadMultipleItems($client, "OPCLabs.KitServer.2", @(
(New-Object DAItemDescriptor("Simulation.Random")),
(New-Object DAItemDescriptor("Trends.Ramp (1 min)")),
(New-Object DAItemDescriptor("Trends.Sine (1 min)")),
(New-Object DAItemDescriptor("Simulation.Register_I4"))
))
for ($i = 0; $i -lt $vtqResults.Length; $i++) {
$vtqResult = $vtqResults[$i]
if ($vtqResult.Succeeded) {
Write-Host "vtqResults[$($i)].Vtq: $($vtqResult.Vtq)"
}
else {
Write-Host "vtqResults[$($i)] *** Failure: $($vtqResult.ErrorMessageBrief)"
}
}
' This example shows how to read 4 items at once, and display their values, timestamps and qualities.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' 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.
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.DataAccess.OperationModel
Namespace DataAccess._EasyDAClient
Partial Friend Class ReadMultipleItems
Public Shared Sub Main1()
Dim client = New EasyDAClient()
Dim vtqResults() As DAVtqResult = client.ReadMultipleItems(
"OPCLabs.KitServer.2",
New DAItemDescriptor() {"Simulation.Random", "Trends.Ramp (1 min)", "Trends.Sine (1 min)", "Simulation.Register_I4"})
For i = 0 To vtqResults.Length - 1
Debug.Assert(vtqResults(i) IsNot Nothing)
If vtqResults(i).Succeeded Then
Console.WriteLine("vtqResult[{0}].Vtq: {1}", i, vtqResults(i).Vtq)
Else
Console.WriteLine("vtqResult[{0}] *** Failure: {1}", i, vtqResults(i).ErrorMessageBrief)
End If
Next i
End Sub
End Class
End Namespace
// This example shows how to read 4 items at once, and display their values, timestamps and qualities.
//
// 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.
$ReadItemArguments1 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments");
$ReadItemArguments1->ServerDescriptor->ServerClass = "OPCLabs.KitServer.2";
$ReadItemArguments1->ItemDescriptor->ItemID = "Simulation.Random";
$ReadItemArguments2 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments");
$ReadItemArguments2->ServerDescriptor->ServerClass = "OPCLabs.KitServer.2";
$ReadItemArguments2->ItemDescriptor->ItemID = "Trends.Ramp (1 min)";
$ReadItemArguments3 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments");
$ReadItemArguments3->ServerDescriptor->ServerClass = "OPCLabs.KitServer.2";
$ReadItemArguments3->ItemDescriptor->ItemID = "Trends.Sine (1 min)";
$ReadItemArguments4 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments");
$ReadItemArguments4->ServerDescriptor->ServerClass = "OPCLabs.KitServer.2";
$ReadItemArguments4->ItemDescriptor->ItemID = "Simulation.Register_I4";
$arguments[0] = $ReadItemArguments1;
$arguments[1] = $ReadItemArguments2;
$arguments[2] = $ReadItemArguments3;
$arguments[3] = $ReadItemArguments4;
$Client = new COM("OpcLabs.EasyOpc.DataAccess.EasyDAClient");
$results = $Client->ReadMultipleItems($arguments);
for ($i = 0; $i < count($results); $i++)
{
$VtqResult = $results[$i];
if ($VtqResult->Succeeded)
printf("results[d].Vtq.ToString()s\n", $i, $VtqResult->Vtq->ToString);
else
printf("results[d]: *** Failures\n", $i, $VtqResult->ErrorMessageBrief);
}
# This example shows how to read 4 items at once, and display their values, timestamps and qualities.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# 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.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
# Import .NET namespaces.
from OpcLabs.EasyOpc import *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.DataAccess.OperationModel import *
from OpcLabs.EasyOpc.OperationModel import *
# Instantiate the client object.
client = EasyDAClient()
#
vtqResultArray = client.ReadMultipleItems([
DAReadItemArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Simulation.Random')),
DAReadItemArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Trends.Ramp (1 min)')),
DAReadItemArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Trends.Sine (1 min)')),
DAReadItemArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Simulation.Register_I4')),
])
for i, vtqResult in enumerate(vtqResultArray):
assert vtqResult is not None
if vtqResult.Succeeded:
print('vtqResultArray[', i, '].Vtq: ', vtqResult.Vtq, sep='')
else:
print('vtqResultArray[', i, '] *** Failure: ', vtqResult.ErrorMessageBrief, sep='')
// This example shows how to read 4 items from an OPC XML-DA server at once, and display their values, timestamps
// and qualities.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// 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.
using System;
using System.Diagnostics;
using OpcLabs.EasyOpc;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;
namespace DocExamples.DataAccess.Xml
{
partial class ReadMultipleItems
{
public static void Main1Xml()
{
// Instantiate the client object.
var client = new EasyDAClient();
DAVtqResult[] vtqResults = client.ReadMultipleItems(
new ServerDescriptor { UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx" },
new DAItemDescriptor[]
{
"Dynamic/Analog Types/Double",
"Dynamic/Analog Types/Double[]",
"Dynamic/Analog Types/Int",
"SomeUnknownItem"
});
for (int i = 0; i < vtqResults.Length; i++)
{
Debug.Assert(vtqResults[i] != null);
if (!(vtqResults[i].Exception is null))
{
Console.WriteLine($"vtqResults[{i}] *** Failure: {vtqResults[i].ErrorMessageBrief}");
continue;
}
Console.WriteLine($"vtqResults[{i}].Vtq: {vtqResults[i].Vtq}");
}
}
}
}
# This example shows how to read 4 items from an OPC XML-DA server at once, and display their values, timestamps
# and qualities.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in PowerShell on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PowerShell .
# 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.
#requires -Version 5.1
using namespace OpcLabs.EasyOpc
using namespace OpcLabs.EasyOpc.DataAccess
# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassicCore.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassic.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassicComponents.dll"
# Instantiate the client object.
$client = New-Object EasyDAClient
$serverDescriptor = New-Object ServerDescriptor -Property @{
UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
}
$vtqResults = [IEasyDAClientExtension]::ReadMultipleItems($client,
$serverDescriptor,
@(
(New-Object DAItemDescriptor("Dynamic/Analog Types/Double")),
(New-Object DAItemDescriptor("Dynamic/Analog Types/Double[]")),
(New-Object DAItemDescriptor("Dynamic/Analog Types/Int")),
(New-Object DAItemDescriptor("SomeUnknownItem"))
))
for ($i = 0; $i -lt $vtqResults.Length; $i++) {
$vtqResult = $vtqResults[$i]
if ($vtqResult.Succeeded) {
Write-Host "vtqResults[$($i)].Vtq: $($vtqResult.Vtq)"
}
else {
Write-Host "vtqResults[$($i)] *** Failure: $($vtqResult.ErrorMessageBrief)"
}
}
' This example shows how to read 4 items from an OPC XML-DA server at once, and display their values, timestamps
' and qualities.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' 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.
Imports OpcLabs.EasyOpc
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.DataAccess.OperationModel
Namespace DataAccess.Xml
Partial Friend Class ReadMultipleItems
Public Shared Sub Main1Xml()
Dim client = New EasyDAClient()
Dim vtqResults() As DAVtqResult = client.ReadMultipleItems(
New ServerDescriptor() With {.UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"},
New DAItemDescriptor() _
{ _
"Dynamic/Analog Types/Double",
"Dynamic/Analog Types/Double[]",
"Dynamic/Analog Types/Int",
"SomeUnknownItem"
})
For i = 0 To vtqResults.Length - 1
Debug.Assert(vtqResults(i) IsNot Nothing)
If vtqResults(i).Exception IsNot Nothing Then
Console.WriteLine("vtqResult[{0}] *** Failure: {1}", i, vtqResults(i).ErrorMessageBrief)
Continue For
End If
Console.WriteLine("vtqResult[{0}].Vtq: {1}", i, vtqResults(i).Vtq)
Next i
End Sub
End Class
End Namespace
# This example shows how to read 4 items from an OPC XML-DA server at once, and display their values, timestamps
# and qualities.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# 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.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
# Import .NET namespaces.
from OpcLabs.EasyOpc import *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.DataAccess.OperationModel import *
from OpcLabs.EasyOpc.OperationModel import *
# Instantiate the client object.
client = EasyDAClient()
#
vtqResultArray = IEasyDAClientExtension.ReadMultipleItems(client,
ServerDescriptor('http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'),
[
DAItemDescriptor('Dynamic/Analog Types/Double'),
DAItemDescriptor('Dynamic/Analog Types/Double[]'),
DAItemDescriptor('Dynamic/Analog Types/Int'),
DAItemDescriptor('SomeUnknownItem')
])
for i, vtqResult in enumerate(vtqResultArray):
assert vtqResult is not None
if vtqResult.Succeeded:
print('vtqResultArray[', i, '].Vtq: ', vtqResult.Vtq, sep='')
else:
print('vtqResultArray[', i, '] *** Failure: ', vtqResult.ErrorMessageBrief, sep='')
// This example repeatedly reads a large number of items.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// 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.
using System;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;
namespace DocExamples.DataAccess._EasyDAClient
{
partial class ReadMultipleItems
{
private const int RepeatCount = 10;
private const int NumberOfItems = 1000;
public static void ManyRepeat()
{
Console.WriteLine("Creating array of arguments...");
var arguments = new DAReadItemArguments[NumberOfItems];
for (int i = 0; i < NumberOfItems; i++)
{
int copy = (i / 100) + 1;
int phase = i % 100;
string itemId = FormattableString.Invariant($"Simulation.Incrementing.Copy_{copy}.Phase_{phase}");
Console.WriteLine(itemId);
var readItemArguments = new DAReadItemArguments("OPCLabs.KitServer.2", itemId);
arguments[i] = readItemArguments;
}
// Instantiate the client object.
var client = new EasyDAClient();
for (int iRepeat = 1; iRepeat <= RepeatCount; iRepeat++)
{
Console.WriteLine("Reading items...");
DAVtqResult[] vtqResults = client.ReadMultipleItems(arguments);
int successCount = 0;
foreach (DAVtqResult vtqResult in vtqResults)
if (vtqResult.Succeeded)
successCount++;
Console.WriteLine($"Success count: {successCount}");
}
}
}
}
' This example repeatedly reads a large number of items.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' 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.
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.DataAccess.OperationModel
Namespace DataAccess._EasyDAClient
Partial Friend Class ReadMultipleItems
Private Const RepeatCount As Integer = 10
Private Const NumberOfItems As Integer = 1000
Public Shared Sub ManyRepeat()
Console.WriteLine("Creating array of arguments...")
Dim arguments = New DAReadItemArguments(NumberOfItems - 1) {}
For i As Integer = 0 To NumberOfItems - 1
Dim copy As Integer = (i \ 100) + 1
Dim phase As Integer = (i Mod 100)
Dim itemId As String = String.Format($"Simulation.Incrementing.Copy_{copy}.Phase_{phase}")
Console.WriteLine(itemId)
Dim readItemArguments As DAReadItemArguments = New DAReadItemArguments("OPCLabs.KitServer.2", itemId)
arguments(i) = readItemArguments
Next i
' Instantiate the client object.
Dim client = New EasyDAClient()
For iRepeat = 1 To RepeatCount
Console.WriteLine("Reading items...")
Dim vtqResults() As DAVtqResult = client.ReadMultipleItems(arguments)
Dim successCount As Integer = 0
For Each vtqResult In vtqResults
If vtqResult.Succeeded Then
successCount += 1
End If
Next vtqResult
Console.WriteLine($"Success count: {successCount}")
Next iRepeat
End Sub
End Class
End Namespace
// This example shows how to read items while subscribed.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// 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.
using System;
using System.Diagnostics;
using System.Threading;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;
namespace DocExamples.DataAccess._EasyDAClient
{
partial class SubscribeMultipleItems
{
public static void WithRead()
{
// Instantiate the client object.
using (var client = new EasyDAClient())
{
client.ItemChanged += client_Read_ItemChanged;
Console.WriteLine("Subscribing item changes...");
client.SubscribeMultipleItems(
new[] {
new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Random", 1000, null),
new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Sine (1 min)", 1000, null),
});
Console.WriteLine("Waiting for 10 seconds...");
Thread.Sleep(10 * 1000);
Console.WriteLine("Reading items...");
DAVtqResult[] vtqResults = client.ReadMultipleItems("OPCLabs.KitServer.2",
new DAItemDescriptor[]
{
"Trends.Ramp (1 min)", "Trends.Sine (1 min)"
});
for (int i = 0; i < vtqResults.Length; i++)
{
Debug.Assert(vtqResults[i] != null);
if (vtqResults[i].Succeeded)
Console.WriteLine("vtqResults[{0}].Vtq: {1}", i, vtqResults[i].Vtq);
else
Console.WriteLine("vtqResults[{0}] *** Failure: {1}", i, vtqResults[i].ErrorMessageBrief);
}
Console.WriteLine("Waiting for 10 seconds...");
Thread.Sleep(10 * 1000);
Console.WriteLine("Unsubscribing item changes...");
}
Console.WriteLine("Finished.");
}
// Item changed event handler
static void client_Read_ItemChanged(object sender, EasyDAItemChangedEventArgs e)
{
if (e.Succeeded)
Console.WriteLine($"< {e.Arguments.ItemDescriptor.ItemId}: {e.Vtq}");
else
Console.WriteLine($"< {e.Arguments.ItemDescriptor.ItemId} *** Failure: {e.ErrorMessageBrief}");
}
}
}
' This example shows how to read items while subscribed.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' 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.
Imports System.Threading
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.DataAccess.OperationModel
Namespace DataAccess._EasyDAClient
Partial Friend Class SubscribeMultipleItems
Public Shared Sub WithRead()
' Instantiate the client object.
Using client = New EasyDAClient()
AddHandler client.ItemChanged, AddressOf client_Read_ItemChanged
Console.WriteLine("Subscribing item changes...")
Dim handleArray() As Integer = client.SubscribeMultipleItems(New DAItemGroupArguments() {
New DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Random", 1000, Nothing),
New DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Sine (1 min)", 1000, Nothing)
})
Console.WriteLine("Waiting for 10 seconds...")
Thread.Sleep(10 * 1000)
Console.WriteLine("Reading items...")
Dim vtqResults() As DAVtqResult = client.ReadMultipleItems("OPCLabs.KitServer.2",
New DAItemDescriptor() {"Trends.Ramp (1 min)", "Trends.Sine (1 min)"})
For i = 0 To vtqResults.Length - 1
Debug.Assert(vtqResults(i) IsNot Nothing)
If vtqResults(i).Succeeded Then
Console.WriteLine("vtqResult[{0}].Vtq: {1}", i, vtqResults(i).Vtq)
Else
Console.WriteLine("vtqResult[{0}] *** Failure: {1}", i, vtqResults(i).ErrorMessageBrief)
End If
Next i
Console.WriteLine("Waiting for 10 seconds...")
Thread.Sleep(10 * 1000)
Console.WriteLine("Unsubscribing item changes...")
End Using
Console.WriteLine("Finished.")
End Sub
' Item changed event handler
Private Shared Sub client_Read_ItemChanged(ByVal sender As Object, ByVal e As EasyDAItemChangedEventArgs)
If e.Succeeded Then
Console.WriteLine($"< {e.Arguments.ItemDescriptor.ItemId}: {e.Vtq}")
Else
Console.WriteLine($"< {e.Arguments.ItemDescriptor.ItemId} *** Failure: {e.ErrorMessageBrief}")
End If
End Sub
End Class
End Namespace
# This example shows how to read items while subscribed.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# 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.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
import time
# Import .NET namespaces.
from OpcLabs.EasyOpc import *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.DataAccess.OperationModel import *
# Item changed event handler.
def itemChanged(sender, e):
if e.Succeeded:
print('< ', e.Arguments.ItemDescriptor.ItemId, ': ', e.Vtq, sep='')
else:
print('< ', e.Arguments.ItemDescriptor.ItemId, ' *** Failure: ', e.ErrorMessageBrief, sep='')
# Instantiate the client object.
client = EasyDAClient()
client.ItemChanged += itemChanged
print('Subscribing item changes...')
client.SubscribeMultipleItems([
EasyDAItemSubscriptionArguments('', 'OPCLabs.KitServer.2', 'Simulation.Random', 1000, None),
EasyDAItemSubscriptionArguments('', 'OPCLabs.KitServer.2', 'Trends.Sine (1 min)', 1000, None),
])
print('Processing item change notifications for 10 seconds...')
time.sleep(10)
print('Reading items...')
vtqResultArray = client.ReadMultipleItems([
DAReadItemArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Trends.Ramp (1 min)')),
DAReadItemArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Trends.Sine (1 min)')),
])
for i, vtqResult in enumerate(vtqResultArray):
assert vtqResult is not None
if vtqResult.Succeeded:
print('vtqResultArray[', i, '].Vtq: ', vtqResult.Vtq, sep='')
else:
print('vtqResultArray[', i, '] *** Failure: ', vtqResult.ErrorMessageBrief, sep='')
print('Processing item change notifications for 10 seconds...')
time.sleep(10)
print('Unsubscribing all items...')
client.UnsubscribeAllItems()
client.ItemChanged -= itemChanged
print('Finished.')