Skip to content

Commit

Permalink
fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
awcullen committed Dec 17, 2023
1 parent af53521 commit 968b1ed
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 7 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand Down
70 changes: 70 additions & 0 deletions UaClient.UnitTests/IntegrationTests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,76 @@ public async Task Read()
await channel.CloseAsync();
}

/// <summary>
/// Connects to server and reads the current ServerState.
/// </summary>
[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<ServerStatusDataType>();

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);
}
}

/// <summary>
/// Tests polling the current time.
/// Only run this test with a running opc test server.
Expand Down
6 changes: 3 additions & 3 deletions UaClient/Workstation.UaClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<AssemblyName>Workstation.UaClient</AssemblyName>
<RootNamespace>Workstation</RootNamespace>
<Version>3.2.1</Version>
<Version>3.2.2</Version>
<Authors>Andrew Cullen</Authors>
<Company>Converter Systems LLC</Company>
<PackageProjectUrl>https://github.com/convertersystems/opc-ua-client</PackageProjectUrl>
Expand All @@ -13,10 +13,10 @@
<PackageTags>opc, opc-ua, iiot</PackageTags>
<RepositoryUrl>https://github.com/convertersystems/opc-ua-client</RepositoryUrl>
<Copyright>Copyright © 2023 Converter Systems LLC.</Copyright>
<AssemblyVersion>3.2.1.0</AssemblyVersion>
<AssemblyVersion>3.2.2.0</AssemblyVersion>
<AssemblyTitle>Workstation.UaClient ($(TargetFramework))</AssemblyTitle>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<FileVersion>3.2.1.0</FileVersion>
<FileVersion>3.2.2.0</FileVersion>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
<IncludeSymbols>true</IncludeSymbols>
Expand Down

0 comments on commit 968b1ed

Please sign in to comment.