opc ua client c# open source code example
Example: opc ua client c#
using System;
using System.Threading;
using Opc.UaFx.Client;
public class Program {
public static void Main()
{
using (var client = new OpcClient("opc.tcp://localhost:4840"))
{
client.Connect();
while (true) {
var temperature = client.ReadNode("ns=2;s=Temperature");
Console.WriteLine("Current Temperature is {0} °C", temperature);
Thread.Sleep(1000);
}
}
}
}
using System.Threading;
using Opc.UaFx;
using Opc.UaFx.Server;
class Program
{
public static void Main()
{
var temperatureNode = new OpcDataVariableNode<double>("Temperature", 100.0);
using (var server = new OpcServer("opc.tcp://localhost:4840/", temperatureNode))
{
server.Start();
while (true)
{
if (temperatureNode.Value == 110)
temperatureNode.Value = 100;
else
temperatureNode.Value++;
temperatureNode.ApplyChanges(server.SystemContext);
Thread.Sleep(1000);
}
}
}
}