diff --git a/Modbus.Net/Modbus.Net.OPC/AddressFormaterOpc.cs b/Modbus.Net/Modbus.Net.OPC/AddressFormaterOpc.cs
index 2d9a4f6..afaf426 100644
--- a/Modbus.Net/Modbus.Net.OPC/AddressFormaterOpc.cs
+++ b/Modbus.Net/Modbus.Net.OPC/AddressFormaterOpc.cs
@@ -24,12 +24,28 @@ namespace Modbus.Net.OPC
Seperator = seperator;
}
+ ///
+ /// 设备
+ ///
public BaseMachine Machine { get; set; }
+ ///
+ /// 标签构造器
+ /// (设备,地址)->不具备分隔符的标签数组
+ ///
protected Func, AddressUnit, string[]> TagGeter { get; set; }
+ ///
+ /// 分割符
+ ///
public char Seperator { get; protected set; }
+ ///
+ /// 编码地址
+ ///
+ /// 地址所在的数据区域
+ /// 地址
+ /// 编码后的地址
public override string FormatAddress(string area, int address)
{
var findAddress = Machine?.GetAddresses.FirstOrDefault(p => p.Area == area && p.Address == address);
@@ -42,6 +58,13 @@ namespace Modbus.Net.OPC
return ans;
}
+ ///
+ /// 编码地址
+ ///
+ /// 地址所在的数据区域
+ /// 地址
+ /// 子地址(忽略)
+ /// 编码后的地址
public override string FormatAddress(string area, int address, int subAddress)
{
return FormatAddress(area, address);
diff --git a/Modbus.Net/Modbus.Net.OPC/AddressTranslatorOpc.cs b/Modbus.Net/Modbus.Net.OPC/AddressTranslatorOpc.cs
index 71f0d20..892b5c7 100644
--- a/Modbus.Net/Modbus.Net.OPC/AddressTranslatorOpc.cs
+++ b/Modbus.Net/Modbus.Net.OPC/AddressTranslatorOpc.cs
@@ -7,11 +7,22 @@ namespace Modbus.Net.OPC
///
public class AddressTranslatorOpc : AddressTranslator
{
+ ///
+ /// 地址转换
+ ///
+ /// 格式化的地址
+ /// 是否为读取,是为读取,否为写入
+ /// 翻译后的地址
public override AddressDef AddressTranslate(string address, bool isRead)
{
throw new NotImplementedException();
}
+ ///
+ /// 获取区域中的单个地址占用的字节长度
+ ///
+ /// 区域名称
+ /// 字节长度
public override double GetAreaByteLength(string area)
{
return 1;
diff --git a/Modbus.Net/Modbus.Net.OPC/ClientExtend.cs b/Modbus.Net/Modbus.Net.OPC/ClientExtend.cs
index d745f7a..43b4e35 100644
--- a/Modbus.Net/Modbus.Net.OPC/ClientExtend.cs
+++ b/Modbus.Net/Modbus.Net.OPC/ClientExtend.cs
@@ -7,54 +7,140 @@ using Hylasoft.Opc.Ua;
namespace Modbus.Net.OPC
{
+ ///
+ /// Opc Client Extend interface, Unified for DA and UA
+ ///
public interface IClientExtend : IDisposable
{
+ ///
+ /// Unified Root Node
+ ///
Node RootNodeBase { get; }
+ ///
+ /// Connect the client to the OPC Server
+ ///
void Connect();
+ ///
+ /// Read a tag
+ ///
+ /// The type of tag to read
+ ///
+ /// 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`
+ ///
+ /// The value retrieved from the OPC
T Read(string tag);
+ ///
+ /// Write a value on the specified opc tag
+ ///
+ /// The type of tag to write on
+ ///
+ /// The fully-qualified identifier of the tag. You can specify a subfolder by using a comma delimited name.
+ /// E.g: the tag `foo.bar` writes on the tag `bar` on the folder `foo`
+ ///
+ ///
void Write(string tag, T item);
+ ///
+ /// Read a tag asynchronusly
+ ///
Task ReadAsync(string tag);
+ ///
+ /// Write a value on the specified opc tag asynchronously
+ ///
Task WriteAsync(string tag, T item);
+ ///
+ /// Finds a node on the Opc Server asynchronously
+ ///
Task FindNodeAsync(string tag);
+ ///
+ /// Explore a folder on the Opc Server asynchronously
+ ///
Task> ExploreFolderAsync(string tag);
}
+ ///
+ /// UaClient Extend
+ ///
public class MyDaClient : DaClient, IClientExtend
{
+ ///
+ /// UaClient Extend
+ ///
+ /// Url address of Opc UA server
public MyDaClient(Uri serverUrl) : base(serverUrl)
{
}
+ ///
+ /// Unified root node
+ ///
public Node RootNodeBase => RootNode;
}
+ ///
+ /// DaClient Extend
+ ///
public class MyUaClient : UaClient, IClientExtend
{
+ ///
+ /// DaClient Extend
+ ///
public MyUaClient(Uri serverUrl) : base(serverUrl)
{
}
+ ///
+ /// Unified root node
+ ///
public Node RootNodeBase => RootNode;
}
+ ///
+ /// Param input of OpcConnector
+ ///
public class OpcParamIn
{
+ ///
+ /// Is the action read (not is write)
+ ///
public bool IsRead { get; set; }
+
+ ///
+ /// Tag of a node
+ ///
public string Tag { get; set; }
+
+ ///
+ /// Tag splitter of a node
+ ///
public char Split { get; set; }
+
+ ///
+ /// The value set to node(only available when IsRead is false
+ ///
public object SetValue { get; set; }
}
+ ///
+ /// Param output of OpcConnector
+ ///
public class OpcParamOut
{
+ ///
+ /// Is the action success
+ ///
public bool Success { get; set; }
+
+ ///
+ /// Action return values
+ ///
public byte[] Value { get; set; }
}
}
\ No newline at end of file
diff --git a/Modbus.Net/Modbus.Net.OPC/FBox/FBoxOpcDaManchine.cs b/Modbus.Net/Modbus.Net.OPC/FBox/FBoxOpcDaManchine.cs
index 074d867..997c627 100644
--- a/Modbus.Net/Modbus.Net.OPC/FBox/FBoxOpcDaManchine.cs
+++ b/Modbus.Net/Modbus.Net.OPC/FBox/FBoxOpcDaManchine.cs
@@ -3,8 +3,18 @@ using System.Configuration;
namespace Modbus.Net.OPC.FBox
{
+ ///
+ /// FBox的Opc服务设备
+ ///
public class FBoxOpcDaMachine : OpcDaMachine
{
+ ///
+ /// 构造函数
+ ///
+ /// 页名称
+ /// 设备名称
+ /// 获取地址
+ /// 是否保持连接
public FBoxOpcDaMachine(string localSequence, string linkerName,
IEnumerable getAddresses, bool keepConnect)
: base(ConfigurationManager.AppSettings["FBoxOpcDaHost"], getAddresses, keepConnect)
@@ -21,14 +31,26 @@ namespace Modbus.Net.OPC.FBox
}, this, '.');
}
+ ///
+ /// 构造函数
+ ///
+ /// 页名称
+ /// 设备名称
+ /// 获取地址
public FBoxOpcDaMachine(string localSequence, string linkerName,
IEnumerable getAddresses)
: this(localSequence, linkerName, getAddresses, false)
{
}
+ ///
+ /// 页名称
+ ///
public string LocalSequence { get; set; }
+ ///
+ /// 设备名称
+ ///
public string LinkerName { get; set; }
}
}
\ No newline at end of file
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcConnector.cs b/Modbus.Net/Modbus.Net.OPC/OpcConnector.cs
index b4281d5..95ba555 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcConnector.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcConnector.cs
@@ -9,19 +9,44 @@ using Serilog;
namespace Modbus.Net.OPC
{
+ ///
+ /// Opc连接器
+ ///
public abstract class OpcConnector : BaseConnector
{
+ ///
+ /// 是否正在连接
+ ///
protected bool _connect;
+
+ ///
+ /// Opc客户端
+ ///
protected IClientExtend Client;
+ ///
+ /// 构造函数
+ ///
+ /// 服务端url
protected OpcConnector(string host)
{
ConnectionToken = host;
}
+ ///
+ /// 连接标识
+ ///
public override string ConnectionToken { get; }
+
+ ///
+ /// 是否正在连接
+ ///
public override bool IsConnected => _connect;
+ ///
+ /// 断开连接
+ ///
+ ///
public override bool Disconnect()
{
try
@@ -40,21 +65,43 @@ namespace Modbus.Net.OPC
}
}
+ ///
+ /// 无返回发送数据
+ ///
+ /// 需要发送的数据
+ /// 是否发送成功
public override bool SendMsgWithoutReturn(OpcParamIn message)
{
throw new NotImplementedException();
}
+ ///
+ /// 无返回发送数据
+ ///
+ /// 需要发送的数据
+ /// 是否发送成功
public override Task SendMsgWithoutReturnAsync(OpcParamIn message)
{
throw new NotImplementedException();
}
+ ///
+ /// 带返回发送数据
+ ///
+ /// 需要发送的数据
+ /// 是否发送成功
public override OpcParamOut SendMsg(OpcParamIn message)
{
return AsyncHelper.RunSync(() => SendMsgAsync(message));
}
+ ///
+ /// 根据括号折叠已经打开的标签
+ ///
+ /// 已经打开的标签
+ /// 分割符
+ /// 开始字符
+ /// 结束字符
private void FoldWith(List tagSplitList, char splitChar, char startChar, char endChar)
{
for (var i = 0; i < tagSplitList.Count; i++)
@@ -72,6 +119,12 @@ namespace Modbus.Net.OPC
}
}
+ ///
+ /// 根据分隔符切分标签
+ ///
+ /// 标签
+ /// 分隔符
+ /// 分割后的标签
private string[] SplitTag(string tag, char split)
{
var tagSplitList = tag.Split(split).ToList();
@@ -83,6 +136,11 @@ namespace Modbus.Net.OPC
return tagSplitList.ToArray();
}
+ ///
+ /// 带返回发送数据
+ ///
+ /// 需要发送的数据
+ /// 是否发送成功
public override async Task SendMsgAsync(OpcParamIn message)
{
try
@@ -154,6 +212,14 @@ namespace Modbus.Net.OPC
}
}
+ ///
+ /// 搜索标签
+ ///
+ /// 标签
+ /// 分隔符
+ /// 递归深度(第几级标签)
+ /// 当前搜索的节点
+ /// 搜索到的标签
private async Task SearchTag(string[] tags, char split, int deep, IEnumerable nodes)
{
foreach (var node in nodes)
@@ -170,11 +236,10 @@ namespace Modbus.Net.OPC
return null;
}
- protected void AddInfo(string message)
- {
- Console.WriteLine(message);
- }
-
+ ///
+ /// 连接PLC
+ ///
+ /// 是否连接成功
public override bool Connect()
{
try
@@ -192,6 +257,10 @@ namespace Modbus.Net.OPC
}
}
+ ///
+ /// 连接PLC,异步
+ ///
+ /// 是否连接成功
public override Task ConnectAsync()
{
return Task.FromResult(Connect());
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcDaConnector.cs b/Modbus.Net/Modbus.Net.OPC/OpcDaConnector.cs
index 4813ef2..416aad5 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcDaConnector.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcDaConnector.cs
@@ -4,17 +4,29 @@ using System.Collections.Generic;
namespace Modbus.Net.OPC
{
///
- /// OpcDa协议连接实现
+ /// Opc DA连接实现
///
public class OpcDaConnector : OpcConnector
{
+ ///
+ /// DA单例管理
+ ///
protected static Dictionary _instances = new Dictionary();
+ ///
+ /// 构造函数
+ ///
+ /// Opc DA 服务地址
protected OpcDaConnector(string host) : base(host)
{
Client = new MyDaClient(new Uri(ConnectionToken));
}
+ ///
+ /// 根据服务地址生成DA单例
+ ///
+ /// Opc DA 服务地址
+ /// Opc DA 连接器实例
public static OpcDaConnector Instance(string host)
{
if (!_instances.ContainsKey(host))
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcDaMachine.cs b/Modbus.Net/Modbus.Net.OPC/OpcDaMachine.cs
index 681fee1..6eed0e3 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcDaMachine.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcDaMachine.cs
@@ -3,9 +3,20 @@ using System.Collections.Generic;
namespace Modbus.Net.OPC
{
+ ///
+ /// Opc DA设备
+ ///
+ /// 设备Id类型
+ /// 设备包含的地址的Id类型
public class OpcDaMachine : OpcMachine where TKey : IEquatable
where TUnitKey : IEquatable
{
+ ///
+ /// 构造函数
+ ///
+ /// 连接地址
+ /// 需要读写的数据
+ /// 是否保持连接
public OpcDaMachine(string connectionString, IEnumerable> getAddresses, bool keepConnect)
: base(getAddresses, keepConnect)
{
@@ -14,14 +25,28 @@ namespace Modbus.Net.OPC
() => ((AddressFormaterOpc) AddressFormater).Seperator;
}
+ ///
+ /// 构造函数
+ ///
+ /// 连接地址
+ /// 需要读写的数据
public OpcDaMachine(string connectionString, IEnumerable> getAddresses)
: this(connectionString, getAddresses, false)
{
}
}
+ ///
+ /// Opc DA设备
+ ///
public class OpcDaMachine : OpcMachine
{
+ ///
+ /// 构造函数
+ ///
+ /// 连接地址
+ /// 需要读写的数据
+ /// 是否保持连接
public OpcDaMachine(string connectionString, IEnumerable getAddresses, bool keepConnect)
: base(getAddresses, keepConnect)
{
@@ -30,6 +55,11 @@ namespace Modbus.Net.OPC
() => ((AddressFormaterOpc) AddressFormater).Seperator;
}
+ ///
+ /// 构造函数
+ ///
+ /// 连接地址
+ /// 需要读写的数据
public OpcDaMachine(string connectionString, IEnumerable getAddresses)
: this(connectionString, getAddresses, false)
{
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcDaProtocal.cs b/Modbus.Net/Modbus.Net.OPC/OpcDaProtocal.cs
index bf5ce6d..41cbdc0 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcDaProtocal.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcDaProtocal.cs
@@ -3,29 +3,39 @@
namespace Modbus.Net.OPC
{
///
- /// OpcDa协议
+ /// Opc Da协议
///
public class OpcDaProtocal : OpcProtocal
{
private readonly string _host;
- private int _connectTryCount;
+ ///
+ /// 构造函数
+ ///
+ /// Opc DA服务地址
public OpcDaProtocal(string host)
{
_host = host;
}
+ ///
+ /// 连接设备
+ ///
+ /// 是否连接成功
public override bool Connect()
{
return AsyncHelper.RunSync(ConnectAsync);
}
+ ///
+ /// 连接设备
+ ///
+ /// 是否连接成功
public override async Task ConnectAsync()
{
- _connectTryCount++;
ProtocalLinker = new OpcDaProtocalLinker(_host);
- if (!await ProtocalLinker.ConnectAsync()) return false;
- _connectTryCount = 0;
+ if (!await ProtocalLinker.ConnectAsync())
+ return false;
return true;
}
}
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcDaProtocalLinker.cs b/Modbus.Net/Modbus.Net.OPC/OpcDaProtocalLinker.cs
index c98b617..7da896b 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcDaProtocalLinker.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcDaProtocalLinker.cs
@@ -7,10 +7,17 @@ namespace Modbus.Net.OPC
///
public class OpcDaProtocalLinker : OpcProtocalLinker
{
+ ///
+ /// 构造函数
+ ///
public OpcDaProtocalLinker() : this(ConfigurationManager.AppSettings["OpcDaHost"])
{
}
+ ///
+ /// 构造函数
+ ///
+ /// Opc DA服务地址
public OpcDaProtocalLinker(string host)
{
BaseConnector = OpcDaConnector.Instance(host);
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcDaUtility.cs b/Modbus.Net/Modbus.Net.OPC/OpcDaUtility.cs
index d52232d..5415754 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcDaUtility.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcDaUtility.cs
@@ -5,6 +5,10 @@
///
public class OpcDaUtility : OpcUtility
{
+ ///
+ /// 构造函数
+ ///
+ /// 连接地址
public OpcDaUtility(string connectionString) : base(connectionString)
{
Wrapper = new OpcDaProtocal(ConnectionString);
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcMachine.cs b/Modbus.Net/Modbus.Net.OPC/OpcMachine.cs
index 3803e54..0b6f537 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcMachine.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcMachine.cs
@@ -4,11 +4,16 @@ using System.Collections.Generic;
namespace Modbus.Net.OPC
{
///
- /// OpcDa设备
+ /// Opc Da设备
///
public abstract class OpcMachine : BaseMachine where TKey : IEquatable
where TUnitKey : IEquatable
{
+ ///
+ /// 构造函数
+ ///
+ /// 需要读写的地址
+ /// 是否保持连接
protected OpcMachine(IEnumerable> getAddresses, bool keepConnect)
: base(getAddresses, keepConnect)
{
@@ -18,10 +23,15 @@ namespace Modbus.Net.OPC
}
///
- /// OpcDa设备
+ /// Opc Da设备
///
public abstract class OpcMachine : BaseMachine
{
+ ///
+ /// 构造函数
+ ///
+ /// 需要读写的地址
+ /// 是否保持连接
protected OpcMachine(IEnumerable getAddresses, bool keepConnect)
: base(getAddresses, keepConnect)
{
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcProtocal.cs b/Modbus.Net/Modbus.Net.OPC/OpcProtocal.cs
index 6f48d67..ca56811 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcProtocal.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcProtocal.cs
@@ -5,6 +5,9 @@
///
public abstract class OpcProtocal : BaseProtocal>
{
+ ///
+ /// 构造函数
+ ///
protected OpcProtocal() : base(0, 0, Endian.BigEndianLsb)
{
}
@@ -12,30 +15,63 @@
#region 读数据
+ ///
+ /// 读数据输入
+ ///
public class ReadRequestOpcInputStruct : IInputStruct
{
+ ///
+ /// 构造函数
+ ///
+ /// 标签
+ /// 分隔符
public ReadRequestOpcInputStruct(string tag, char split)
{
Tag = tag;
Split = split;
}
+ ///
+ /// 标签
+ ///
public string Tag { get; }
+
+ ///
+ /// 分隔符
+ ///
public char Split { get; }
}
+ ///
+ /// 读地址输出
+ ///
public class ReadRequestOpcOutputStruct : IOutputStruct
{
+ ///
+ /// 构造函数
+ ///
+ /// 读取的数据
public ReadRequestOpcOutputStruct(byte[] value)
{
GetValue = value;
}
+ ///
+ /// 读取的地址
+ ///
public byte[] GetValue { get; private set; }
}
+ ///
+ /// 读数据协议
+ ///
public class ReadRequestOpcProtocal : ProtocalUnit, ISpecialProtocalUnit
{
+ ///
+ /// 从对象的参数数组格式化
+ ///
+ /// 非结构化的输入数据
+ /// 格式化后的字节流
public override OpcParamIn Format(IInputStruct message)
{
var r_message = (ReadRequestOpcInputStruct) message;
@@ -47,6 +83,12 @@
};
}
+ ///
+ /// 把仪器返回的内容填充到输出结构中
+ ///
+ /// 返回数据的字节流
+ /// 转换标记位
+ /// 结构化的输出数据
public override IOutputStruct Unformat(OpcParamOut messageBytes, ref int pos)
{
return new ReadRequestOpcOutputStruct(messageBytes.Value);
@@ -57,8 +99,17 @@
#region 写数据
+ ///
+ /// 写数据输入
+ ///
public class WriteRequestOpcInputStruct : IInputStruct
{
+ ///
+ /// 构造函数
+ ///
+ /// 标签
+ /// 分隔符
+ /// 写入的数据
public WriteRequestOpcInputStruct(string tag, char split, object setValue)
{
Tag = tag;
@@ -66,23 +117,52 @@
SetValue = setValue;
}
+ ///
+ /// 标签
+ ///
public string Tag { get; }
+
+ ///
+ /// 分隔符
+ ///
public char Split { get; }
+
+ ///
+ /// 写入的数据
+ ///
public object SetValue { get; }
}
+ ///
+ /// 写数据输出
+ ///
public class WriteRequestOpcOutputStruct : IOutputStruct
{
+ ///
+ /// 构造函数
+ ///
+ /// 写入是否成功
public WriteRequestOpcOutputStruct(bool writeResult)
{
WriteResult = writeResult;
}
+ ///
+ /// 写入是否成功
+ ///
public bool WriteResult { get; private set; }
}
+ ///
+ /// 写数据协议
+ ///
public class WriteRequestOpcProtocal : ProtocalUnit, ISpecialProtocalUnit
{
+ ///
+ /// 从对象的参数数组格式化
+ ///
+ /// 非结构化的输入数据
+ /// 格式化后的字节流
public override OpcParamIn Format(IInputStruct message)
{
var r_message = (WriteRequestOpcInputStruct) message;
@@ -95,6 +175,12 @@
};
}
+ ///
+ /// 把仪器返回的内容填充到输出结构中
+ ///
+ /// 返回数据的字节流
+ /// 转换标记位
+ /// 结构化的输出数据
public override IOutputStruct Unformat(OpcParamOut messageBytes, ref int pos)
{
var ansByte = BigEndianValueHelper.Instance.GetByte(messageBytes.Value, ref pos);
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcUaConnector.cs b/Modbus.Net/Modbus.Net.OPC/OpcUaConnector.cs
index 8fc4152..498a3e6 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcUaConnector.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcUaConnector.cs
@@ -4,17 +4,29 @@ using System.Collections.Generic;
namespace Modbus.Net.OPC
{
///
- /// OpcDa协议连接实现
+ /// Opc UA连接实现
///
public class OpcUaConnector : OpcConnector
{
+ ///
+ /// UA单例管理
+ ///
protected static Dictionary _instances = new Dictionary();
+ ///
+ /// 构造函数
+ ///
+ /// Opc UA 服务地址
protected OpcUaConnector(string host) : base(host)
{
Client = new MyUaClient(new Uri(ConnectionToken));
}
+ ///
+ /// 根据地址获取UA连接器单例
+ ///
+ /// Opc UA服务地址
+ /// OPC UA实例
public static OpcUaConnector Instance(string host)
{
if (!_instances.ContainsKey(host))
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcUaMachine.cs b/Modbus.Net/Modbus.Net.OPC/OpcUaMachine.cs
index 7e49287..815d482 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcUaMachine.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcUaMachine.cs
@@ -3,9 +3,20 @@ using System.Collections.Generic;
namespace Modbus.Net.OPC
{
+ ///
+ /// Opc UA设备
+ ///
+ /// 设备Id的类型
+ /// 设备中地址的Id的类型
public class OpcUaMachine : OpcMachine where TKey : IEquatable
where TUnitKey : IEquatable
{
+ ///
+ /// 构造函数
+ ///
+ /// 连接地址
+ /// 需要读写的数据
+ /// 是否保持连接
public OpcUaMachine(string connectionString, IEnumerable> getAddresses, bool keepConnect)
: base(getAddresses, keepConnect)
{
@@ -14,14 +25,28 @@ namespace Modbus.Net.OPC
() => ((AddressFormaterOpc) AddressFormater).Seperator;
}
+ ///
+ /// 构造函数
+ ///
+ /// 连接地址
+ /// 需要读写的数据
public OpcUaMachine(string connectionString, IEnumerable> getAddresses)
: this(connectionString, getAddresses, false)
{
}
}
+ ///
+ /// Opc UA设备
+ ///
public class OpcUaMachine : OpcMachine
{
+ ///
+ /// 构造函数
+ ///
+ /// 连接地址
+ /// 需要读写的数据
+ /// 是否保持连接
public OpcUaMachine(string connectionString, IEnumerable getAddresses, bool keepConnect)
: base(getAddresses, keepConnect)
{
@@ -30,6 +55,11 @@ namespace Modbus.Net.OPC
() => ((AddressFormaterOpc) AddressFormater).Seperator;
}
+ ///
+ /// 构造函数
+ ///
+ /// 连接地址
+ /// 需要读写的数据
public OpcUaMachine(string connectionString, IEnumerable getAddresses)
: this(connectionString, getAddresses, false)
{
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcUaProtocal.cs b/Modbus.Net/Modbus.Net.OPC/OpcUaProtocal.cs
index b146880..f358e98 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcUaProtocal.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcUaProtocal.cs
@@ -3,29 +3,38 @@
namespace Modbus.Net.OPC
{
///
- /// OpcUa协议
+ /// Opc UA协议
///
public class OpcUaProtocal : OpcProtocal
{
private readonly string _host;
- private int _connectTryCount;
+ ///
+ /// 构造函数
+ ///
+ /// Opc UA服务地址
public OpcUaProtocal(string host)
{
_host = host;
}
+ ///
+ /// 连接设备
+ ///
+ /// 是否连接成功
public override bool Connect()
{
return AsyncHelper.RunSync(ConnectAsync);
}
+ ///
+ /// 连接设备
+ ///
+ /// 是否连接成功
public override async Task ConnectAsync()
{
- _connectTryCount++;
ProtocalLinker = new OpcUaProtocalLinker(_host);
if (!await ProtocalLinker.ConnectAsync()) return false;
- _connectTryCount = 0;
return true;
}
}
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcUaProtocalLinker.cs b/Modbus.Net/Modbus.Net.OPC/OpcUaProtocalLinker.cs
index 31b3279..34dc6cb 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcUaProtocalLinker.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcUaProtocalLinker.cs
@@ -3,14 +3,21 @@
namespace Modbus.Net.OPC
{
///
- /// Opc Da协议连接器
+ /// Opc UA协议连接器
///
public class OpcUaProtocalLinker : OpcProtocalLinker
{
+ ///
+ /// 构造函数
+ ///
public OpcUaProtocalLinker() : this(ConfigurationManager.AppSettings["OpcUaHost"])
{
}
+ ///
+ /// 构造函数
+ ///
+ /// Opc UA服务地址
public OpcUaProtocalLinker(string host)
{
BaseConnector = OpcUaConnector.Instance(host);
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcUaUtility.cs b/Modbus.Net/Modbus.Net.OPC/OpcUaUtility.cs
index e061c28..e144afe 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcUaUtility.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcUaUtility.cs
@@ -1,10 +1,14 @@
namespace Modbus.Net.OPC
{
///
- /// Opc Da协议Api入口
+ /// Opc Ua协议Api入口
///
public class OpcUaUtility : OpcUtility
{
+ ///
+ /// 构造函数
+ ///
+ /// 连接地址
public OpcUaUtility(string connectionString) : base(connectionString)
{
Wrapper = new OpcUaProtocal(ConnectionString);
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcUtility.cs b/Modbus.Net/Modbus.Net.OPC/OpcUtility.cs
index 8da536b..050b2e6 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcUtility.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcUtility.cs
@@ -4,25 +4,52 @@ using Serilog;
namespace Modbus.Net.OPC
{
+ ///
+ /// Opc通用Api入口
+ ///
public abstract class OpcUtility : BaseUtility>
{
+ ///
+ /// 获取分隔符
+ ///
+ /// 分隔符
public delegate char GetSeperatorDelegate();
+ ///
+ /// 构造函数
+ ///
+ /// 连接地址
protected OpcUtility(string connectionString) : base(0, 0)
{
ConnectionString = connectionString;
AddressTranslator = new AddressTranslatorOpc();
}
+ ///
+ /// 端格式(大端)
+ ///
public override Endian Endian => Endian.BigEndianLsb;
+ ///
+ /// 获取分隔符
+ ///
public event GetSeperatorDelegate GetSeperator;
+ ///
+ /// 设置连接方式(Opc忽略该函数)
+ ///
+ /// 连接方式
public override void SetConnectionType(int connectionType)
{
- throw new NotImplementedException();
+ //ignore
}
+ ///
+ /// 获取数据
+ ///
+ /// 开始地址
+ /// 获取字节数个数
+ /// 接收到的byte数据
public override async Task GetDatasAsync(string startAddress, int getByteCount)
{
try
@@ -42,6 +69,12 @@ namespace Modbus.Net.OPC
}
}
+ ///
+ /// 设置数据
+ ///
+ /// 开始地址
+ /// 设置数据
+ /// 是否设置成功
public override async Task SetDatasAsync(string startAddress, object[] setContents)
{
try