Creates a new item change observable for OPC item, specifying machine name, server class, item ID, requested update rate, and percent deadband.
Syntax
Parameters
- machineName
- Name of the machine (empty string for local computer).
The value represents a UNC or DNS computer name. Any string can be passed to this parameter (i.e. will not cause System.ArgumentException), but not all values make sense and will work when an operation using them is attempted. IPv6 addresses are normally enclosed between '[' and ']'.
The value of this parameter cannot be null
(Nothing
in Visual Basic).
- serverClass
- Contains ProgID of the OPC server.
The value of this parameter cannot be null
(Nothing
in Visual Basic).
- itemId
- ID of the item that will be subscribed to.
The value of this parameter cannot be null
(Nothing
in Visual Basic).
- requestedUpdateRate
- How often should the updates be received (number of milliseconds)
Valid values of this parameter are in the range from -1
to 2147483647 (Int32.MaxValue)
.
Type Parameters
- TValue
Return Value
Returns an observable for changes in the given OPC item.
This method never returns null
(Nothing
in Visual Basic).
Example
// Shows how to create an observable for OPC-DA item changes, and subscribe to it.
//
// 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.Threading;
using OpcLabs.EasyOpc.DataAccess.Reactive;
namespace ReactiveDocExamples
{
namespace _DAItemChangedObservable
{
partial class Subscribe
{
public static void Main1()
{
Console.WriteLine("Creating observable...");
DAItemChangedObservable<double> ramp =
DAItemChangedObservable.Create<double>("", "OPCLabs.KitServer.2", "Demo.Ramp", 1000);
Console.WriteLine("Subscribing...");
using (ramp.Subscribe(e => Console.WriteLine(
(e.Exception is null) ? e.Vtq.ToString() : e.Exception.GetBaseException().ToString())))
{
Console.WriteLine("Waiting for 10 seconds...");
Thread.Sleep(10*1000);
Console.WriteLine("Unsubscribing...");
}
Console.WriteLine("Waiting for 2 seconds...");
Thread.Sleep(2 * 1000);
}
}
}
}
Requirements
Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows
See Also