OPC EntryPoint Fix
This commit is contained in:
@@ -1,74 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Modbus.Net.OPC
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Opc DA设备
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TKey">设备Id类型</typeparam>
|
|
||||||
/// <typeparam name="TUnitKey">设备包含的地址的Id类型</typeparam>
|
|
||||||
public class OpcDaMachine<TKey, TUnitKey> : OpcMachine<TKey, TUnitKey> where TKey : IEquatable<TKey>
|
|
||||||
where TUnitKey : IEquatable<TUnitKey>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 构造函数
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id">设备的ID号</param>
|
|
||||||
/// <param name="connectionString">连接地址</param>
|
|
||||||
/// <param name="getAddresses">需要读写的数据</param>
|
|
||||||
/// <param name="keepConnect">是否保持连接</param>
|
|
||||||
/// <param name="isRegexOn">是否开启正则匹配</param>
|
|
||||||
public OpcDaMachine(TKey id, string connectionString, IEnumerable<AddressUnit<TUnitKey>> getAddresses, bool keepConnect, bool isRegexOn = false)
|
|
||||||
: base(id, getAddresses, keepConnect)
|
|
||||||
{
|
|
||||||
BaseUtility = new OpcDaUtility(connectionString, isRegexOn);
|
|
||||||
((OpcUtility)BaseUtility).GetSeperator +=
|
|
||||||
() => ((AddressFormaterOpc<TKey, TUnitKey>)AddressFormater).Seperator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 构造函数
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id">设备的ID号</param>
|
|
||||||
/// <param name="connectionString">连接地址</param>
|
|
||||||
/// <param name="getAddresses">需要读写的数据</param>
|
|
||||||
public OpcDaMachine(TKey id, string connectionString, IEnumerable<AddressUnit<TUnitKey>> getAddresses)
|
|
||||||
: this(id, connectionString, getAddresses, false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Opc DA设备
|
|
||||||
/// </summary>
|
|
||||||
public class OpcDaMachine : OpcMachine
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 构造函数
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id">设备的ID号</param>
|
|
||||||
/// <param name="connectionString">连接地址</param>
|
|
||||||
/// <param name="getAddresses">需要读写的数据</param>
|
|
||||||
/// <param name="keepConnect">是否保持连接</param>
|
|
||||||
/// <param name="isRegexOn">是否开启正则匹配</param>
|
|
||||||
public OpcDaMachine(string id, string connectionString, IEnumerable<AddressUnit> getAddresses, bool keepConnect, bool isRegexOn = false)
|
|
||||||
: base(id, getAddresses, keepConnect)
|
|
||||||
{
|
|
||||||
BaseUtility = new OpcDaUtility(connectionString, isRegexOn);
|
|
||||||
((OpcUtility)BaseUtility).GetSeperator +=
|
|
||||||
() => ((AddressFormaterOpc<string, string>)AddressFormater).Seperator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 构造函数
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id">设备的ID号</param>
|
|
||||||
/// <param name="connectionString">连接地址</param>
|
|
||||||
/// <param name="getAddresses">需要读写的数据</param>
|
|
||||||
public OpcDaMachine(string id, string connectionString, IEnumerable<AddressUnit> getAddresses)
|
|
||||||
: this(id, connectionString, getAddresses, false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
namespace Modbus.Net.OPC
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Opc Da协议Api入口
|
|
||||||
/// </summary>
|
|
||||||
public class OpcDaUtility : OpcUtility
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 构造函数
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="connectionString">连接地址</param>
|
|
||||||
/// <param name="isRegexOn">是否开启正则匹配</param>
|
|
||||||
public OpcDaUtility(string connectionString, bool isRegexOn = false) : base(connectionString)
|
|
||||||
{
|
|
||||||
Wrapper = new OpcDaProtocol(ConnectionString, isRegexOn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,41 +4,28 @@ using System.Collections.Generic;
|
|||||||
namespace Modbus.Net.OPC
|
namespace Modbus.Net.OPC
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Opc Da设备
|
/// Opc设备
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class OpcMachine<TKey, TUnitKey> : BaseMachine<TKey, TUnitKey> where TKey : IEquatable<TKey>
|
public class OpcMachine<TKey, TUnitKey> : BaseMachine<TKey, TUnitKey> where TKey : IEquatable<TKey>
|
||||||
where TUnitKey : IEquatable<TUnitKey>
|
where TUnitKey : IEquatable<TUnitKey>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">设备的ID号</param>
|
/// <param name="id">设备的ID号</param>
|
||||||
|
/// <param name="connectionType">连接类型</param>
|
||||||
|
/// <param name="connectionString">连接地址</param>
|
||||||
/// <param name="getAddresses">需要读写的地址</param>
|
/// <param name="getAddresses">需要读写的地址</param>
|
||||||
/// <param name="keepConnect">是否保持连接</param>
|
/// <param name="isRegexOn">开启正则匹配</param>
|
||||||
protected OpcMachine(TKey id, IEnumerable<AddressUnit<TUnitKey>> getAddresses, bool keepConnect)
|
protected OpcMachine(TKey id, OpcType connectionType, string connectionString, IEnumerable<AddressUnit<TUnitKey>> getAddresses, bool isRegexOn = false)
|
||||||
: base(id, getAddresses, keepConnect)
|
: base(id, getAddresses, true)
|
||||||
{
|
{
|
||||||
|
BaseUtility = new OpcUtility(connectionType, connectionString, isRegexOn);
|
||||||
|
AddressFormater = new AddressFormaterOpc<TKey, TUnitKey>((machine, unit) => { return new string[] { unit.Area }; }, this);
|
||||||
|
((OpcUtility)BaseUtility).GetSeperator +=
|
||||||
|
() => ((AddressFormaterOpc<TKey, TUnitKey>)AddressFormater).Seperator;
|
||||||
AddressCombiner = new AddressCombinerSingle<TUnitKey>();
|
AddressCombiner = new AddressCombinerSingle<TUnitKey>();
|
||||||
AddressCombinerSet = new AddressCombinerSingle<TUnitKey>();
|
AddressCombinerSet = new AddressCombinerSingle<TUnitKey>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Opc Da设备
|
|
||||||
/// </summary>
|
|
||||||
public abstract class OpcMachine : BaseMachine<string, string>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 构造函数
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id">设备的ID号</param>
|
|
||||||
/// <param name="getAddresses">需要读写的地址</param>
|
|
||||||
/// <param name="keepConnect">是否保持连接</param>
|
|
||||||
protected OpcMachine(string id, IEnumerable<AddressUnit> getAddresses, bool keepConnect)
|
|
||||||
: base(id, getAddresses, keepConnect)
|
|
||||||
{
|
|
||||||
AddressCombiner = new AddressCombinerSingle<string>();
|
|
||||||
AddressCombinerSet = new AddressCombinerSingle<string>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Modbus.Net.OPC
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Opc UA设备
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TKey">设备Id的类型</typeparam>
|
|
||||||
/// <typeparam name="TUnitKey">设备中地址的Id的类型</typeparam>
|
|
||||||
public class OpcUaMachine<TKey, TUnitKey> : OpcMachine<TKey, TUnitKey> where TKey : IEquatable<TKey>
|
|
||||||
where TUnitKey : IEquatable<TUnitKey>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 构造函数
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id">设备的ID号</param>
|
|
||||||
/// <param name="connectionString">连接地址</param>
|
|
||||||
/// <param name="getAddresses">需要读写的数据</param>
|
|
||||||
/// <param name="keepConnect">是否保持连接</param>
|
|
||||||
/// <param name="isRegexOn">是否开启正则匹配</param>
|
|
||||||
public OpcUaMachine(TKey id, string connectionString, IEnumerable<AddressUnit<TUnitKey>> getAddresses, bool keepConnect, bool isRegexOn = false)
|
|
||||||
: base(id, getAddresses, keepConnect)
|
|
||||||
{
|
|
||||||
BaseUtility = new OpcUaUtility(connectionString, isRegexOn);
|
|
||||||
((OpcUtility)BaseUtility).GetSeperator +=
|
|
||||||
() => ((AddressFormaterOpc<string, string>)AddressFormater).Seperator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 构造函数
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id">设备的ID号</param>
|
|
||||||
/// <param name="connectionString">连接地址</param>
|
|
||||||
/// <param name="getAddresses">需要读写的数据</param>
|
|
||||||
public OpcUaMachine(TKey id, string connectionString, IEnumerable<AddressUnit<TUnitKey>> getAddresses)
|
|
||||||
: this(id, connectionString, getAddresses, false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Opc UA设备
|
|
||||||
/// </summary>
|
|
||||||
public class OpcUaMachine : OpcMachine
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 构造函数
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id">设备的ID号</param>
|
|
||||||
/// <param name="connectionString">连接地址</param>
|
|
||||||
/// <param name="getAddresses">需要读写的数据</param>
|
|
||||||
/// <param name="keepConnect">是否保持连接</param>
|
|
||||||
/// <param name="isRegexOn">是否开启正则匹配</param>
|
|
||||||
public OpcUaMachine(string id, string connectionString, IEnumerable<AddressUnit> getAddresses, bool keepConnect, bool isRegexOn = false)
|
|
||||||
: base(id, getAddresses, keepConnect)
|
|
||||||
{
|
|
||||||
BaseUtility = new OpcUaUtility(connectionString, isRegexOn);
|
|
||||||
((OpcUtility)BaseUtility).GetSeperator +=
|
|
||||||
() => ((AddressFormaterOpc<string, string>)AddressFormater).Seperator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 构造函数
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id">设备的ID号</param>
|
|
||||||
/// <param name="connectionString">连接地址</param>
|
|
||||||
/// <param name="getAddresses">需要读写的数据</param>
|
|
||||||
public OpcUaMachine(string id, string connectionString, IEnumerable<AddressUnit> getAddresses)
|
|
||||||
: this(id, connectionString, getAddresses, false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
namespace Modbus.Net.OPC
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Opc Ua协议Api入口
|
|
||||||
/// </summary>
|
|
||||||
public class OpcUaUtility : OpcUtility
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 构造函数
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="connectionString">连接地址</param>
|
|
||||||
/// <param name="isRegexOn">是否开启正则匹配</param>
|
|
||||||
public OpcUaUtility(string connectionString, bool isRegexOn = false) : base(connectionString)
|
|
||||||
{
|
|
||||||
Wrapper = new OpcUaProtocol(ConnectionString, isRegexOn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,15 +4,61 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Modbus.Net.OPC
|
namespace Modbus.Net.OPC
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Opc类型
|
||||||
|
/// </summary>
|
||||||
|
public enum OpcType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// DA连接
|
||||||
|
/// </summary>
|
||||||
|
Da=0,
|
||||||
|
/// <summary>
|
||||||
|
/// UA连接
|
||||||
|
/// </summary>
|
||||||
|
Ua=1
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Opc通用Api入口
|
/// Opc通用Api入口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class OpcUtility : BaseUtility<OpcParamIn, OpcParamOut, ProtocolUnit<OpcParamIn, OpcParamOut>,
|
public class OpcUtility : BaseUtility<OpcParamIn, OpcParamOut, ProtocolUnit<OpcParamIn, OpcParamOut>,
|
||||||
PipeUnit<OpcParamIn, OpcParamOut, IProtocolLinker<OpcParamIn, OpcParamOut>,
|
PipeUnit<OpcParamIn, OpcParamOut, IProtocolLinker<OpcParamIn, OpcParamOut>,
|
||||||
ProtocolUnit<OpcParamIn, OpcParamOut>>>
|
ProtocolUnit<OpcParamIn, OpcParamOut>>>
|
||||||
{
|
{
|
||||||
private static readonly ILogger<OpcUtility> logger = LogProvider.CreateLogger<OpcUtility>();
|
private static readonly ILogger<OpcUtility> logger = LogProvider.CreateLogger<OpcUtility>();
|
||||||
|
|
||||||
|
private OpcType _opcType;
|
||||||
|
|
||||||
|
private bool IsRegexOn { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 协议类型
|
||||||
|
/// </summary>
|
||||||
|
public OpcType OpcType
|
||||||
|
{
|
||||||
|
get { return _opcType; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_opcType = value;
|
||||||
|
switch (_opcType)
|
||||||
|
{
|
||||||
|
//Da协议
|
||||||
|
case OpcType.Da:
|
||||||
|
{
|
||||||
|
Wrapper = new OpcDaProtocol(ConnectionString, IsRegexOn);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//Ua协议
|
||||||
|
case OpcType.Ua:
|
||||||
|
{
|
||||||
|
Wrapper = new OpcUaProtocol(ConnectionString, IsRegexOn);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取分隔符
|
/// 获取分隔符
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -22,10 +68,28 @@ namespace Modbus.Net.OPC
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="connectionType">连接类型</param>
|
||||||
/// <param name="connectionString">连接地址</param>
|
/// <param name="connectionString">连接地址</param>
|
||||||
protected OpcUtility(string connectionString) : base(0, 0)
|
/// <param name="isRegexOn">是否开启正则匹配</param>
|
||||||
|
public OpcUtility(int connectionType, string connectionString, bool isRegexOn = false) : base(0, 0)
|
||||||
{
|
{
|
||||||
|
OpcType = (OpcType)connectionType;
|
||||||
ConnectionString = connectionString;
|
ConnectionString = connectionString;
|
||||||
|
IsRegexOn = isRegexOn;
|
||||||
|
AddressTranslator = new AddressTranslatorOpc();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构造函数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connectionType">连接类型</param>
|
||||||
|
/// <param name="connectionString">连接地址</param>
|
||||||
|
/// <param name="isRegexOn">是否开启正则匹配</param>
|
||||||
|
public OpcUtility(OpcType connectionType, string connectionString, bool isRegexOn = false) : base(0, 0)
|
||||||
|
{
|
||||||
|
OpcType = connectionType;
|
||||||
|
ConnectionString = connectionString;
|
||||||
|
IsRegexOn = isRegexOn;
|
||||||
AddressTranslator = new AddressTranslatorOpc();
|
AddressTranslator = new AddressTranslatorOpc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -281,10 +281,10 @@ namespace Modbus.Net
|
|||||||
new ReturnUnit<double>
|
new ReturnUnit<double>
|
||||||
{
|
{
|
||||||
DeviceValue =
|
DeviceValue =
|
||||||
Convert.ToDouble(
|
Math.Round(Convert.ToDouble(
|
||||||
ValueHelper.GetInstance(BaseUtility.Endian)
|
ValueHelper.GetInstance(BaseUtility.Endian)
|
||||||
.GetValue(datas.Datas, ref localMainPos, ref localSubPos,
|
.GetValue(datas.Datas, ref localMainPos, ref localSubPos,
|
||||||
address.DataType)) * address.Zoom,
|
address.DataType)) * address.Zoom, address.DecimalPos),
|
||||||
AddressUnit = address.MapAddressUnitTUnitKeyToAddressUnit(),
|
AddressUnit = address.MapAddressUnitTUnitKeyToAddressUnit(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user