Updated
This commit is contained in:
1 parent
2c5b69bf2c
commit
22dee59f47
132 files changed
+19653
-7192
No files matched your search
@@ -0,0 +1,41 @@
|
||||
using EonaCat.Connections.OpcUa.Client;
|
||||
using EonaCat.Connections.OpcUa.Configuration;
|
||||
|
||||
const string endpointUrl = "opc.tcp://localhost:4840/EonaCat/Connector";
|
||||
const string namespaceUri = "urn:EonaCat:Connector:OpcUa:Example";
|
||||
|
||||
await using var client = new OpcUaNetworkClient(new OpcUaClientOptions
|
||||
{
|
||||
EndpointUrl = endpointUrl,
|
||||
UseSecurity = false,
|
||||
AutoAcceptUntrustedCertificates = true,
|
||||
CheckCertificateRevocation = false
|
||||
});
|
||||
|
||||
client.Error += (_, exception) => Console.Error.WriteLine(exception);
|
||||
if (!await client.ConnectAsync())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var temperatureNode = client.GetNodeId(namespaceUri, "Machine.Temperature");
|
||||
var enabledNode = client.GetNodeId(namespaceUri, "Machine.Enabled");
|
||||
var addMethod = client.GetNodeId(namespaceUri, "Machine.Add");
|
||||
var rootNode = client.GetNodeId(namespaceUri, "EonaCat");
|
||||
|
||||
await using var subscription = await client.SubscribeAsync([temperatureNode, enabledNode], (_, args) => Console.WriteLine($"Subscription: {args.NodeId} = {args.Value}"));
|
||||
var temperature = await client.ReadAsync(temperatureNode);
|
||||
Console.WriteLine($"Temperature: {temperature.Value}");
|
||||
|
||||
await client.WriteAsync(temperatureNode, 42.0d);
|
||||
var result = await client.CallAsync(rootNode, addMethod, [2.0d, 3.5d]);
|
||||
Console.WriteLine($"2 + 3.5 = {result[0]}");
|
||||
|
||||
var children = await client.BrowseAsync(rootNode);
|
||||
foreach (var child in children)
|
||||
{
|
||||
Console.WriteLine($"{child.NodeClass}: {child.DisplayName} ({child.NodeId})");
|
||||
}
|
||||
|
||||
await Task.Delay(1_500);
|
||||
Console.ReadKey();
|
||||
Reference in new issue
Block a user