diff --git a/Modbus.Net/Modbus.Net.OPC/AddressFormaterOpc.cs b/Modbus.Net/Modbus.Net.OPC/AddressFormaterOpc.cs
index afaf426..47d082a 100644
--- a/Modbus.Net/Modbus.Net.OPC/AddressFormaterOpc.cs
+++ b/Modbus.Net/Modbus.Net.OPC/AddressFormaterOpc.cs
@@ -53,7 +53,7 @@ namespace Modbus.Net.OPC
var strings = TagGeter(Machine, findAddress);
var ans = "";
for (var i = 0; i < strings.Length; i++)
- ans += strings[i].Trim().Replace(" ", "") + Seperator;
+ ans += strings[i].Trim().Replace(" ", "") + '\r';
ans = ans.Substring(0, ans.Length - 1);
return ans;
}
diff --git a/Modbus.Net/Modbus.Net.OPC/ClientExtend.cs b/Modbus.Net/Modbus.Net.OPC/ClientExtend.cs
index 43b4e35..109c537 100644
--- a/Modbus.Net/Modbus.Net.OPC/ClientExtend.cs
+++ b/Modbus.Net/Modbus.Net.OPC/ClientExtend.cs
@@ -115,7 +115,7 @@ namespace Modbus.Net.OPC
///
/// Tag of a node
///
- public string Tag { get; set; }
+ public string[] Tag { get; set; }
///
/// Tag splitter of a node
diff --git a/Modbus.Net/Modbus.Net.OPC/FBox/FBoxOpcDaManchine.cs b/Modbus.Net/Modbus.Net.OPC/FBox/FBoxOpcDaManchine.cs
index c1f4827..04053a2 100644
--- a/Modbus.Net/Modbus.Net.OPC/FBox/FBoxOpcDaManchine.cs
+++ b/Modbus.Net/Modbus.Net.OPC/FBox/FBoxOpcDaManchine.cs
@@ -19,7 +19,7 @@ namespace Modbus.Net.OPC.FBox
IEnumerable getAddresses, bool keepConnect)
: base(
ConfigurationManager.AppSettings["FBoxOpcDaHost"] ?? "opcda://localhost/FBoxOpcServer", getAddresses,
- keepConnect)
+ keepConnect, true)
{
LocalSequence = localSequence;
LinkerName = linkerName;
diff --git a/Modbus.Net/Modbus.Net.OPC/Modbus.Net.OPC.csproj b/Modbus.Net/Modbus.Net.OPC/Modbus.Net.OPC.csproj
index de8c511..aab3c11 100644
--- a/Modbus.Net/Modbus.Net.OPC/Modbus.Net.OPC.csproj
+++ b/Modbus.Net/Modbus.Net.OPC/Modbus.Net.OPC.csproj
@@ -5,7 +5,7 @@
Modbus.Net.OPC
Modbus.Net.OPC
Modbus.Net.OPC
- 1.3.9-beta1
+ 1.3.9-beta2
Chris L.(Luo Sheng)
Hangzhou Delian IoT Science Technology Co.,Ltd.
Modbus.Net OPC Implementation
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcConnector.cs b/Modbus.Net/Modbus.Net.OPC/OpcConnector.cs
index e9d42d4..bcfaeb3 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcConnector.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcConnector.cs
@@ -24,13 +24,20 @@ namespace Modbus.Net.OPC
///
protected IClientExtend Client;
+ ///
+ /// 是否开启正则匹配
+ ///
+ protected bool RegexOn { get; set; }
+
///
/// 构造函数
///
/// 服务端url
- protected OpcConnector(string host)
+ /// 是否开启正则匹配
+ protected OpcConnector(string host, bool isRegexOn)
{
ConnectionToken = host;
+ RegexOn = isRegexOn;
}
///
@@ -95,47 +102,6 @@ namespace Modbus.Net.OPC
return AsyncHelper.RunSync(() => SendMsgAsync(message));
}
- ///
- /// 根据括号折叠已经打开的标签
- ///
- /// 已经打开的标签
- /// 分割符
- /// 开始字符
- /// 结束字符
- private void FoldWith(List tagSplitList, char splitChar, char startChar, char endChar)
- {
- for (var i = 0; i < tagSplitList.Count; i++)
- if (tagSplitList[i].Count(ch => ch == startChar) > tagSplitList[i].Count(ch => ch == endChar))
- for (var j = i + 1; j < tagSplitList.Count; j++)
- if (tagSplitList[j].Contains(endChar))
- {
- for (var k = i + 1; k <= j; k++)
- {
- tagSplitList[i] += splitChar + tagSplitList[i + 1];
- tagSplitList.RemoveAt(i + 1);
- }
- i--;
- break;
- }
- }
-
- ///
- /// 根据分隔符切分标签
- ///
- /// 标签
- /// 分隔符
- /// 分割后的标签
- private string[] SplitTag(string tag, char split)
- {
- var tagSplitList = tag.Split(split).ToList();
-
- FoldWith(tagSplitList, split, '(', ')');
- FoldWith(tagSplitList, split, '[', ']');
- FoldWith(tagSplitList, split, '{', '}');
-
- return tagSplitList.ToArray();
- }
-
///
/// 带返回发送数据
///
@@ -149,9 +115,8 @@ namespace Modbus.Net.OPC
{
var split = message.Split;
var tag = message.Tag;
- var tagSplit = SplitTag(tag, split);
var rootDirectory = await Client.ExploreFolderAsync("");
- var answerTag = await SearchTag(tagSplit, split, 0, rootDirectory);
+ var answerTag = await SearchTag(tag, split, 0, rootDirectory);
if (answerTag != null)
{
var result = await Client.ReadAsync
/// Opc DA 服务地址
- protected OpcDaConnector(string host) : base(host)
+ /// 是否开启正则匹配
+ protected OpcDaConnector(string host, bool isRegexOn) : base(host, isRegexOn)
{
Client = new MyDaClient(new Uri(ConnectionToken));
}
@@ -26,12 +27,13 @@ namespace Modbus.Net.OPC
/// 根据服务地址生成DA单例
///
/// Opc DA 服务地址
+ /// 是否开启正则匹配
/// Opc DA 连接器实例
- public static OpcDaConnector Instance(string host)
+ public static OpcDaConnector Instance(string host, bool isRegexOn)
{
if (!_instances.ContainsKey(host))
{
- var connector = new OpcDaConnector(host);
+ var connector = new OpcDaConnector(host, isRegexOn);
_instances.Add(host, connector);
}
return _instances[host];
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcDaMachine.cs b/Modbus.Net/Modbus.Net.OPC/OpcDaMachine.cs
index 6eed0e3..ed39377 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcDaMachine.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcDaMachine.cs
@@ -17,10 +17,11 @@ namespace Modbus.Net.OPC
/// 连接地址
/// 需要读写的数据
/// 是否保持连接
- public OpcDaMachine(string connectionString, IEnumerable> getAddresses, bool keepConnect)
+ /// 是否开启正则匹配
+ public OpcDaMachine(string connectionString, IEnumerable> getAddresses, bool keepConnect, bool isRegexOn = false)
: base(getAddresses, keepConnect)
{
- BaseUtility = new OpcDaUtility(connectionString);
+ BaseUtility = new OpcDaUtility(connectionString, isRegexOn);
((OpcUtility) BaseUtility).GetSeperator +=
() => ((AddressFormaterOpc) AddressFormater).Seperator;
}
@@ -47,10 +48,11 @@ namespace Modbus.Net.OPC
/// 连接地址
/// 需要读写的数据
/// 是否保持连接
- public OpcDaMachine(string connectionString, IEnumerable getAddresses, bool keepConnect)
+ /// 是否开启正则匹配
+ public OpcDaMachine(string connectionString, IEnumerable getAddresses, bool keepConnect, bool isRegexOn = false)
: base(getAddresses, keepConnect)
{
- BaseUtility = new OpcDaUtility(connectionString);
+ BaseUtility = new OpcDaUtility(connectionString, isRegexOn);
((OpcUtility) BaseUtility).GetSeperator +=
() => ((AddressFormaterOpc) AddressFormater).Seperator;
}
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcDaProtocal.cs b/Modbus.Net/Modbus.Net.OPC/OpcDaProtocal.cs
index 41cbdc0..47beba8 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcDaProtocal.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcDaProtocal.cs
@@ -9,13 +9,17 @@ namespace Modbus.Net.OPC
{
private readonly string _host;
+ private readonly bool _isRegexOn;
+
///
/// 构造函数
///
/// Opc DA服务地址
- public OpcDaProtocal(string host)
+ /// 是否开启正则匹配
+ public OpcDaProtocal(string host, bool isRegexOn)
{
_host = host;
+ _isRegexOn = isRegexOn;
}
///
@@ -33,7 +37,7 @@ namespace Modbus.Net.OPC
/// 是否连接成功
public override async Task ConnectAsync()
{
- ProtocalLinker = new OpcDaProtocalLinker(_host);
+ ProtocalLinker = new OpcDaProtocalLinker(_host, _isRegexOn);
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 7da896b..265a1a8 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcDaProtocalLinker.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcDaProtocalLinker.cs
@@ -10,7 +10,8 @@ namespace Modbus.Net.OPC
///
/// 构造函数
///
- public OpcDaProtocalLinker() : this(ConfigurationManager.AppSettings["OpcDaHost"])
+ /// 是否开启正则匹配
+ public OpcDaProtocalLinker(bool isRegexOn) : this(ConfigurationManager.AppSettings["OpcDaHost"], isRegexOn)
{
}
@@ -18,9 +19,10 @@ namespace Modbus.Net.OPC
/// 构造函数
///
/// Opc DA服务地址
- public OpcDaProtocalLinker(string host)
+ /// 是否开启正则匹配
+ public OpcDaProtocalLinker(string host, bool isRegexOn)
{
- BaseConnector = OpcDaConnector.Instance(host);
+ BaseConnector = OpcDaConnector.Instance(host, isRegexOn);
}
}
}
\ No newline at end of file
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcDaUtility.cs b/Modbus.Net/Modbus.Net.OPC/OpcDaUtility.cs
index 5415754..3acb95e 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcDaUtility.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcDaUtility.cs
@@ -9,9 +9,10 @@
/// 构造函数
///
/// 连接地址
- public OpcDaUtility(string connectionString) : base(connectionString)
+ /// 是否开启正则匹配
+ public OpcDaUtility(string connectionString, bool isRegexOn = false) : base(connectionString)
{
- Wrapper = new OpcDaProtocal(ConnectionString);
+ Wrapper = new OpcDaProtocal(ConnectionString, isRegexOn);
}
}
}
\ No newline at end of file
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcProtocal.cs b/Modbus.Net/Modbus.Net.OPC/OpcProtocal.cs
index 0b7d66a..30c2501 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcProtocal.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcProtocal.cs
@@ -25,7 +25,7 @@
///
/// 标签
/// 分隔符
- public ReadRequestOpcInputStruct(string tag, char split)
+ public ReadRequestOpcInputStruct(string[] tag, char split)
{
Tag = tag;
Split = split;
@@ -34,7 +34,7 @@
///
/// 标签
///
- public string Tag { get; }
+ public string[] Tag { get; }
///
/// 分隔符
@@ -111,7 +111,7 @@
/// 标签
/// 分隔符
/// 写入的数据
- public WriteRequestOpcInputStruct(string tag, char split, object setValue)
+ public WriteRequestOpcInputStruct(string[] tag, char split, object setValue)
{
Tag = tag;
Split = split;
@@ -121,7 +121,7 @@
///
/// 标签
///
- public string Tag { get; }
+ public string[] Tag { get; }
///
/// 分隔符
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcUaConnector.cs b/Modbus.Net/Modbus.Net.OPC/OpcUaConnector.cs
index 498a3e6..acae757 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcUaConnector.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcUaConnector.cs
@@ -17,7 +17,8 @@ namespace Modbus.Net.OPC
/// 构造函数
///
/// Opc UA 服务地址
- protected OpcUaConnector(string host) : base(host)
+ /// 是否开启正则匹配
+ protected OpcUaConnector(string host, bool isRegexOn) : base(host, isRegexOn)
{
Client = new MyUaClient(new Uri(ConnectionToken));
}
@@ -26,12 +27,13 @@ namespace Modbus.Net.OPC
/// 根据地址获取UA连接器单例
///
/// Opc UA服务地址
+ /// 是否开启正则匹配
/// OPC UA实例
- public static OpcUaConnector Instance(string host)
+ public static OpcUaConnector Instance(string host, bool isRegexOn)
{
if (!_instances.ContainsKey(host))
{
- var connector = new OpcUaConnector(host);
+ var connector = new OpcUaConnector(host, isRegexOn);
_instances.Add(host, connector);
}
return _instances[host];
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcUaMachine.cs b/Modbus.Net/Modbus.Net.OPC/OpcUaMachine.cs
index 815d482..584a4eb 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcUaMachine.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcUaMachine.cs
@@ -17,10 +17,11 @@ namespace Modbus.Net.OPC
/// 连接地址
/// 需要读写的数据
/// 是否保持连接
- public OpcUaMachine(string connectionString, IEnumerable> getAddresses, bool keepConnect)
+ /// 是否开启正则匹配
+ public OpcUaMachine(string connectionString, IEnumerable> getAddresses, bool keepConnect, bool isRegexOn = false)
: base(getAddresses, keepConnect)
{
- BaseUtility = new OpcUaUtility(connectionString);
+ BaseUtility = new OpcUaUtility(connectionString, isRegexOn);
((OpcUtility) BaseUtility).GetSeperator +=
() => ((AddressFormaterOpc) AddressFormater).Seperator;
}
@@ -47,10 +48,11 @@ namespace Modbus.Net.OPC
/// 连接地址
/// 需要读写的数据
/// 是否保持连接
- public OpcUaMachine(string connectionString, IEnumerable getAddresses, bool keepConnect)
+ /// 是否开启正则匹配
+ public OpcUaMachine(string connectionString, IEnumerable getAddresses, bool keepConnect, bool isRegexOn = false)
: base(getAddresses, keepConnect)
{
- BaseUtility = new OpcUaUtility(connectionString);
+ BaseUtility = new OpcUaUtility(connectionString, isRegexOn);
((OpcUtility) BaseUtility).GetSeperator +=
() => ((AddressFormaterOpc) AddressFormater).Seperator;
}
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcUaProtocal.cs b/Modbus.Net/Modbus.Net.OPC/OpcUaProtocal.cs
index f358e98..32d07fc 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcUaProtocal.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcUaProtocal.cs
@@ -9,13 +9,17 @@ namespace Modbus.Net.OPC
{
private readonly string _host;
+ private readonly bool _isRegexOn;
+
///
/// 构造函数
///
/// Opc UA服务地址
- public OpcUaProtocal(string host)
+ /// 是否开启正则匹配
+ public OpcUaProtocal(string host, bool isRegexOn)
{
_host = host;
+ _isRegexOn = isRegexOn;
}
///
@@ -33,7 +37,7 @@ namespace Modbus.Net.OPC
/// 是否连接成功
public override async Task ConnectAsync()
{
- ProtocalLinker = new OpcUaProtocalLinker(_host);
+ ProtocalLinker = new OpcUaProtocalLinker(_host, _isRegexOn);
if (!await ProtocalLinker.ConnectAsync()) return false;
return true;
}
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcUaProtocalLinker.cs b/Modbus.Net/Modbus.Net.OPC/OpcUaProtocalLinker.cs
index 34dc6cb..d4ed0af 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcUaProtocalLinker.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcUaProtocalLinker.cs
@@ -10,7 +10,8 @@ namespace Modbus.Net.OPC
///
/// 构造函数
///
- public OpcUaProtocalLinker() : this(ConfigurationManager.AppSettings["OpcUaHost"])
+ /// 是否开启正则匹配
+ public OpcUaProtocalLinker(bool isRegexOn) : this(ConfigurationManager.AppSettings["OpcUaHost"], isRegexOn)
{
}
@@ -18,9 +19,10 @@ namespace Modbus.Net.OPC
/// 构造函数
///
/// Opc UA服务地址
- public OpcUaProtocalLinker(string host)
+ /// 是否开启正则匹配
+ public OpcUaProtocalLinker(string host, bool isRegexOn)
{
- BaseConnector = OpcUaConnector.Instance(host);
+ BaseConnector = OpcUaConnector.Instance(host, isRegexOn);
}
}
}
\ No newline at end of file
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcUaUtility.cs b/Modbus.Net/Modbus.Net.OPC/OpcUaUtility.cs
index e144afe..e4db506 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcUaUtility.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcUaUtility.cs
@@ -9,9 +9,10 @@
/// 构造函数
///
/// 连接地址
- public OpcUaUtility(string connectionString) : base(connectionString)
+ /// 是否开启正则匹配
+ public OpcUaUtility(string connectionString, bool isRegexOn = false) : base(connectionString)
{
- Wrapper = new OpcUaProtocal(ConnectionString);
+ Wrapper = new OpcUaProtocal(ConnectionString, isRegexOn);
}
}
}
\ No newline at end of file
diff --git a/Modbus.Net/Modbus.Net.OPC/OpcUtility.cs b/Modbus.Net/Modbus.Net.OPC/OpcUtility.cs
index 050b2e6..ea72ded 100644
--- a/Modbus.Net/Modbus.Net.OPC/OpcUtility.cs
+++ b/Modbus.Net/Modbus.Net.OPC/OpcUtility.cs
@@ -55,7 +55,7 @@ namespace Modbus.Net.OPC
try
{
var split = GetSeperator?.Invoke() ?? '/';
- var readRequestOpcInputStruct = new ReadRequestOpcInputStruct(startAddress, split);
+ var readRequestOpcInputStruct = new ReadRequestOpcInputStruct(startAddress.Split('\r'), split);
var readRequestOpcOutputStruct =
await
Wrapper.SendReceiveAsync(Wrapper[typeof(ReadRequestOpcProtocal)],
@@ -80,7 +80,7 @@ namespace Modbus.Net.OPC
try
{
var split = GetSeperator?.Invoke() ?? '/';
- var writeRequestOpcInputStruct = new WriteRequestOpcInputStruct(startAddress, split, setContents[0]);
+ var writeRequestOpcInputStruct = new WriteRequestOpcInputStruct(startAddress.Split('\r'), split, setContents[0]);
var writeRequestOpcOutputStruct =
await
Wrapper.SendReceiveAsync(Wrapper[typeof(WriteRequestOpcProtocal)],