No problem - here is the example (you may have to re-reference the assemblies, but besides this, it should be buildable):
It subscribes to three OPC Unified Architecture node values, and shows them updating in WPF TextBox-es.
And here is the relevant part of code:
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void ClientOnMonitoredItemChanged(object sender, EasyUAMonitoredItemChangedEventArgs eventArgs)
{
// We have passed in a reference to the target TextBox as the State property in EasyUAMonitoredItemArguments.
var textBox = (TextBox) eventArgs.Arguments.State;
if (eventArgs.Succeeded)
textBox.Text = eventArgs.AttributeData.DisplayValue();
else
textBox.Text = "*** Error";
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// Define the target controls, the OPC data we want to monitor, and how fast.
var arguments = new []
{
new EasyUAMonitoredItemArguments(TextBox1, "http://localhost:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10845", 1000),
new EasyUAMonitoredItemArguments(TextBox2, "http://localhost:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10853", 1000),
new EasyUAMonitoredItemArguments(TextBox3, "http://localhost:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10855", 1000)
};
// Hook the event handler, and subscribe to OPC data
_client.MonitoredItemChanged += ClientOnMonitoredItemChanged;
_handles = _client.SubscribeMultipleMonitoredItems(arguments);
}
private void Window_Unloaded(object sender, RoutedEventArgs e)
{
// Unsubscribe from OPC data, and unhook the event handler
_client.UnsubscribeMultipleMonitoredItems(_handles);
_client.MonitoredItemChanged -= ClientOnMonitoredItemChanged;
}
private readonly EasyUAClient _client = new EasyUAClient();
private int[] _handles;
}
Note that the connection-less nature of our API makes this into a fully usable application: No extra code is needed to achieve complete resiliency against network failures, server shutdowns etc. - it will reconnect itself in case of problems.
Best regards