From 968b1ed4683da78ab26e0efbb08e1051b2f76e69 Mon Sep 17 00:00:00 2001 From: Andrew Cullen Date: Sat, 16 Dec 2023 22:02:17 -0500 Subject: [PATCH] fix readme --- README.md | 7 +- .../IntegrationTests/IntegrationTests.cs | 70 +++++++++++++++++++ UaClient/Workstation.UaClient.csproj | 6 +- 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e3e8495..1a1bfa4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # opc-ua-client -[![Actions Status](https://github.com/convertersystems/opc-ua-client/workflows/Unit%20Tests/badge.svg)](https://github.com/convertersystems/opc-ua-client/actions) +[![Actions Status](https://github.com/convertersystems/opc-ua-client/actions/workflows/dotnet.yml/badge.svg)](https://github.com/convertersystems/opc-ua-client/actions) Communicate using OPC Unified Architecture and Visual Studio. With this library, your app can browse, read, write and subscribe to the live data published by the OPC UA servers on your network. @@ -40,7 +40,7 @@ public class Program clientDescription, null, // no x509 certificates new AnonymousIdentity(), // no user identity - "opc.tcp://opcua.rocks:4840", // the public endpoint of a server at opcua.rocks. + "opc.tcp://opcua.umati.app:4840", // the public endpoint of the umati sample server. SecurityPolicyUris.None); // no encryption try { @@ -93,10 +93,9 @@ public class Program // Server status: // ProductName: open62541 OPC UA Server -// SoftwareVersion: 1.0.0-rc5-52-g04067153-dirty +// SoftwareVersion: 1.4.0-rc1 // ManufacturerName: open62541 // State: Running - ``` ### Model, View, ViewModel (MVVM) diff --git a/UaClient.UnitTests/IntegrationTests/IntegrationTests.cs b/UaClient.UnitTests/IntegrationTests/IntegrationTests.cs index 15693fa..733be41 100644 --- a/UaClient.UnitTests/IntegrationTests/IntegrationTests.cs +++ b/UaClient.UnitTests/IntegrationTests/IntegrationTests.cs @@ -292,6 +292,76 @@ public async Task Read() await channel.CloseAsync(); } + /// + /// Connects to server and reads the current ServerState. + /// + [Fact] + public async Task ReadMe() + { + // describe this client application. + var clientDescription = new ApplicationDescription + { + ApplicationName = "Workstation.UaClient.FeatureTests", + ApplicationUri = $"urn:{System.Net.Dns.GetHostName()}:Workstation.UaClient.FeatureTests", + ApplicationType = ApplicationType.Client + }; + + // create a 'ClientSessionChannel', a client-side channel that opens a 'session' with the server. + var channel = new ClientSessionChannel( + clientDescription, + null, // no x509 certificates + new AnonymousIdentity(), // no user identity + "opc.tcp://opcua.umati.app:4840", // the public endpoint of the umati sample server. + SecurityPolicyUris.None); // no encryption + try + { + // try opening a session and reading a few nodes. + await channel.OpenAsync(); + + logger.LogInformation($"Opened session with endpoint '{channel.RemoteEndpoint.EndpointUrl}'."); + logger.LogInformation($"SecurityPolicy: '{channel.RemoteEndpoint.SecurityPolicyUri}'."); + logger.LogInformation($"SecurityMode: '{channel.RemoteEndpoint.SecurityMode}'."); + logger.LogInformation($"UserIdentityToken: '{channel.UserIdentity}'."); + + // build a ReadRequest. See 'OPC UA Spec Part 4' paragraph 5.10.2 + var readRequest = new ReadRequest + { + // set the NodesToRead to an array of ReadValueIds. + NodesToRead = new[] { + // construct a ReadValueId from a NodeId and AttributeId. + new ReadValueId { + // you can parse the nodeId from a string. + // e.g. NodeId.Parse("ns=2;s=Demo.Static.Scalar.Double") + NodeId = NodeId.Parse(VariableIds.Server_ServerStatus), + // variable class nodes have a Value attribute. + AttributeId = AttributeIds.Value + } + } + }; + // send the ReadRequest to the server. + var readResult = await channel.ReadAsync(readRequest); + + // DataValue is a class containing value, timestamps and status code. + // the 'Results' array returns DataValues, one for every ReadValueId. + var serverStatus = readResult.Results[0].GetValueOrDefault(); + + logger.LogInformation("\nServer status:"); + logger.LogInformation(" ProductName: {0}", serverStatus.BuildInfo.ProductName); + logger.LogInformation(" SoftwareVersion: {0}", serverStatus.BuildInfo.SoftwareVersion); + logger.LogInformation(" ManufacturerName: {0}", serverStatus.BuildInfo.ManufacturerName); + logger.LogInformation(" State: {0}", serverStatus.State); + logger.LogInformation(" CurrentTime: {0}", serverStatus.CurrentTime); + + logger.LogInformation($"\nClosing session '{channel.SessionId}'."); + await channel.CloseAsync(); + } + catch (Exception ex) + { + await channel.AbortAsync(); + logger.LogInformation(ex.Message); + } + } + /// /// Tests polling the current time. /// Only run this test with a running opc test server. diff --git a/UaClient/Workstation.UaClient.csproj b/UaClient/Workstation.UaClient.csproj index 2b8a20e..72fce77 100644 --- a/UaClient/Workstation.UaClient.csproj +++ b/UaClient/Workstation.UaClient.csproj @@ -4,7 +4,7 @@ netstandard2.0;net6.0 Workstation.UaClient Workstation - 3.2.1 + 3.2.2 Andrew Cullen Converter Systems LLC https://github.com/convertersystems/opc-ua-client @@ -13,10 +13,10 @@ opc, opc-ua, iiot https://github.com/convertersystems/opc-ua-client Copyright © 2023 Converter Systems LLC. - 3.2.1.0 + 3.2.2.0 Workstation.UaClient ($(TargetFramework)) true - 3.2.1.0 + 3.2.2.0 True Key.snk true