godsharp - GodSharp.Extensions.Opc.Ua.Client 2022.205.10.1
Opc.Ua produced by GodSharp
PM> Install-Package GodSharp.Extensions.Opc.Ua.Client -Version 2022.205.10.1 -Source https://www.myget.org/F/godsharp/api/v3/index.json
> nuget.exe install GodSharp.Extensions.Opc.Ua.Client -Version 2022.205.10.1 -Source https://www.myget.org/F/godsharp/api/v3/index.json
> dotnet add package GodSharp.Extensions.Opc.Ua.Client --version 2022.205.10.1 --source https://www.myget.org/F/godsharp/api/v3/index.json
<PackageReference Include="GodSharp.Extensions.Opc.Ua.Client" Version="2022.205.10.1" />
Copy to clipboard
source https://www.myget.org/F/godsharp/api/v3/index.json
nuget GodSharp.Extensions.Opc.Ua.Client ~> 2022.205.10.1
Copy to clipboard
> choco install GodSharp.Extensions.Opc.Ua.Client --version 2022.205.10.1 --source https://www.myget.org/F/godsharp/api/v2
Import-Module PowerShellGet
Register-PSRepository -Name "godsharp" -SourceLocation "https://www.myget.org/F/godsharp/api/v2"
Install-Module -Name "GodSharp.Extensions.Opc.Ua.Client" -RequiredVersion "2022.205.10.1" -Repository "godsharp"
Copy to clipboard
GodSharp.Extensions.Opc.Ua
Package Version
Introduction
| Package | Uasge |
|---|---|
| GodSharp.Extensions.Opc.Ua | extensions library for opc ua |
| GodSharp.Extensions.Opc.Ua.Client | extensions library for opc ua client |
| GodSharp.Extensions.Opc.Ua.Generator | attributes for CodeGenerator |
| GodSharp.Extensions.Opc.Ua.CodeGenerator | generate encode/decode method for EncodeableObject class by DIY |
| GodSharp.Extensions.Opc.Ua.MsBuild | generate code for which class with ComplexObjectGenerator attribute |
| GodSharp.Opc.Ua.Client | a Sample opc ua client |
Getting Started
PM> Install-Package GodSharp.Opc.Ua.Client
Discovery Server
Sample code:
var url = "opc.tcp://127.0.0.1:4840";
OpcUaServerDiscovery discovery = new OpcUaServerDiscovery();
Console.WriteLine("discovery Discovery");
var servers = discovery.Discovery(url);
foreach (var item in servers)
{
foreach (var durl in item.DiscoveryUrls)
{
Console.WriteLine($"{durl}");
var endpoints = discovery.GetEndpoints(durl);
if (endpoints == null) continue;
foreach (var endpoint in endpoints)
{
Console.WriteLine($"\t- {endpoint.EndpointUrl}/ {endpoint.SecurityMode}/ {endpoint.SecurityPolicyUri}");
}
}
}
Console.WriteLine("discovery DiscoveryUrls");
var discoverys = discovery.DiscoveryUrls(url);
if (discoverys != null)
{
foreach (var discoveryUrl in discoverys)
{
Console.WriteLine($"{discoveryUrl}");
var endpoints = discovery.GetEndpoints(discoveryUrl);
if (endpoints == null) continue;
foreach (var endpoint in endpoints)
{
Console.WriteLine($"\t- {endpoint.EndpointUrl}/ {endpoint.SecurityMode}/ {endpoint.SecurityPolicyUri}");
}
}
}
Console.WriteLine("discovery finished");
Browse / BrowseTree
Browse: To browse node list with specialized node or default.
BrowseTree: To browse node tree with specialized node or default.
Sample code:
// To browse node list with specialized node or default var all = client.Session.Browse(); //var browse = client.Session.Browse(new NodeId ("ns=4;s=Demo.Static")); Console.WriteLine(" DisplayName, BrowseName, NodeClass"); foreach (var obj in all) { Console.WriteLine(" {0}, {1}, {2}", obj.DisplayName, obj.BrowseName, obj.NodeClass); var browse2 = client.Session.Browse((NodeId)obj.NodeId); foreach (var refd in browse2) { Console.WriteLine(" + {0}, {1}, {2}", refd.DisplayName, refd.BrowseName, refd.NodeClass); } } // To browse node tree with specialized node or default var tree = client.Session.BrowseTree(); //var tree = client.Session.BrowseTree(new NodeId ("ns=4;s=Demo.Static")); Browse(tree); static void Browse(IEnumerable<ReferenceBrowseDescription> refs, int level = -1) { level++; foreach (var description in refs) { Console.WriteLine("{0}{4}+{1}, {2},{3}", new string('\t', level), //Formatter.FormatAttributeValue (attribute.ValueId.AttributeId, attribute.Value)} //description.Node.BrowseName, description.GetFormatText(), description.Node.NodeClass, description.Node.NodeId, level ); if (description.Children != null) { Browse(description.Children, level); } } }
GetAttributes / GetProperties
Sample code:
var node = new NodeId("ns=0;i=2258"); // 2258 Server.ServerStatus.CurrentTime
var attributes = client.Session.GetAttributes(node);
foreach (var attribute in attributes)
{
Console.WriteLine($"{attribute.Name}: {attribute.ValueText}");
}
var properties = client.Session.GetProperties(node);
if (properties != null)
{
foreach (var attribute in properties)
{
Console.WriteLine($"{attribute.Name}: {Formatter.FormatAttributeValue (attribute.ValueId.AttributeId, attribute.Value, client.Session)}");
}
}
Subscribe / Unsubscribe
Sample code:
var sub_name = "andon";
var subscribes = new string[] { "ns=0;i=2258", "ns=0;i=2259" };
// 2258 Server.ServerStatus.CurrentTime
// 2259 Server.ServerStatus.State
client.Subscribe(sub_name, subscribes);
Console.WriteLine("Press any key to Unsubscribe");
Console.ReadLine();
client.Unsubscribe(sub_name);
Read Node
Sample code:
T val = client.Session.Read<T>(node);
// or
DataValue val = client.Session.Read(node);
Write Node
Sample code:
var ret = client.Session.Write(node, value);
MsBuild
Generate code for which class is customized with ComplexObjectGenerator attribute, the class generated is implement ComplexObject.
PM> Install-Package GodSharp.Extensions.Opc.Ua.Generator
PM> Install-Package GodSharp.Extensions.Opc.Ua.MsBuild
ComplexObject class types:
[DefaultValue(ComplexObjectType.EncodeableObject)]
public enum ComplexObjectType
{
EncodeableObject,
SwitchField,
OptionalField
}
Sample code:
[ComplexObjectGenerator(ComplexObjectType.SwitchField, EncodingMethodType.Factory)]
public partial class UaAnsiUnion
{
[SwitchField(1)]
public int Int32;
[SwitchField(2, 4)]
public string String;
public UaAnsiUnion()
{
TypeIdNamespace = "nsu=http://www.unifiedautomation.com/DemoServer/;i=3006";
BinaryEncodingIdNamespace = "nsu=http://www.unifiedautomation.com/DemoServer/;i=5003";
}
}
Just build project, code will be generated by msbuild task in the file with extension {filename}.uamgen.cs by default.
like this:
//----------------------------------------------------------- - ------------------
// <auto-generated>
// Generated by MSBuild generator.
// Source: UaAnsiUnion.cs
// </auto-generated>
//----------------------------------------------------------- - ------------------
using GodSharp.Extensions.Opc.Ua.Types;
using Opc.Ua;
using static GodSharp.Extensions.Opc.Ua.Types.Encodings.EncodingFactory;
namespace GodSharpOpcUaClientSample.Types
{
public partial class UaAnsiUnion : ComplexObject
{
public uint SwitchField;
public override void Encode(IEncoder encoder)
{
base.Encode(encoder);
encoder.WriteUInt32("SwitchField",SwitchField);
switch (SwitchField)
{
case 1:
Encoding.Write(encoder, Int32, nameof (Int32));
break;
case 2:
case 4:
Encoding.Write(encoder, String, nameof (String));
break;
default:
break;
}
}
public override void Decode(IDecoder decoder)
{
base.Decode(decoder);
SwitchField = decoder.ReadUInt32("SwitchField");
switch (SwitchField)
{
case 1:
Encoding.Read(decoder,ref Int32, nameof (Int32));
break;
case 2:
case 4:
Encoding.Read(decoder,ref String, nameof (String));
break;
default:
break;
}
}
}
}
Register Custom Types
Register Custom Type Namespace
You can register custom type namespace by hard code in constructor.
Sample code:
[ComplexObjectGenerator(ComplexObjectType.SwitchField, EncodingMethodType.Factory)]
public partial class UaAnsiUnion
{
[SwitchField(1)]
public int Int32;
[SwitchField(2, 4)]
public string String;
public UaAnsiUnion()
{
TypeIdNamespace = "nsu=http:// www.unifiedautomation.com/DemoServer/;i=3006";
BinaryEncodingIdNamespace = "nsu=http:// www.unifiedautomation.com/DemoServer/;i=5003";
}
}
Also can support by configuration from file or db,and others.
Sample code:
EncodingFactory.Instance.RegisterTypeNamespace(
new TypeNamespace()
{
Type = typeof(UaAnsiVector).AssemblyQualifiedName,
TypeId = "nsu=http://www.unifiedautomation.com/ DemoServer/;i=3002",
BinaryEncodingId = "nsu=http://www.unifiedautomation.com/ DemoServer/;i=5054"
}
);
Register Custom Type to System
Sample code:
EncodingFactory.Instance.RegisterEncodeableTypes(typeof(UaAnsiVector), typeof(UaAnsiVector));
EncodingFactory.Instance.RegisterEncodeableTypes(Assembly.GetEntryAssembly(),Assembly.GetExecutingAssembly());
Contact
- QQ Qun: 467764581
- QQ: 2267930027
- Email: seayxu@163.com
License
Free!
-
.NETFramework 4.6
- GodSharp.Extensions.Opc.Ua (>= 2022.205.10.1)
- System.ValueTuple (>= 4.5.0)
-
.NETFramework 4.6.2
- GodSharp.Extensions.Opc.Ua (>= 2022.205.10.1)
- OPCFoundation.NetStandard.Opc.Ua.Client (>= 1.4.363.107)
- System.ValueTuple (>= 4.5.0)
-
.NETStandard 2.0
- GodSharp.Extensions.Opc.Ua (>= 2022.205.10.1)
- OPCFoundation.NetStandard.Opc.Ua.Client (>= 1.4.363.107)
- System.ValueTuple (>= 4.5.0)
-
.NETStandard 2.1
- GodSharp.Extensions.Opc.Ua (>= 2022.205.10.1)
- OPCFoundation.NetStandard.Opc.Ua.Client (>= 1.4.363.107)
- System.ValueTuple (>= 4.5.0)
- .NETFramework 4.6: 4.6.0.0
- .NETFramework 4.6.2: 4.6.2.0
- .NETStandard 2.0: 2.0.0.0
- .NETStandard 2.1: 2.1.0.0
OwnersSeay |
Authorsseayxu |
Project URLhttps://github.com/godsharp/opcua.extensions |
LicenseUnknown |
TagsOpcUa Opc Ua GodSharp |
Info429 total downloads |
| 76 downloads for version 2022.205.10.1 |
| Download (224.07 KB) |
| Found on the current feed only |
Package history
| Version | Size | Last updated | Downloads | Mirrored? | |||
|---|---|---|---|---|---|---|---|
|
|
2022.205.10.1 | 224.07 KB | Thu, 12 May 2022 06:31:00 GMT | 76 |
|
||
|
|
2022.205.10 | 224.05 KB | Thu, 12 May 2022 03:56:39 GMT | 78 |
|
||
|
|
2021.411.18 | 224.21 KB | Thu, 18 Nov 2021 10:48:30 GMT | 74 |
|
||
|
|
2021.411.4 | 185.8 KB | Thu, 04 Nov 2021 08:04:02 GMT | 64 |
|
||
|
|
2021.309.1 | 185.82 KB | Wed, 22 Sep 2021 16:46:16 GMT | 70 |
|
||
|
|
2021.308.1 | 170.57 KB | Tue, 31 Aug 2021 06:13:50 GMT | 67 |
|