This commit is contained in:
luosheng
2023-05-29 10:32:25 +08:00
parent 3870c41256
commit 050ed78c3b
16 changed files with 40 additions and 44 deletions

View File

@@ -1,7 +1,7 @@
using System; using System;
using System.Linq; using System.Linq;
namespace Modbus.Net.OPC namespace Modbus.Net.Opc
{ {
/// <summary> /// <summary>
/// Opc地址编码器 /// Opc地址编码器

View File

@@ -1,6 +1,6 @@
using System; using System;
namespace Modbus.Net.OPC namespace Modbus.Net.Opc
{ {
/// <summary> /// <summary>
/// Opc地址解析器 /// Opc地址解析器

View File

@@ -5,7 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Modbus.Net.OPC namespace Modbus.Net.Opc
{ {
/// <summary> /// <summary>
/// Opc Client Extend interface, Unified for DA and UA /// Opc Client Extend interface, Unified for DA and UA
@@ -18,7 +18,7 @@ namespace Modbus.Net.OPC
Node RootNodeBase { get; } Node RootNodeBase { get; }
/// <summary> /// <summary>
/// Connect the client to the OPC Server /// Connect the client to the Opc Server
/// </summary> /// </summary>
void Connect(); void Connect();
@@ -30,11 +30,11 @@ namespace Modbus.Net.OPC
/// The fully-qualified identifier of the tag. You can specify a subfolder by using a comma delimited name. /// The fully-qualified identifier of the tag. You can specify a subfolder by using a comma delimited name.
/// E.g: the tag `foo.bar` reads the tag `bar` on the folder `foo` /// E.g: the tag `foo.bar` reads the tag `bar` on the folder `foo`
/// </param> /// </param>
/// <returns>The value retrieved from the OPC</returns> /// <returns>The value retrieved from the Opc</returns>
ReadEvent<T> Read<T>(string tag); ReadEvent<T> Read<T>(string tag);
/// <summary> /// <summary>
/// Write a value on the specified opc tag /// Write a value on the specified Opc tag
/// </summary> /// </summary>
/// <typeparam name="T">The type of tag to write on</typeparam> /// <typeparam name="T">The type of tag to write on</typeparam>
/// <param name="tag"> /// <param name="tag">
@@ -50,7 +50,7 @@ namespace Modbus.Net.OPC
Task<ReadEvent<T>> ReadAsync<T>(string tag); Task<ReadEvent<T>> ReadAsync<T>(string tag);
/// <summary> /// <summary>
/// Write a value on the specified opc tag asynchronously /// Write a value on the specified Opc tag asynchronously
/// </summary> /// </summary>
Task WriteAsync<T>(string tag, T item); Task WriteAsync<T>(string tag, T item);

View File

@@ -3,16 +3,16 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net462</TargetFramework> <TargetFramework>net462</TargetFramework>
<LangVersion>10.0</LangVersion> <LangVersion>10.0</LangVersion>
<AssemblyName>Modbus.Net.OPC</AssemblyName> <AssemblyName>Modbus.Net.Opc</AssemblyName>
<RootNamespace>Modbus.Net.OPC</RootNamespace> <RootNamespace>Modbus.Net.Opc</RootNamespace>
<PackageId>Modbus.Net.OPC</PackageId> <PackageId>Modbus.Net.Opc</PackageId>
<Version>1.4.1</Version> <Version>1.4.1</Version>
<Authors>Chris L.(Luo Sheng)</Authors> <Authors>Chris L.(Luo Sheng)</Authors>
<Company>Hangzhou Delian Science Technology Co.,Ltd.</Company> <Company>Hangzhou Delian Science Technology Co.,Ltd.</Company>
<Product>Modbus.Net.OPC</Product> <Product>Modbus.Net.Opc</Product>
<Description>Modbus.Net OPC Implementation</Description> <Description>Modbus.Net Opc Implementation</Description>
<Copyright>Copyright 2023 Hangzhou Delian Science Technology Co.,Ltd.</Copyright> <Copyright>Copyright 2023 Hangzhou Delian Science Technology Co.,Ltd.</Copyright>
<PackageProjectUrl>https://github.com/parallelbgls/Modbus.Net/tree/master/Modbus.Net/Modbus.Net.OPC</PackageProjectUrl> <PackageProjectUrl>https://github.com/parallelbgls/Modbus.Net/tree/master/Modbus.Net/Modbus.Net.Opc</PackageProjectUrl>
<RepositoryUrl>https://github.com/parallelbgls/Modbus.Net</RepositoryUrl> <RepositoryUrl>https://github.com/parallelbgls/Modbus.Net</RepositoryUrl>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<PackageTags>hardware communicate protocol modbus Delian</PackageTags> <PackageTags>hardware communicate protocol modbus Delian</PackageTags>
@@ -26,7 +26,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\Modbus.Net.OPC.xml</DocumentationFile> <DocumentationFile>bin\Debug\Modbus.Net.Opc.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -6,7 +6,7 @@ using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Modbus.Net.OPC namespace Modbus.Net.Opc
{ {
/// <summary> /// <summary>
/// Opc连接器 /// Opc连接器
@@ -62,12 +62,12 @@ namespace Modbus.Net.OPC
Client?.Dispose(); Client?.Dispose();
Client = null; Client = null;
_connect = false; _connect = false;
logger.LogInformation("opc client {ConnectionToken} disconnected success", ConnectionToken); logger.LogInformation("Opc client {ConnectionToken} disconnected success", ConnectionToken);
return true; return true;
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError(ex, "opc client {ConnectionToken} disconnected error", ConnectionToken); logger.LogError(ex, "Opc client {ConnectionToken} disconnected error", ConnectionToken);
_connect = false; _connect = false;
return false; return false;
} }
@@ -109,7 +109,7 @@ namespace Modbus.Net.OPC
if (answerTag != null) if (answerTag != null)
{ {
var result = await Client.ReadAsync<object>(answerTag); var result = await Client.ReadAsync<object>(answerTag);
logger.LogDebug($"Opc Machine {ConnectionToken} Read opc tag {answerTag} for value {result.Value}"); logger.LogDebug($"Opc Machine {ConnectionToken} Read Opc tag {answerTag} for value {result.Value}");
return new OpcParamOut return new OpcParamOut
{ {
Success = true, Success = true,
@@ -135,11 +135,11 @@ namespace Modbus.Net.OPC
try try
{ {
await Client.WriteAsync(answerTag, value); await Client.WriteAsync(answerTag, value);
logger.LogDebug($"Opc Machine {ConnectionToken} Write opc tag {answerTag} for value {value}"); logger.LogDebug($"Opc Machine {ConnectionToken} Write Opc tag {answerTag} for value {value}");
} }
catch (Exception e) catch (Exception e)
{ {
logger.LogError(e, "opc client {ConnectionToken} write exception", ConnectionToken); logger.LogError(e, "Opc client {ConnectionToken} write exception", ConnectionToken);
return new OpcParamOut return new OpcParamOut
{ {
Success = false Success = false
@@ -158,7 +158,7 @@ namespace Modbus.Net.OPC
} }
catch (Exception e) catch (Exception e)
{ {
logger.LogError(e, "opc client {ConnectionToken} read exception", ConnectionToken); logger.LogError(e, "Opc client {ConnectionToken} read exception", ConnectionToken);
return new OpcParamOut return new OpcParamOut
{ {
Success = false, Success = false,
@@ -197,12 +197,12 @@ namespace Modbus.Net.OPC
{ {
Client.Connect(); Client.Connect();
_connect = true; _connect = true;
logger.LogInformation("opc client {ConnectionToken} connect success", ConnectionToken); logger.LogInformation("Opc client {ConnectionToken} connect success", ConnectionToken);
return true; return true;
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError(ex, "opc client {ConnectionToken} connected failed", ConnectionToken); logger.LogError(ex, "Opc client {ConnectionToken} connected failed", ConnectionToken);
_connect = false; _connect = false;
return false; return false;
} }

View File

@@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Modbus.Net.OPC namespace Modbus.Net.Opc
{ {
/// <summary> /// <summary>
/// Opc DA连接实现 /// Opc DA连接实现

View File

@@ -1,6 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Modbus.Net.OPC namespace Modbus.Net.Opc
{ {
/// <summary> /// <summary>
/// Opc Da协议 /// Opc Da协议

View File

@@ -1,6 +1,4 @@
namespace Modbus.Net.Opc
namespace Modbus.Net.OPC
{ {
/// <summary> /// <summary>
/// Opc Da协议连接器 /// Opc Da协议连接器

View File

@@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Modbus.Net.OPC namespace Modbus.Net.Opc
{ {
/// <summary> /// <summary>
/// Opc设备 /// Opc设备
@@ -17,7 +17,7 @@ namespace Modbus.Net.OPC
/// <param name="connectionString">连接地址</param> /// <param name="connectionString">连接地址</param>
/// <param name="getAddresses">需要读写的地址</param> /// <param name="getAddresses">需要读写的地址</param>
/// <param name="isRegexOn">开启正则匹配</param> /// <param name="isRegexOn">开启正则匹配</param>
protected OpcMachine(TKey id, OpcType connectionType, string connectionString, IEnumerable<AddressUnit<TUnitKey>> getAddresses, bool isRegexOn = false) public OpcMachine(TKey id, OpcType connectionType, string connectionString, IEnumerable<AddressUnit<TUnitKey>> getAddresses, bool isRegexOn = false)
: base(id, getAddresses, true) : base(id, getAddresses, true)
{ {
BaseUtility = new OpcUtility(connectionType, connectionString, isRegexOn); BaseUtility = new OpcUtility(connectionType, connectionString, isRegexOn);

View File

@@ -1,4 +1,4 @@
namespace Modbus.Net.OPC namespace Modbus.Net.Opc
{ {
/// <summary> /// <summary>
/// Opc协议 /// Opc协议

View File

@@ -1,7 +1,7 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Modbus.Net.OPC namespace Modbus.Net.Opc
{ {
/// <summary> /// <summary>
/// Opc协议连接器 /// Opc协议连接器

View File

@@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Modbus.Net.OPC namespace Modbus.Net.Opc
{ {
/// <summary> /// <summary>
/// Opc UA连接实现 /// Opc UA连接实现
@@ -28,7 +28,7 @@ namespace Modbus.Net.OPC
/// </summary> /// </summary>
/// <param name="host">Opc UA服务地址</param> /// <param name="host">Opc UA服务地址</param>
/// <param name="isRegexOn">是否开启正则匹配</param> /// <param name="isRegexOn">是否开启正则匹配</param>
/// <returns>OPC UA实例</returns> /// <returns>Opc UA实例</returns>
public static OpcUaConnector Instance(string host, bool isRegexOn) public static OpcUaConnector Instance(string host, bool isRegexOn)
{ {
if (!_instances.ContainsKey(host)) if (!_instances.ContainsKey(host))

View File

@@ -1,6 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Modbus.Net.OPC namespace Modbus.Net.Opc
{ {
/// <summary> /// <summary>
/// Opc UA协议 /// Opc UA协议

View File

@@ -1,6 +1,4 @@
using System.Configuration; namespace Modbus.Net.Opc
namespace Modbus.Net.OPC
{ {
/// <summary> /// <summary>
/// Opc UA协议连接器 /// Opc UA协议连接器

View File

@@ -2,7 +2,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Modbus.Net.OPC namespace Modbus.Net.Opc
{ {
/// <summary> /// <summary>
/// Opc类型 /// Opc类型
@@ -73,9 +73,9 @@ namespace Modbus.Net.OPC
/// <param name="isRegexOn">是否开启正则匹配</param> /// <param name="isRegexOn">是否开启正则匹配</param>
public OpcUtility(int connectionType, string connectionString, bool isRegexOn = false) : base(0, 0) public OpcUtility(int connectionType, string connectionString, bool isRegexOn = false) : base(0, 0)
{ {
OpcType = (OpcType)connectionType;
ConnectionString = connectionString; ConnectionString = connectionString;
IsRegexOn = isRegexOn; IsRegexOn = isRegexOn;
OpcType = (OpcType)connectionType;
AddressTranslator = new AddressTranslatorOpc(); AddressTranslator = new AddressTranslatorOpc();
} }
@@ -87,9 +87,9 @@ namespace Modbus.Net.OPC
/// <param name="isRegexOn">是否开启正则匹配</param> /// <param name="isRegexOn">是否开启正则匹配</param>
public OpcUtility(OpcType connectionType, string connectionString, bool isRegexOn = false) : base(0, 0) public OpcUtility(OpcType connectionType, string connectionString, bool isRegexOn = false) : base(0, 0)
{ {
OpcType = connectionType;
ConnectionString = connectionString; ConnectionString = connectionString;
IsRegexOn = isRegexOn; IsRegexOn = isRegexOn;
OpcType = connectionType;
AddressTranslator = new AddressTranslatorOpc(); AddressTranslator = new AddressTranslatorOpc();
} }

View File

@@ -26,7 +26,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modbus.Net.Modbus.NA200H",
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AnyType", "..\Samples\AnyType\AnyType.csproj", "{1857DA63-3335-428F-84D8-1FA4F8178643}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AnyType", "..\Samples\AnyType\AnyType.csproj", "{1857DA63-3335-428F-84D8-1FA4F8178643}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modbus.Net.OPC", "Modbus.Net.OPC\Modbus.Net.OPC.csproj", "{C854A379-C5EA-4CAC-9C5F-7291372D1D3F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modbus.Net.Opc", "Modbus.Net.OPC\Modbus.Net.Opc.csproj", "{C854A379-C5EA-4CAC-9C5F-7291372D1D3F}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CrossLamp", "..\Samples\CrossLamp\CrossLamp.csproj", "{AA3A42D2-0502-41D3-929A-BAB729DF07D6}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CrossLamp", "..\Samples\CrossLamp\CrossLamp.csproj", "{AA3A42D2-0502-41D3-929A-BAB729DF07D6}"
EndProject EndProject