Push-based notification receiver (observer) that writes incoming values into an attribute of an OPC Unified Architecture node.
Object Model
Syntax
[ComVisible(false)]
[TypeConverter(System.ComponentModel.ExpandableObjectConverter)]
[CLSCompliant(true)]
[ValueControl("OpcLabs.BaseLib.Forms.Common.ObjectSerializationControl, OpcLabs.BaseLibForms, Version=5.80.82.1, Culture=neutral, PublicKeyToken=6faddca41dacb409",
DefaultReadWrite=false,
Export=true,
PageId=10001)]
[Serializable()]
public sealed class UAWriteValueObserver<> : UAReactive, LINQPad.ICustomMemberProvider, OpcLabs.BaseLib.ComTypes._Info, OpcLabs.BaseLib.ComTypes._Object2, System.ICloneable, System.IObserver<TValue>, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable
[ComVisible(false)]
[TypeConverter(System.ComponentModel.ExpandableObjectConverter)]
[CLSCompliant(true)]
[ValueControl("OpcLabs.BaseLib.Forms.Common.ObjectSerializationControl, OpcLabs.BaseLibForms, Version=5.80.82.1, Culture=neutral, PublicKeyToken=6faddca41dacb409",
DefaultReadWrite=false,
Export=true,
PageId=10001)]
[Serializable()]
generic<typename >
public ref class UAWriteValueObserver sealed : public UAReactive, LINQPad.ICustomMemberProvider, OpcLabs.BaseLib.ComTypes._Info, OpcLabs.BaseLib.ComTypes._Object2, System.ICloneable, System.IObserver<TValue>, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable
'Declaration
<ComVisibleAttribute(False)>
<TypeConverterAttribute(System.ComponentModel.ExpandableObjectConverter)>
<CLSCompliantAttribute(True)>
<ValueControlAttribute("OpcLabs.BaseLib.Forms.Common.ObjectSerializationControl, OpcLabs.BaseLibForms, Version=5.80.82.1, Culture=neutral, PublicKeyToken=6faddca41dacb409",
DefaultReadWrite=False,
Export=True,
PageId=10001)>
<SerializableAttribute()>
Public NotInheritable Class UAWriteValueObserver(Of )
Inherits UAReactive
Implements LINQPad.ICustomMemberProvider, OpcLabs.BaseLib.ComTypes._Info, OpcLabs.BaseLib.ComTypes._Object2, System.ICloneable, System.IObserver(Of TValue), System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable
Type Parameters
- TValue
- The type of OPC values received.
Example
.NET
.NET
// Shows how to create an observer that writes values to OPC-UA node, and subscribe it to a generated sequence of values.
// Requires Microsoft Reactive Extensions (Rx).
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
using System;
using System.Reactive.Linq;
using System.Threading;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.Reactive;
namespace ReactiveDocExamples
{
namespace _UAWriteValueObserver
{
class OnNext
{
public static void Main1()
{
// Define which server we will work with.
UAEndpointDescriptor endpointDescriptor =
"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
// or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
// or "https://opcua.demo-this.com:51212/UA/SampleServer/"
Console.WriteLine("Creating source observable, 0..9 in 1 second intervals...");
IObservable<int> source = Observable.Generate(0, i => i < 10, i => i + 1, i => i, i => TimeSpan.FromSeconds(1));
Console.WriteLine("Creating observer to write values into OPC node...");
UAWriteValueObserver<int> observer =
UAWriteValueObserver.Create<int>(
endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10389");
Console.WriteLine("Monitoring changes of the target OPC node using traditional means...");
int handle = EasyUAClient.SharedInstance.SubscribeDataChange(
endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10389",
100, (_, e) => Console.WriteLine(e.AttributeData));
Console.WriteLine("Subscribing the observer to source observable...");
source.Subscribe(observer);
Console.WriteLine("Waiting for 10 seconds...");
Thread.Sleep(10 * 1000);
Console.WriteLine("Finalizing monitoring...");
EasyUAClient.SharedInstance.UnsubscribeMonitoredItem(handle);
Console.WriteLine("Waiting for 2 seconds...");
Thread.Sleep(2 * 1000);
}
}
}
}
// Shows how to continuously transform values of OPC-UA node, and write the results into a second node.
// Requires Microsoft Reactive Extensions (Rx).
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
using System;
using System.Reactive.Linq;
using System.Threading;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.Reactive;
namespace ReactiveDocExamples
{
namespace _UAReactive
{
class Composition
{
public static void Pipeline()
{
// Define which server we will work with.
UAEndpointDescriptor endpointDescriptor =
"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
// or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
// or "https://opcua.demo-this.com:51212/UA/SampleServer/"
Console.WriteLine("Creating source observable...");
UADataChangeNotificationObservable<int> source =
UADataChangeNotificationObservable.Create<int>(
endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=11017", 100);
Console.WriteLine("Creating processed observable (takes valid input values and take modulo 1000)...");
IObservable<int> processed = source
.Where(e => e.Exception is null)
.Select(e => e.TypedAttributeData.TypedValue % 1000);
Console.WriteLine("Creating observer to write values into OPC node...");
UAWriteValueObserver<int> observer =
UAWriteValueObserver.Create<int>(
endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10389");
Console.WriteLine("Monitoring changes of the target OPC node using traditional means...");
int handle = EasyUAClient.SharedInstance.SubscribeDataChange(
endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10389",
100, (_, e) => Console.WriteLine(e.AttributeData));
Console.WriteLine("Subscribing the observer to the processed observable...");
using (processed.Subscribe(observer))
{
Console.WriteLine("Waiting for 10 seconds...");
Thread.Sleep(10 * 1000);
Console.WriteLine("Unsubscribing the observer from the processed observable...");
}
Console.WriteLine("Finalizing monitoring...");
EasyUAClient.SharedInstance.UnsubscribeMonitoredItem(handle);
Console.WriteLine("Waiting for 2 seconds...");
Thread.Sleep(2 * 1000);
}
}
}
}
Inheritance Hierarchy
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