This commit is contained in:
EonaCat authored and Jeroen Saey committed 2026-11-04 07:53:40 +01:00
1 parent 2c5b69bf2c
commit 22dee59f47
132 files changed
+19653 -7192

No files matched your search

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\EonaCat.Connections.OpcUa\EonaCat.Connections.OpcUa.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,39 @@
using EonaCat.Connections.OpcUa.Configuration;
using EonaCat.Connections.OpcUa.Models;
using EonaCat.Connections.OpcUa.Server;
using Opc.Ua;
const string namespaceUri = "urn:EonaCat:Connector:OpcUa:Example";
await using var server = new OpcUaNetworkServer(new OpcUaServerOptions
{
BaseAddress = "opc.tcp://localhost:4840/EonaCat/Connector",
NamespaceUri = namespaceUri,
AutoAcceptUntrustedCertificates = true,
CheckCertificateRevocation = false
});
server.AddVariable(new OpcUaNodeDefinition("Machine.Temperature", "Temperature", DataTypeIds.Double, 1337.0d, Description: "Current machine temperature in degrees Celsius"))
.AddVariable(new OpcUaNodeDefinition("Machine.Enabled", "Enabled", DataTypeIds.Boolean, true))
.AddMethod(new OpcUaMethodDefinition("Machine.Add", "Add",
[
new OpcUaMethodArgument("Left", DataTypeIds.Double),
new OpcUaMethodArgument("Right", DataTypeIds.Double)
],
[new OpcUaMethodArgument("Result", DataTypeIds.Double)], arguments => [Convert.ToDouble(arguments[0]) + Convert.ToDouble(arguments[1])], "Adds two numbers"));
server.ValueChanged += (_, args) => Console.WriteLine($"Value changed: {args.NodeId} = {args.Value}");
server.Error += (_, exception) => Console.Error.WriteLine(exception);
await server.StartAsync();
Console.WriteLine($"OPC UA server listening on {server.EndpointUrl}");
Console.WriteLine("Press Ctrl+C to stop.");
var stopped = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
Console.CancelKeyPress += (_, eventArgs) =>
{
eventArgs.Cancel = true;
stopped.TrySetResult(true);
};
await stopped.Task;