2017-10-27 update 1 BaseController and IController First Commit (Not complete, temporary disable all serial port codes.)
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<AssemblyName>Modbus.Net.Core</AssemblyName>
|
||||
<RootNamespace>Modbus.Net</RootNamespace>
|
||||
<PackageId>Modbus.Net.Core</PackageId>
|
||||
<Version>1.4.0</Version>
|
||||
<Version>1.4.1</Version>
|
||||
<Product>Modbus.Net</Product>
|
||||
<Authors>Chris L.(Luo Sheng)</Authors>
|
||||
<Company>Hangzhou Delian IoT Science Technology Co.,Ltd.</Company>
|
||||
@@ -51,9 +51,13 @@
|
||||
<Compile Include="..\src\Base.Common\IUtilityMethod.cs" Link="IUtilityMethod.cs" />
|
||||
<Compile Include="..\src\Base.Common\IMachineMethod.cs" Link="IMachineMethod.cs" />
|
||||
<Compile Include="..\src\Base.Common\IConnector.cs" Link="IConnector.cs" />
|
||||
<!--
|
||||
<Compile Include="..\src\Base.Common\ComProtocalLinker.cs" Link="ComProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Base.Common\ComConnector.cs" Link="ComConnector.cs" />
|
||||
-->
|
||||
<Compile Include="..\src\Base.Common\PipeUnit.cs" Link="PipeUnit.cs" />
|
||||
<Compile Include="..\src\Base.Common\IController.cs" Link="IController.cs" />
|
||||
<Compile Include="..\src\Base.Common\BaseController.cs" Link="BaseController.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<AssemblyName>Modbus.Net.Modbus.Core</AssemblyName>
|
||||
<RootNamespace>Modbus.Net.Modbus</RootNamespace>
|
||||
<PackageId>Modbus.Net.Modbus.Core</PackageId>
|
||||
<Version>1.4.0</Version>
|
||||
<Version>1.4.1</Version>
|
||||
<Authors>Chris L.(Luo Sheng)</Authors>
|
||||
<Company>Hangzhou Delian IoT Science Technology Co.,Ltd.</Company>
|
||||
<Product>Modbus.Net.Modbus</Product>
|
||||
@@ -28,17 +28,21 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="..\src\Modbus.Common\AddressFormaterModbus.cs" Link="AddressFormaterModbus.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\AddressTranslatorModbus.cs" Link="AddressTranslatorModbus.cs" />
|
||||
<!--
|
||||
<Compile Include="..\src\Modbus.Common\ModbusAsciiProtocal.cs" Link="ModbusAsciiProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusAsciiProtocalLinker.cs" Link="ModbusAsciiProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusAsciiInTcpProtocal.cs" Link="ModbusAsciiInTcpProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusAsciiInTcpProtocalLinker.cs" Link="ModbusAsciiInTcpProtocalLinker.cs" />
|
||||
-->
|
||||
<Compile Include="..\src\Modbus.Common\ModbusMachine.cs" Link="ModbusMachine.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusProtocal.cs" Link="ModbusProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusProtocalLinkerBytesExtend.cs" Link="ModbusProtocalLinkerBytesExtend.cs" />
|
||||
<!--
|
||||
<Compile Include="..\src\Modbus.Common\ModbusRtuProtocal.cs" Link="ModbusRtuProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusRtuProtocalLinker.cs" Link="ModbusRtuProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusRtuInTcpProtocal.cs" Link="ModbusRtuInTcpProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusRtuInTcpProtocalLinker.cs" Link="ModbusRtuInTcpProtocalLinker.cs" />
|
||||
-->
|
||||
<Compile Include="..\src\Modbus.Common\ModbusTcpProtocal.cs" Link="ModbusTcpProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusTcpProtocalLinker.cs" Link="ModbusTcpProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusUtility.cs" Link="ModbusUtility.cs" />
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<AssemblyName>Modbus.Net.Modbus</AssemblyName>
|
||||
<RootNamespace>Modbus.Net.Modbus</RootNamespace>
|
||||
<PackageId>Modbus.Net.Modbus</PackageId>
|
||||
<Version>1.4.0</Version>
|
||||
<Version>1.4.1</Version>
|
||||
<Authors>Chris L.(Luo Sheng)</Authors>
|
||||
<Company>Hangzhou Delian IoT Science Technology Co.,Ltd.</Company>
|
||||
<Product>Modbus.Net.Modbus</Product>
|
||||
@@ -33,17 +33,21 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="..\src\Modbus.Common\AddressFormaterModbus.cs" Link="AddressFormaterModbus.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\AddressTranslatorModbus.cs" Link="AddressTranslatorModbus.cs" />
|
||||
<!--
|
||||
<Compile Include="..\src\Modbus.Common\ModbusAsciiProtocal.cs" Link="ModbusAsciiProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusAsciiProtocalLinker.cs" Link="ModbusAsciiProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusAsciiInTcpProtocal.cs" Link="ModbusAsciiInTcpProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusAsciiInTcpProtocalLinker.cs" Link="ModbusAsciiInTcpProtocalLinker.cs" />
|
||||
-->
|
||||
<Compile Include="..\src\Modbus.Common\ModbusMachine.cs" Link="ModbusMachine.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusProtocal.cs" Link="ModbusProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusProtocalLinkerBytesExtend.cs" Link="ModbusProtocalLinkerBytesExtend.cs" />
|
||||
<!--
|
||||
<Compile Include="..\src\Modbus.Common\ModbusRtuProtocal.cs" Link="ModbusRtuProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusRtuProtocalLinker.cs" Link="ModbusRtuProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusRtuInTcpProtocal.cs" Link="ModbusRtuInTcpProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusRtuInTcpProtocalLinker.cs" Link="ModbusRtuInTcpProtocalLinker.cs" />
|
||||
-->
|
||||
<Compile Include="..\src\Modbus.Common\ModbusTcpProtocal.cs" Link="ModbusTcpProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusTcpProtocalLinker.cs" Link="ModbusTcpProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusUtility.cs" Link="ModbusUtility.cs" />
|
||||
|
||||
@@ -15,9 +15,9 @@ namespace Modbus.Net.OPC.FBox
|
||||
/// <param name="linkerName">设备名称</param>
|
||||
/// <param name="getAddresses">获取地址</param>
|
||||
/// <param name="keepConnect">是否保持连接</param>
|
||||
public FBoxOpcDaMachine(string localSequence, string linkerName,
|
||||
public FBoxOpcDaMachine(string id, string localSequence, string linkerName,
|
||||
IEnumerable<AddressUnit> getAddresses, bool keepConnect)
|
||||
: base(
|
||||
: base(id,
|
||||
ConfigurationManager.AppSettings["FBoxOpcDaHost"] ?? "opcda://localhost/FBoxOpcServer", getAddresses,
|
||||
keepConnect, true)
|
||||
{
|
||||
@@ -39,9 +39,9 @@ namespace Modbus.Net.OPC.FBox
|
||||
/// <param name="localSequence">页名称</param>
|
||||
/// <param name="linkerName">设备名称</param>
|
||||
/// <param name="getAddresses">获取地址</param>
|
||||
public FBoxOpcDaMachine(string localSequence, string linkerName,
|
||||
public FBoxOpcDaMachine(string id, string localSequence, string linkerName,
|
||||
IEnumerable<AddressUnit> getAddresses)
|
||||
: this(localSequence, linkerName, getAddresses, false)
|
||||
: this(id, localSequence, linkerName, getAddresses, false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<AssemblyName>Modbus.Net.OPC</AssemblyName>
|
||||
<RootNamespace>Modbus.Net.OPC</RootNamespace>
|
||||
<PackageId>Modbus.Net.OPC</PackageId>
|
||||
<Version>1.4.0</Version>
|
||||
<Version>1.4.1</Version>
|
||||
<Authors>Chris L.(Luo Sheng)</Authors>
|
||||
<Company>Hangzhou Delian IoT Science Technology Co.,Ltd.</Company>
|
||||
<Description>Modbus.Net OPC Implementation</Description>
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Modbus.Net.OPC
|
||||
/// <summary>
|
||||
/// Opc连接器
|
||||
/// </summary>
|
||||
public abstract class OpcConnector : BaseConnector<OpcParamIn, OpcParamOut>
|
||||
public abstract class OpcConnector : IConnector<OpcParamIn, OpcParamOut>
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否正在连接
|
||||
@@ -43,18 +43,18 @@ namespace Modbus.Net.OPC
|
||||
/// <summary>
|
||||
/// 连接标识
|
||||
/// </summary>
|
||||
public override string ConnectionToken { get; }
|
||||
public virtual string ConnectionToken { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否正在连接
|
||||
/// </summary>
|
||||
public override bool IsConnected => _connect;
|
||||
public virtual bool IsConnected => _connect;
|
||||
|
||||
/// <summary>
|
||||
/// 断开连接
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override bool Disconnect()
|
||||
public virtual bool Disconnect()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -77,17 +77,7 @@ namespace Modbus.Net.OPC
|
||||
/// </summary>
|
||||
/// <param name="message">需要发送的数据</param>
|
||||
/// <returns>是否发送成功</returns>
|
||||
public override OpcParamOut SendMsg(OpcParamIn message)
|
||||
{
|
||||
return AsyncHelper.RunSync(() => SendMsgAsync(message));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 带返回发送数据
|
||||
/// </summary>
|
||||
/// <param name="message">需要发送的数据</param>
|
||||
/// <returns>是否发送成功</returns>
|
||||
public override async Task<OpcParamOut> SendMsgAsync(OpcParamIn message)
|
||||
public virtual async Task<OpcParamOut> SendMsgAsync(OpcParamIn message)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -186,7 +176,7 @@ namespace Modbus.Net.OPC
|
||||
/// 连接PLC
|
||||
/// </summary>
|
||||
/// <returns>是否连接成功</returns>
|
||||
public override bool Connect()
|
||||
protected bool Connect()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -207,7 +197,7 @@ namespace Modbus.Net.OPC
|
||||
/// 连接PLC,异步
|
||||
/// </summary>
|
||||
/// <returns>是否连接成功</returns>
|
||||
public override Task<bool> ConnectAsync()
|
||||
public virtual Task<bool> ConnectAsync()
|
||||
{
|
||||
return Task.FromResult(Connect());
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace Modbus.Net.OPC
|
||||
/// <param name="getAddresses">需要读写的数据</param>
|
||||
/// <param name="keepConnect">是否保持连接</param>
|
||||
/// <param name="isRegexOn">是否开启正则匹配</param>
|
||||
public OpcDaMachine(string connectionString, IEnumerable<AddressUnit<TUnitKey>> getAddresses, bool keepConnect, bool isRegexOn = false)
|
||||
: base(getAddresses, keepConnect)
|
||||
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 +=
|
||||
@@ -31,8 +31,8 @@ namespace Modbus.Net.OPC
|
||||
/// </summary>
|
||||
/// <param name="connectionString">连接地址</param>
|
||||
/// <param name="getAddresses">需要读写的数据</param>
|
||||
public OpcDaMachine(string connectionString, IEnumerable<AddressUnit<TUnitKey>> getAddresses)
|
||||
: this(connectionString, getAddresses, false)
|
||||
public OpcDaMachine(TKey id, string connectionString, IEnumerable<AddressUnit<TUnitKey>> getAddresses)
|
||||
: this(id, connectionString, getAddresses, false)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -49,8 +49,8 @@ namespace Modbus.Net.OPC
|
||||
/// <param name="getAddresses">需要读写的数据</param>
|
||||
/// <param name="keepConnect">是否保持连接</param>
|
||||
/// <param name="isRegexOn">是否开启正则匹配</param>
|
||||
public OpcDaMachine(string connectionString, IEnumerable<AddressUnit> getAddresses, bool keepConnect, bool isRegexOn = false)
|
||||
: base(getAddresses, keepConnect)
|
||||
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 +=
|
||||
@@ -62,8 +62,8 @@ namespace Modbus.Net.OPC
|
||||
/// </summary>
|
||||
/// <param name="connectionString">连接地址</param>
|
||||
/// <param name="getAddresses">需要读写的数据</param>
|
||||
public OpcDaMachine(string connectionString, IEnumerable<AddressUnit> getAddresses)
|
||||
: this(connectionString, getAddresses, false)
|
||||
public OpcDaMachine(string id, string connectionString, IEnumerable<AddressUnit> getAddresses)
|
||||
: this(id, connectionString, getAddresses, false)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,15 +22,6 @@ namespace Modbus.Net.OPC
|
||||
_isRegexOn = isRegexOn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
/// <returns>是否连接成功</returns>
|
||||
public override bool Connect()
|
||||
{
|
||||
return AsyncHelper.RunSync(ConnectAsync);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace Modbus.Net.OPC
|
||||
/// </summary>
|
||||
/// <param name="getAddresses">需要读写的地址</param>
|
||||
/// <param name="keepConnect">是否保持连接</param>
|
||||
protected OpcMachine(IEnumerable<AddressUnit<TUnitKey>> getAddresses, bool keepConnect)
|
||||
: base(getAddresses, keepConnect)
|
||||
protected OpcMachine(TKey id, IEnumerable<AddressUnit<TUnitKey>> getAddresses, bool keepConnect)
|
||||
: base(id, getAddresses, keepConnect)
|
||||
{
|
||||
AddressCombiner = new AddressCombinerSingle<TUnitKey>();
|
||||
AddressCombinerSet = new AddressCombinerSingle<TUnitKey>();
|
||||
@@ -32,8 +32,8 @@ namespace Modbus.Net.OPC
|
||||
/// </summary>
|
||||
/// <param name="getAddresses">需要读写的地址</param>
|
||||
/// <param name="keepConnect">是否保持连接</param>
|
||||
protected OpcMachine(IEnumerable<AddressUnit> getAddresses, bool keepConnect)
|
||||
: base(getAddresses, keepConnect)
|
||||
protected OpcMachine(string id, IEnumerable<AddressUnit> getAddresses, bool keepConnect)
|
||||
: base(id, getAddresses, keepConnect)
|
||||
{
|
||||
AddressCombiner = new AddressCombinerSingle();
|
||||
AddressCombinerSet = new AddressCombinerSingle();
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace Modbus.Net.OPC
|
||||
/// <param name="getAddresses">需要读写的数据</param>
|
||||
/// <param name="keepConnect">是否保持连接</param>
|
||||
/// <param name="isRegexOn">是否开启正则匹配</param>
|
||||
public OpcUaMachine(string connectionString, IEnumerable<AddressUnit<TUnitKey>> getAddresses, bool keepConnect, bool isRegexOn = false)
|
||||
: base(getAddresses, keepConnect)
|
||||
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 +=
|
||||
@@ -31,8 +31,8 @@ namespace Modbus.Net.OPC
|
||||
/// </summary>
|
||||
/// <param name="connectionString">连接地址</param>
|
||||
/// <param name="getAddresses">需要读写的数据</param>
|
||||
public OpcUaMachine(string connectionString, IEnumerable<AddressUnit<TUnitKey>> getAddresses)
|
||||
: this(connectionString, getAddresses, false)
|
||||
public OpcUaMachine(TKey id, string connectionString, IEnumerable<AddressUnit<TUnitKey>> getAddresses)
|
||||
: this(id, connectionString, getAddresses, false)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -49,8 +49,8 @@ namespace Modbus.Net.OPC
|
||||
/// <param name="getAddresses">需要读写的数据</param>
|
||||
/// <param name="keepConnect">是否保持连接</param>
|
||||
/// <param name="isRegexOn">是否开启正则匹配</param>
|
||||
public OpcUaMachine(string connectionString, IEnumerable<AddressUnit> getAddresses, bool keepConnect, bool isRegexOn = false)
|
||||
: base(getAddresses, keepConnect)
|
||||
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 +=
|
||||
@@ -62,8 +62,8 @@ namespace Modbus.Net.OPC
|
||||
/// </summary>
|
||||
/// <param name="connectionString">连接地址</param>
|
||||
/// <param name="getAddresses">需要读写的数据</param>
|
||||
public OpcUaMachine(string connectionString, IEnumerable<AddressUnit> getAddresses)
|
||||
: this(connectionString, getAddresses, false)
|
||||
public OpcUaMachine(string id, string connectionString, IEnumerable<AddressUnit> getAddresses)
|
||||
: this(id, connectionString, getAddresses, false)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,15 +22,6 @@ namespace Modbus.Net.OPC
|
||||
_isRegexOn = isRegexOn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
/// <returns>是否连接成功</returns>
|
||||
public override bool Connect()
|
||||
{
|
||||
return AsyncHelper.RunSync(ConnectAsync);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<AssemblyName>Modbus.Net.Siemens.Core</AssemblyName>
|
||||
<RootNamespace>Modbus.Net.Siemens</RootNamespace>
|
||||
<PackageId>Modbus.Net.Siemens.Core</PackageId>
|
||||
<Version>1.4.0</Version>
|
||||
<Version>1.4.1</Version>
|
||||
<Authors>Chris L.(Luo Sheng)</Authors>
|
||||
<Company>Hangzhou Delian IoT Science Technology Co.,Ltd.</Company>
|
||||
<Description>Modbus.Net Siemens Profinet Implementation</Description>
|
||||
@@ -29,8 +29,10 @@
|
||||
<Compile Include="..\src\Siemens.Common\AddressFormaterSiemens.cs" Link="AddressFormaterSiemens.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\AddressTranslatorSiemens.cs" Link="AddressTranslatorSiemens.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensMachine.cs" Link="SiemensMachine.cs" />
|
||||
<!--
|
||||
<Compile Include="..\src\Siemens.Common\SiemensPpiProtocal.cs" Link="SiemensPpiProtocal.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensPpiProtocalLinker.cs" Link="SiemensPpiProtocalLinker.cs" />
|
||||
-->
|
||||
<Compile Include="..\src\Siemens.Common\SiemensProtocal.cs" Link="SiemensProtocal.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensProtocalLinkerBytesExtend.cs" Link="SiemensProtocalLinkerBytesExtend.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensTcpProtocal.cs" Link="SiemensTcpProtocal.cs" />
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<AssemblyName>Modbus.Net.Siemens</AssemblyName>
|
||||
<RootNamespace>Modbus.Net.Siemens</RootNamespace>
|
||||
<PackageId>Modbus.Net.Siemens</PackageId>
|
||||
<Version>1.4.0</Version>
|
||||
<Version>1.4.1</Version>
|
||||
<Authors>Chris L.(Luo Sheng)</Authors>
|
||||
<Company>Hangzhou Delian IoT Science Technology Co.,Ltd.</Company>
|
||||
<Description>Modbus.Net Siemens Profinet Implementation</Description>
|
||||
@@ -29,8 +29,10 @@
|
||||
<Compile Include="..\src\Siemens.Common\AddressFormaterSiemens.cs" Link="AddressFormaterSiemens.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\AddressTranslatorSiemens.cs" Link="AddressTranslatorSiemens.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensMachine.cs" Link="SiemensMachine.cs" />
|
||||
<!--
|
||||
<Compile Include="..\src\Siemens.Common\SiemensPpiProtocal.cs" Link="SiemensPpiProtocal.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensPpiProtocalLinker.cs" Link="SiemensPpiProtocalLinker.cs" />
|
||||
-->
|
||||
<Compile Include="..\src\Siemens.Common\SiemensProtocal.cs" Link="SiemensProtocal.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensProtocalLinkerBytesExtend.cs" Link="SiemensProtocalLinkerBytesExtend.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensTcpProtocal.cs" Link="SiemensTcpProtocal.cs" />
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<AssemblyName>Modbus.Net</AssemblyName>
|
||||
<RootNamespace>Modbus.Net</RootNamespace>
|
||||
<PackageId>Modbus.Net</PackageId>
|
||||
<Version>1.4.0</Version>
|
||||
<Version>1.4.1</Version>
|
||||
<Product>Modbus.Net</Product>
|
||||
<Authors>Chris L.(Luo Sheng)</Authors>
|
||||
<Company>Hangzhou Delian IoT Science Technology Co.,Ltd.</Company>
|
||||
@@ -51,9 +51,13 @@
|
||||
<Compile Include="..\src\Base.Common\IUtilityMethod.cs" Link="IUtilityMethod.cs" />
|
||||
<Compile Include="..\src\Base.Common\IMachineMethod.cs" Link="IMachineMethod.cs" />
|
||||
<Compile Include="..\src\Base.Common\IConnector.cs" Link="IConnector.cs" />
|
||||
<!--
|
||||
<Compile Include="..\src\Base.Common\ComProtocalLinker.cs" Link="ComProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Base.Common\ComConnector.cs" Link="ComConnector.cs" />
|
||||
-->
|
||||
<Compile Include="..\src\Base.Common\PipeUnit.cs" Link="PipeUnit.cs" />
|
||||
<Compile Include="..\src\Base.Common\IController.cs" Link="IController.cs" />
|
||||
<Compile Include="..\src\Base.Common\BaseController.cs" Link="BaseController.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -14,6 +14,17 @@ namespace Modbus.Net
|
||||
/// </summary>
|
||||
public abstract class BaseConnector<TParamIn, TParamOut> : IConnector<TParamIn, TParamOut>
|
||||
{
|
||||
//protected delegate MessageReturnCallbackArgs MessageReturnDelegate(object sender, MessageReturnArgs args);
|
||||
|
||||
//protected event MessageReturnDelegate MessageReturn;
|
||||
|
||||
public void AddController(IController controller)
|
||||
{
|
||||
Controller = controller;
|
||||
}
|
||||
|
||||
protected IController Controller { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 标识Connector的连接关键字
|
||||
/// </summary>
|
||||
@@ -24,12 +35,6 @@ namespace Modbus.Net
|
||||
/// </summary>
|
||||
public abstract bool IsConnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 连接PLC
|
||||
/// </summary>
|
||||
/// <returns>是否连接成功</returns>
|
||||
public abstract bool Connect();
|
||||
|
||||
/// <summary>
|
||||
/// 连接PLC,异步
|
||||
/// </summary>
|
||||
@@ -47,13 +52,36 @@ namespace Modbus.Net
|
||||
/// </summary>
|
||||
/// <param name="message">需要发送的数据</param>
|
||||
/// <returns>是否发送成功</returns>
|
||||
public abstract TParamOut SendMsg(TParamIn message);
|
||||
public abstract Task<TParamOut> SendMsgAsync(TParamIn message);
|
||||
|
||||
/// <summary>
|
||||
/// 带返回发送数据
|
||||
/// 发送数据,不确认
|
||||
/// </summary>
|
||||
/// <param name="message">需要发送的数据</param>
|
||||
/// <returns>是否发送成功</returns>
|
||||
public abstract Task<TParamOut> SendMsgAsync(TParamIn message);
|
||||
protected abstract Task SendMsgWithoutConfirm(TParamIn message);
|
||||
|
||||
/// <summary>
|
||||
/// 接收消息单独线程开启
|
||||
/// </summary>
|
||||
protected abstract void ReceiveMsgThreadStart();
|
||||
|
||||
/// <summary>
|
||||
/// 接收消息单独线程停止
|
||||
/// </summary>
|
||||
protected abstract void ReceiveMsgThreadStop();
|
||||
}
|
||||
|
||||
/*public class MessageReturnArgs
|
||||
{
|
||||
public byte[] ReturnMessage { get; set; }
|
||||
|
||||
public string MessageKey { get; set; }
|
||||
}
|
||||
|
||||
public class MessageReturnCallbackArgs
|
||||
{
|
||||
public bool ShouldLockSender { get; set; } = false;
|
||||
|
||||
public bool ShouldReleaseSender { get; set; } = false;
|
||||
}*/
|
||||
}
|
||||
175
Modbus.Net/src/Base.Common/BaseController.cs
Normal file
175
Modbus.Net/src/Base.Common/BaseController.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace Modbus.Net
|
||||
{
|
||||
public abstract class BaseController : IController
|
||||
{
|
||||
protected List<MessageWaitingDef> WaitingMessages { get; set; }
|
||||
|
||||
protected Task SendingThread { get; set; }
|
||||
protected bool _taskCancel = false;
|
||||
|
||||
protected BaseController()
|
||||
{
|
||||
WaitingMessages = new List<MessageWaitingDef>();
|
||||
}
|
||||
|
||||
public MessageWaitingDef AddMessage(byte[] sendMessage)
|
||||
{
|
||||
var def = new MessageWaitingDef
|
||||
{
|
||||
Key = GetKeyFromMessage(sendMessage),
|
||||
SendMessage = sendMessage,
|
||||
SendMutex = new AutoResetEvent(false),
|
||||
ReceiveMutex = new AutoResetEvent(false)
|
||||
};
|
||||
AddMessageToList(def);
|
||||
return def;
|
||||
}
|
||||
|
||||
protected abstract void SendingMessageControlInner();
|
||||
|
||||
public void SendStop()
|
||||
{
|
||||
_taskCancel = true;
|
||||
}
|
||||
|
||||
public void SendStart()
|
||||
{
|
||||
if (SendingThread == null)
|
||||
{
|
||||
SendingThread = Task.Run(()=>SendingMessageControlInner());
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
lock (WaitingMessages)
|
||||
{
|
||||
WaitingMessages.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void AddMessageToList(MessageWaitingDef def)
|
||||
{
|
||||
lock (WaitingMessages)
|
||||
{
|
||||
WaitingMessages.Add(def);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract string GetKeyFromMessage(byte[] message);
|
||||
|
||||
public bool ConfirmMessage(byte[] receiveMessage)
|
||||
{
|
||||
var def = GetMessageFromWaitingList(receiveMessage);
|
||||
if (def != null)
|
||||
{
|
||||
def.ReceiveMessage = receiveMessage;
|
||||
lock (WaitingMessages)
|
||||
{
|
||||
WaitingMessages.Remove(def);
|
||||
}
|
||||
def.ReceiveMutex.Set();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract MessageWaitingDef GetMessageFromWaitingList(byte[] receiveMessage);
|
||||
|
||||
public void ForceRemoveWaitingMessage(MessageWaitingDef def)
|
||||
{
|
||||
lock (WaitingMessages)
|
||||
{
|
||||
WaitingMessages.Remove(def);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MessageWaitingDef
|
||||
{
|
||||
public string Key { get; set; }
|
||||
|
||||
public byte[] SendMessage { get; set; }
|
||||
|
||||
public byte[] ReceiveMessage { get; set; }
|
||||
|
||||
public EventWaitHandle SendMutex { get; set; }
|
||||
|
||||
public EventWaitHandle ReceiveMutex { get; set; }
|
||||
}
|
||||
|
||||
public class FIFOController : BaseController
|
||||
{
|
||||
private MessageWaitingDef _currentSendingPos;
|
||||
|
||||
public int AcquireTime { get; }
|
||||
|
||||
public FIFOController(int acquireTime)
|
||||
{
|
||||
AcquireTime = acquireTime;
|
||||
}
|
||||
|
||||
protected override void SendingMessageControlInner()
|
||||
{
|
||||
try
|
||||
{
|
||||
while (!_taskCancel)
|
||||
{
|
||||
if (AcquireTime > 0)
|
||||
{
|
||||
Thread.Sleep(AcquireTime);
|
||||
}
|
||||
lock (WaitingMessages)
|
||||
{
|
||||
if (_currentSendingPos == null)
|
||||
{
|
||||
if (WaitingMessages.Count > 0)
|
||||
{
|
||||
_currentSendingPos = WaitingMessages.First();
|
||||
}
|
||||
}
|
||||
if (_currentSendingPos != null)
|
||||
{
|
||||
_currentSendingPos.SendMutex.Set();
|
||||
if (WaitingMessages.Count <= 1)
|
||||
{
|
||||
_currentSendingPos = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentSendingPos = WaitingMessages[WaitingMessages.IndexOf(_currentSendingPos) + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
//ignore
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Log.Error(e, "Controller thorws exception");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected override string GetKeyFromMessage(byte[] message)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override MessageWaitingDef GetMessageFromWaitingList(byte[] receiveMessage)
|
||||
{
|
||||
return WaitingMessages.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ namespace Modbus.Net
|
||||
/// 构造器
|
||||
/// </summary>
|
||||
/// <param name="getAddresses">需要与设备通讯的地址</param>
|
||||
protected BaseMachine(IEnumerable<AddressUnit> getAddresses) : base(getAddresses)
|
||||
protected BaseMachine(string id, IEnumerable<AddressUnit> getAddresses) : base(id, getAddresses)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -102,8 +102,8 @@ namespace Modbus.Net
|
||||
/// </summary>
|
||||
/// <param name="getAddresses">需要与设备通讯的地址</param>
|
||||
/// <param name="keepConnect">是否保持连接</param>
|
||||
protected BaseMachine(IEnumerable<AddressUnit> getAddresses, bool keepConnect)
|
||||
: base(getAddresses, keepConnect)
|
||||
protected BaseMachine(string id, IEnumerable<AddressUnit> getAddresses, bool keepConnect)
|
||||
: base(id, getAddresses, keepConnect)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -114,8 +114,8 @@ namespace Modbus.Net
|
||||
/// <param name="keepConnect">是否保持连接</param>
|
||||
/// <param name="slaveAddress">从站地址</param>
|
||||
/// <param name="masterAddress">主站地址</param>
|
||||
protected BaseMachine(IEnumerable<AddressUnit> getAddresses, bool keepConnect, byte slaveAddress,
|
||||
byte masterAddress) : base(getAddresses, keepConnect, slaveAddress, masterAddress)
|
||||
protected BaseMachine(string id, IEnumerable<AddressUnit> getAddresses, bool keepConnect, byte slaveAddress,
|
||||
byte masterAddress) : base(id, getAddresses, keepConnect, slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -135,8 +135,8 @@ namespace Modbus.Net
|
||||
/// 构造器
|
||||
/// </summary>
|
||||
/// <param name="getAddresses">需要与设备通讯的地址</param>
|
||||
protected BaseMachine(IEnumerable<AddressUnit<TUnitKey>> getAddresses)
|
||||
: this(getAddresses, false)
|
||||
protected BaseMachine(TKey id, IEnumerable<AddressUnit<TUnitKey>> getAddresses)
|
||||
: this(id, getAddresses, false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -145,8 +145,9 @@ namespace Modbus.Net
|
||||
/// </summary>
|
||||
/// <param name="getAddresses">需要与设备通讯的地址</param>
|
||||
/// <param name="keepConnect">是否保持连接</param>
|
||||
protected BaseMachine(IEnumerable<AddressUnit<TUnitKey>> getAddresses, bool keepConnect)
|
||||
protected BaseMachine(TKey id, IEnumerable<AddressUnit<TUnitKey>> getAddresses, bool keepConnect)
|
||||
{
|
||||
Id = id;
|
||||
GetAddresses = getAddresses;
|
||||
KeepConnect = keepConnect;
|
||||
}
|
||||
@@ -158,8 +159,8 @@ namespace Modbus.Net
|
||||
/// <param name="keepConnect">是否保持连接</param>
|
||||
/// <param name="slaveAddress">从站地址</param>
|
||||
/// <param name="masterAddress">主站地址</param>
|
||||
protected BaseMachine(IEnumerable<AddressUnit<TUnitKey>> getAddresses, bool keepConnect, byte slaveAddress,
|
||||
byte masterAddress) : this(getAddresses, keepConnect)
|
||||
protected BaseMachine(TKey id, IEnumerable<AddressUnit<TUnitKey>> getAddresses, bool keepConnect, byte slaveAddress,
|
||||
byte masterAddress) : this(id, getAddresses, keepConnect)
|
||||
{
|
||||
SlaveAddress = slaveAddress;
|
||||
MasterAddress = masterAddress;
|
||||
@@ -604,15 +605,6 @@ namespace Modbus.Net
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
/// <returns>是否连接成功</returns>
|
||||
public bool Connect()
|
||||
{
|
||||
return BaseUtility.Connect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
@@ -874,12 +866,6 @@ namespace Modbus.Net
|
||||
/// <returns>设备的方法集合</returns>
|
||||
TMachineMethod GetMachineMethods<TMachineMethod>() where TMachineMethod : class, IMachineMethod;
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
/// <returns>是否连接成功</returns>
|
||||
bool Connect();
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
|
||||
@@ -136,12 +136,6 @@ namespace Modbus.Net
|
||||
/// 协议连接开始
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract bool Connect();
|
||||
|
||||
/// <summary>
|
||||
/// 协议连接开始(异步)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract Task<bool> ConnectAsync();
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -250,15 +250,6 @@ namespace Modbus.Net
|
||||
/// </summary>
|
||||
public AddressTranslator AddressTranslator { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
/// <returns>设备是否连接成功</returns>
|
||||
public bool Connect()
|
||||
{
|
||||
return Wrapper.Connect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
@@ -323,12 +314,6 @@ namespace Modbus.Net
|
||||
/// </summary>
|
||||
AddressTranslator AddressTranslator { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
/// <returns>设备是否连接成功</returns>
|
||||
bool Connect();
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
|
||||
@@ -17,12 +17,6 @@ namespace Modbus.Net
|
||||
/// </summary>
|
||||
bool IsConnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 连接PLC
|
||||
/// </summary>
|
||||
/// <returns>是否连接成功</returns>
|
||||
bool Connect();
|
||||
|
||||
/// <summary>
|
||||
/// 连接PLC,异步
|
||||
/// </summary>
|
||||
@@ -35,13 +29,6 @@ namespace Modbus.Net
|
||||
/// <returns>是否断开成功</returns>
|
||||
bool Disconnect();
|
||||
|
||||
/// <summary>
|
||||
/// 带返回发送数据
|
||||
/// </summary>
|
||||
/// <param name="message">需要发送的数据</param>
|
||||
/// <returns>是否发送成功</returns>
|
||||
TParamOut SendMsg(TParamIn message);
|
||||
|
||||
/// <summary>
|
||||
/// 带返回发送数据
|
||||
/// </summary>
|
||||
|
||||
17
Modbus.Net/src/Base.Common/IController.cs
Normal file
17
Modbus.Net/src/Base.Common/IController.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace Modbus.Net
|
||||
{
|
||||
public interface IController
|
||||
{
|
||||
MessageWaitingDef AddMessage(byte[] sendMessage);
|
||||
|
||||
void SendStop();
|
||||
|
||||
void SendStart();
|
||||
|
||||
void Clear();
|
||||
|
||||
bool ConfirmMessage(byte[] receiveMessage);
|
||||
|
||||
void ForceRemoveWaitingMessage(MessageWaitingDef def);
|
||||
}
|
||||
}
|
||||
@@ -30,12 +30,6 @@ namespace Modbus.Net
|
||||
/// 协议连接开始
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
bool Connect();
|
||||
|
||||
/// <summary>
|
||||
/// 协议连接开始(异步)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<bool> ConnectAsync();
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -19,12 +19,6 @@ namespace Modbus.Net
|
||||
/// </summary>
|
||||
bool IsConnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
/// <returns>设备是否连接成功</returns>
|
||||
bool Connect();
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
|
||||
@@ -78,15 +78,6 @@ namespace Modbus.Net
|
||||
/// </summary>
|
||||
protected IConnector<TParamIn, TParamOut> BaseConnector;
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
/// <returns>设备是否连接成功</returns>
|
||||
public bool Connect()
|
||||
{
|
||||
return BaseConnector.Connect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
|
||||
@@ -52,6 +52,9 @@ namespace Modbus.Net
|
||||
|
||||
private bool m_disposed;
|
||||
|
||||
private Task _receiveThread;
|
||||
private bool _taskCancel = false;
|
||||
|
||||
/// <summary>
|
||||
/// 构造器
|
||||
/// </summary>
|
||||
@@ -138,15 +141,6 @@ namespace Modbus.Net
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接
|
||||
/// </summary>
|
||||
/// <returns>是否连接成功</returns>
|
||||
public override bool Connect()
|
||||
{
|
||||
return AsyncHelper.RunSync(ConnectAsync);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接
|
||||
/// </summary>
|
||||
@@ -175,6 +169,8 @@ namespace Modbus.Net
|
||||
}
|
||||
if (_socketClient.Connected)
|
||||
{
|
||||
Controller.SendStart();
|
||||
ReceiveMsgThreadStart();
|
||||
Log.Information("Tcp client {ConnectionToken} connected", ConnectionToken);
|
||||
return true;
|
||||
}
|
||||
@@ -219,17 +215,28 @@ namespace Modbus.Net
|
||||
/// </summary>
|
||||
/// <param name="message">发送的数据</param>
|
||||
/// <returns>是否发送成功</returns>
|
||||
public override byte[] SendMsg(byte[] message)
|
||||
public override async Task<byte[]> SendMsgAsync(byte[] message)
|
||||
{
|
||||
return AsyncHelper.RunSync(() => SendMsgAsync(message));
|
||||
var task = SendMsgInner(message).WithCancellation(new CancellationTokenSource(10000).Token);
|
||||
var ans = await task;
|
||||
if (task.IsCanceled)
|
||||
{
|
||||
Controller.ForceRemoveWaitingMessage(ans);
|
||||
return null;
|
||||
}
|
||||
return ans.ReceiveMessage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送数据,需要返回
|
||||
/// </summary>
|
||||
/// <param name="message">发送的数据</param>
|
||||
/// <returns>是否发送成功</returns>
|
||||
public override async Task<byte[]> SendMsgAsync(byte[] message)
|
||||
private async Task<MessageWaitingDef> SendMsgInner(byte[] message)
|
||||
{
|
||||
var messageSendingdef = Controller.AddMessage(message);
|
||||
messageSendingdef.SendMutex.WaitOne();
|
||||
await SendMsgWithoutConfirm(message);
|
||||
messageSendingdef.ReceiveMutex.WaitOne();
|
||||
return messageSendingdef;
|
||||
}
|
||||
|
||||
protected override async Task SendMsgWithoutConfirm(byte[] message)
|
||||
{
|
||||
var datagram = message;
|
||||
|
||||
@@ -245,45 +252,64 @@ namespace Modbus.Net
|
||||
Log.Verbose("Tcp client {ConnectionToken} send text len = {Length}", ConnectionToken, datagram.Length);
|
||||
Log.Verbose($"Tcp client {ConnectionToken} send: {String.Concat(datagram.Select(p => " " + p.ToString("X2")))}");
|
||||
await stream.WriteAsync(datagram, 0, datagram.Length);
|
||||
|
||||
var receiveBytes = await ReceiveAsync(stream);
|
||||
Log.Verbose("Tcp client {ConnectionToken} receive text len = {Length}", ConnectionToken,
|
||||
receiveBytes.Length);
|
||||
Log.Verbose($"Tcp client {ConnectionToken} receive: {String.Concat(receiveBytes.Select(p => " " + p.ToString("X2")))}");
|
||||
|
||||
RefreshReceiveCount();
|
||||
|
||||
return receiveBytes;
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Log.Error(err, "Tcp client {ConnectionToken} send exception", ConnectionToken);
|
||||
CloseClientSocket();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ReceiveMsgThreadStart()
|
||||
{
|
||||
_receiveThread = Task.Run(ReceiveMessage);
|
||||
}
|
||||
|
||||
protected override void ReceiveMsgThreadStop()
|
||||
{
|
||||
_taskCancel = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接收返回消息
|
||||
/// </summary>
|
||||
/// <param name="stream">Network Stream</param>
|
||||
/// <returns>返回的消息</returns>
|
||||
protected async Task<byte[]> ReceiveAsync(NetworkStream stream)
|
||||
protected async Task ReceiveMessage()
|
||||
{
|
||||
try
|
||||
{
|
||||
while (!_taskCancel)
|
||||
{
|
||||
NetworkStream stream = _socketClient.GetStream();
|
||||
var len = await stream.ReadAsync(_receiveBuffer, 0, _receiveBuffer.Length);
|
||||
stream.Flush();
|
||||
|
||||
// 异步接收回答
|
||||
if (len > 0)
|
||||
return CheckReplyDatagram(len);
|
||||
return null;
|
||||
{
|
||||
byte[] receiveBytes = CheckReplyDatagram(len);
|
||||
Log.Verbose("Tcp client {ConnectionToken} receive text len = {Length}", ConnectionToken,
|
||||
receiveBytes.Length);
|
||||
Log.Verbose(
|
||||
$"Tcp client {ConnectionToken} receive: {String.Concat(receiveBytes.Select(p => " " + p.ToString("X2")))}");
|
||||
var isMessageConfirmed = Controller.ConfirmMessage(receiveBytes);
|
||||
if (isMessageConfirmed == false)
|
||||
{
|
||||
//主动传输事件
|
||||
}
|
||||
}
|
||||
|
||||
RefreshReceiveCount();
|
||||
}
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
//ignore
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Log.Error(err, "Tcp client {ConnectionToken} receive exception", ConnectionToken);
|
||||
CloseClientSocket();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,10 +350,11 @@ namespace Modbus.Net
|
||||
{
|
||||
try
|
||||
{
|
||||
var stream = _socketClient.GetStream();
|
||||
stream.Dispose();
|
||||
_socketClient.Client.Shutdown(SocketShutdown.Both);
|
||||
_socketClient.Client.Dispose();
|
||||
Controller.SendStop();
|
||||
Controller.Clear();
|
||||
ReceiveMsgThreadStop();
|
||||
_socketClient?.GetStream().Dispose();
|
||||
_socketClient?.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -19,10 +19,10 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
public ModbusMachine(ModbusType connectionType, string connectionString,
|
||||
public ModbusMachine(TKey id, ModbusType connectionType, string connectionString,
|
||||
IEnumerable<AddressUnit<TUnitKey>> getAddresses, bool keepConnect, byte slaveAddress, byte masterAddress,
|
||||
Endian endian = Endian.BigEndianLsb)
|
||||
: base(getAddresses, keepConnect, slaveAddress, masterAddress)
|
||||
: base(id, getAddresses, keepConnect, slaveAddress, masterAddress)
|
||||
{
|
||||
BaseUtility = new ModbusUtility(connectionType, connectionString, slaveAddress, masterAddress, endian);
|
||||
AddressFormater = new AddressFormaterModbus();
|
||||
@@ -39,10 +39,10 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
public ModbusMachine(ModbusType connectionType, string connectionString,
|
||||
public ModbusMachine(TKey id, ModbusType connectionType, string connectionString,
|
||||
IEnumerable<AddressUnit<TUnitKey>> getAddresses, byte slaveAddress, byte masterAddress,
|
||||
Endian endian = Endian.BigEndianLsb)
|
||||
: this(connectionType, connectionString, getAddresses, false, slaveAddress, masterAddress, endian)
|
||||
: this(id, connectionType, connectionString, getAddresses, false, slaveAddress, masterAddress, endian)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -62,10 +62,10 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
public ModbusMachine(ModbusType connectionType, string connectionString,
|
||||
public ModbusMachine(string id, ModbusType connectionType, string connectionString,
|
||||
IEnumerable<AddressUnit> getAddresses, bool keepConnect, byte slaveAddress, byte masterAddress,
|
||||
Endian endian = Endian.BigEndianLsb)
|
||||
: base(getAddresses, keepConnect, slaveAddress, masterAddress)
|
||||
: base(id, getAddresses, keepConnect, slaveAddress, masterAddress)
|
||||
{
|
||||
BaseUtility = new ModbusUtility(connectionType, connectionString, slaveAddress, masterAddress, endian);
|
||||
AddressFormater = new AddressFormaterModbus();
|
||||
@@ -82,10 +82,10 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
public ModbusMachine(ModbusType connectionType, string connectionString,
|
||||
public ModbusMachine(string id, ModbusType connectionType, string connectionString,
|
||||
IEnumerable<AddressUnit> getAddresses, byte slaveAddress, byte masterAddress,
|
||||
Endian endian = Endian.BigEndianLsb)
|
||||
: this(connectionType, connectionString, getAddresses, false, slaveAddress, masterAddress, endian)
|
||||
: this(id, connectionType, connectionString, getAddresses, false, slaveAddress, masterAddress, endian)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,15 +104,6 @@ namespace Modbus.Net.Modbus
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接
|
||||
/// </summary>
|
||||
/// <returns>是否连接成功</returns>
|
||||
public override bool Connect()
|
||||
{
|
||||
return ProtocalLinker.Connect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接
|
||||
/// </summary>
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Modbus.Net.Modbus
|
||||
/// </summary>
|
||||
/// <param name="ip">IP地址</param>
|
||||
public ModbusTcpProtocalLinker(string ip)
|
||||
: base(ip, int.Parse(ConfigurationManager.AppSettings["ModbusPort"] ?? "502"))
|
||||
: this(ip, int.Parse(ConfigurationManager.AppSettings["ModbusPort"] ?? "502"))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="port">端口</param>
|
||||
public ModbusTcpProtocalLinker(string ip, int port) : base(ip, port)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new FIFOController(500));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -142,13 +142,13 @@ namespace Modbus.Net.Modbus
|
||||
switch (_modbusType)
|
||||
{
|
||||
//Rtu协议
|
||||
case ModbusType.Rtu:
|
||||
/*case ModbusType.Rtu:
|
||||
{
|
||||
Wrapper = ConnectionString == null
|
||||
? new ModbusRtuProtocal(SlaveAddress, MasterAddress, Endian)
|
||||
: new ModbusRtuProtocal(ConnectionString, SlaveAddress, MasterAddress, Endian);
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
//Tcp协议
|
||||
case ModbusType.Tcp:
|
||||
{
|
||||
@@ -161,6 +161,7 @@ namespace Modbus.Net.Modbus
|
||||
break;
|
||||
}
|
||||
//Ascii协议
|
||||
/*
|
||||
case ModbusType.Ascii:
|
||||
{
|
||||
Wrapper = ConnectionString == null
|
||||
@@ -190,6 +191,7 @@ namespace Modbus.Net.Modbus
|
||||
MasterAddress, Endian));
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ namespace Modbus.Net.Siemens
|
||||
/// <param name="keepConnect">是否保持连接</param>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
public SiemensMachine(SiemensType connectionType, string connectionString, SiemensMachineModel model,
|
||||
public SiemensMachine(TKey id, SiemensType connectionType, string connectionString, SiemensMachineModel model,
|
||||
IEnumerable<AddressUnit<TUnitKey>> getAddresses, bool keepConnect, byte slaveAddress, byte masterAddress)
|
||||
: base(getAddresses, keepConnect, slaveAddress, masterAddress)
|
||||
: base(id, getAddresses, keepConnect, slaveAddress, masterAddress)
|
||||
{
|
||||
BaseUtility = new SiemensUtility(connectionType, connectionString, model, slaveAddress, masterAddress);
|
||||
AddressFormater = new AddressFormaterSiemens();
|
||||
@@ -38,9 +38,9 @@ namespace Modbus.Net.Siemens
|
||||
/// <param name="getAddresses">读写的地址</param>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
public SiemensMachine(SiemensType connectionType, string connectionString, SiemensMachineModel model,
|
||||
public SiemensMachine(TKey id, SiemensType connectionType, string connectionString, SiemensMachineModel model,
|
||||
IEnumerable<AddressUnit<TUnitKey>> getAddresses, byte slaveAddress, byte masterAddress)
|
||||
: this(connectionType, connectionString, model, getAddresses, false, slaveAddress, masterAddress)
|
||||
: this(id, connectionType, connectionString, model, getAddresses, false, slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -60,9 +60,9 @@ namespace Modbus.Net.Siemens
|
||||
/// <param name="keepConnect">是否保持连接</param>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
public SiemensMachine(SiemensType connectionType, string connectionString, SiemensMachineModel model,
|
||||
public SiemensMachine(string id, SiemensType connectionType, string connectionString, SiemensMachineModel model,
|
||||
IEnumerable<AddressUnit> getAddresses, bool keepConnect, byte slaveAddress, byte masterAddress)
|
||||
: base(getAddresses, keepConnect, slaveAddress, masterAddress)
|
||||
: base(id, getAddresses, keepConnect, slaveAddress, masterAddress)
|
||||
{
|
||||
BaseUtility = new SiemensUtility(connectionType, connectionString, model, slaveAddress, masterAddress);
|
||||
AddressFormater = new AddressFormaterSiemens();
|
||||
@@ -79,9 +79,9 @@ namespace Modbus.Net.Siemens
|
||||
/// <param name="getAddresses">读写的地址</param>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
public SiemensMachine(SiemensType connectionType, string connectionString, SiemensMachineModel model,
|
||||
public SiemensMachine(string id, SiemensType connectionType, string connectionString, SiemensMachineModel model,
|
||||
IEnumerable<AddressUnit> getAddresses, byte slaveAddress, byte masterAddress)
|
||||
: this(connectionType, connectionString, model, getAddresses, false, slaveAddress, masterAddress)
|
||||
: this(id, connectionType, connectionString, model, getAddresses, false, slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,15 +136,6 @@ namespace Modbus.Net.Siemens
|
||||
return await base.SendReceiveAsync(unit, content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
/// <returns>设备是否连接成功</returns>
|
||||
public override bool Connect()
|
||||
{
|
||||
return AsyncHelper.RunSync(ConnectAsync);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace Modbus.Net.Siemens
|
||||
public SiemensTcpProtocalLinker(string ip, int port)
|
||||
: base(ip, port)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new FIFOController(500));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -184,6 +184,7 @@ namespace Modbus.Net.Siemens
|
||||
switch (_siemensType)
|
||||
{
|
||||
//PPI
|
||||
/*
|
||||
case SiemensType.Ppi:
|
||||
{
|
||||
Wrapper = ConnectionString == null
|
||||
@@ -196,6 +197,7 @@ namespace Modbus.Net.Siemens
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
*/
|
||||
//Ethenet
|
||||
case SiemensType.Tcp:
|
||||
{
|
||||
|
||||
35
README.md
35
README.md
@@ -8,7 +8,7 @@ Overview
|
||||
-------------------
|
||||
Modbus.Net is an open hardware communication platform written by C# 7.0.
|
||||
|
||||
You can only focusing on the protocal itself, and the platform can automaticaly create a full asynchronized or synchronized communication library.
|
||||
You can only focusing on the Protocol itself, and the platform can automaticaly create a full asynchronized or synchronized communication library.
|
||||
|
||||
Why called Modbus.Net
|
||||
-------------------
|
||||
@@ -18,7 +18,7 @@ The real Modbus Implementation has been moved to Modbus.Net.Modbus. If you want
|
||||
|
||||
There are also "Modbus.Net.Siemens" that can communicate to Siemens S7-200, S7-200 Smart, S7-300, S7-400, S7-1200, S7-1500 using PPI or TCP/IP.
|
||||
|
||||
"Modbus.Net.OPC" Implements OPC DA and OPC UA protocal.
|
||||
"Modbus.Net.OPC" Implements OPC DA and OPC UA Protocol.
|
||||
|
||||
Platform Supported
|
||||
-------------------
|
||||
@@ -61,7 +61,7 @@ RoadMap
|
||||
|
||||
### Version 1.3.1
|
||||
* InputStruct -> IInputStruct, OutputStruct -> IOutputStruct (Complete)
|
||||
* Generic Method For ProtocalUnit (Complete)
|
||||
* Generic Method For ProtocolUnit (Complete)
|
||||
|
||||
### Version 1.3.2
|
||||
* Add Interface IMachineMethod and IUtilityMethod. Utiltiy and Machine can extend function using interface (Complete)
|
||||
@@ -86,7 +86,7 @@ RoadMap
|
||||
|
||||
### Version 1.3.8
|
||||
* Change Resx to appsettings.json, now you can set default params there (Complete - CORE ONLY)
|
||||
* Change ISpecialProtocalUnit to SpecialProtocalUnitAttribute (Complete)
|
||||
* Change ISpecialProtocolUnit to SpecialProtocolUnitAttribute (Complete)
|
||||
|
||||
### Version 1.3.9
|
||||
* Modbus Single Write for Coil and Reg (05 and 06) (Complete)
|
||||
@@ -100,32 +100,33 @@ RoadMap
|
||||
* Update to .Net Standard 2.0 (Complete)
|
||||
|
||||
### Version 1.4.0
|
||||
* New Protocal Pipeline System (Complete)
|
||||
* New Protocol Pipeline System (Complete)
|
||||
|
||||
### Version 1.4.1
|
||||
* BaseController (In Road)
|
||||
* New ComConnector (In Road)
|
||||
* New TcpConnector (In Road)
|
||||
* New UdpConnector (In Road)
|
||||
* Serial Port Connection with Multiple Master Station (In Road)
|
||||
* BaseController and IController (Programming)
|
||||
* New ComConnector (Programming)
|
||||
* New TcpConnector (Programming)
|
||||
* New UdpConnector (Programming)
|
||||
* Serial Port Connection with Multiple Master Station (Delay)
|
||||
|
||||
### Version 1.4.2
|
||||
* PPI Remake (In Road)
|
||||
* Siemens MPI Support (In Road)
|
||||
* Siemens MultiStation PPI Support (In Road)
|
||||
* PPI Remake (Delay)
|
||||
* Siemens MPI Support (Delay)
|
||||
* Siemens MultiStation PPI Support (Delay)
|
||||
|
||||
### Version 1.5.X
|
||||
* Unite TransServer.Net into Modbus.Net (In Road)
|
||||
* Passive Connector and Controller (In Road)
|
||||
* Architechture rebuild (In Road)
|
||||
|
||||
### Version 1.6.X
|
||||
* English comment (In Road)
|
||||
* ValueHelper remake to interface, users can add their own value translate function (In Road)
|
||||
* New Zoom (In Road)
|
||||
|
||||
### Version 1.6.X
|
||||
* English comment (In Road)
|
||||
|
||||
### Version 2.0.0
|
||||
* Rename to Transport.Net (In Road)
|
||||
* Puzzle System (In Road)
|
||||
* Puzzle Builder (In Road)
|
||||
* Machine Builder (In Road)
|
||||
* Protocol Builer (In Road)
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace AnyType.Controllers
|
||||
//初始化任务管理器
|
||||
task = new TaskManager(10, true);
|
||||
//向任务管理器中添加设备
|
||||
task.AddMachine(new ModbusMachine(ModbusType.Tcp, "192.168.3.10", addressUnits,
|
||||
task.AddMachine(new ModbusMachine("1", ModbusType.Tcp, "192.168.3.10", addressUnits,
|
||||
true, 2, 0));
|
||||
//启动任务
|
||||
task.InvokeTimerAll(new TaskItemGetData(returnValues =>
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace TaskManager.Controllers
|
||||
//初始化任务管理器
|
||||
task = new Modbus.Net.TaskManager(10, true);
|
||||
//向任务管理器中添加设备
|
||||
task.AddMachine(new ModbusMachine(ModbusType.Tcp, "192.168.3.10", addressUnits,
|
||||
task.AddMachine(new ModbusMachine("1", ModbusType.Tcp, "192.168.3.10", addressUnits,
|
||||
true, 2, 0));
|
||||
//启动任务
|
||||
task.InvokeTimerAll(new TaskItemGetData(returnValues =>
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace TripleAdd.Controllers
|
||||
{
|
||||
if (machine == null)
|
||||
{
|
||||
machine = new ModbusMachine(ModbusType.Tcp, "192.168.3.10", new List<AddressUnit>()
|
||||
machine = new ModbusMachine("1", ModbusType.Tcp, "192.168.3.10", new List<AddressUnit>()
|
||||
{
|
||||
new AddressUnit() {Id = "1", Area = "4X", Address = 1, CommunicationTag = "Add1", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
|
||||
new AddressUnit() {Id = "2", Area = "4X", Address = 2, CommunicationTag = "Add2", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
|
||||
|
||||
@@ -129,20 +129,18 @@ namespace Modbus.Net.Tests
|
||||
},
|
||||
};
|
||||
|
||||
_baseMachine = new ModbusMachine<int, int>(ModbusType.Tcp, "192.168.1.1", _addressUnits, true, 2, 0)
|
||||
_baseMachine = new ModbusMachine<int, int>(1, ModbusType.Tcp, "192.168.1.1", _addressUnits, true, 2, 0)
|
||||
{
|
||||
Id = 1,
|
||||
ProjectName = "Project 1",
|
||||
MachineName = "Test 1"
|
||||
};
|
||||
_baseMachine2 = new SiemensMachine<int, int>(SiemensType.Tcp, "192.168.3.10", SiemensMachineModel.S7_1200, _addressUnits, true, 2, 0)
|
||||
_baseMachine2 = new SiemensMachine<int, int>(2, SiemensType.Tcp, "192.168.3.10", SiemensMachineModel.S7_1200, _addressUnits, true, 2, 0)
|
||||
{
|
||||
Id = 2,
|
||||
ProjectName = "Project 1",
|
||||
MachineName = "Test 2"
|
||||
};
|
||||
|
||||
_baseMachine2.Connect();
|
||||
_baseMachine2.ConnectAsync().Wait();
|
||||
|
||||
_taskManager = new TaskManager<int>(10, true);
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Modbus.Net.Tests
|
||||
[TestMethod]
|
||||
public void GetUtility()
|
||||
{
|
||||
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(ModbusType.Tcp, "192.168.3.12", null, true, 2, 0);
|
||||
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(1, ModbusType.Tcp, "192.168.3.12", null, true, 2, 0);
|
||||
var utility = baseMachine.GetUtility<IUtilityMethodTime>();
|
||||
var methods = utility.GetType().GetRuntimeMethods();
|
||||
Assert.AreEqual(methods.FirstOrDefault(method => method.Name == "GetTimeAsync") != null, true);
|
||||
@@ -25,7 +25,7 @@ namespace Modbus.Net.Tests
|
||||
[TestMethod]
|
||||
public async Task InvokeUtility()
|
||||
{
|
||||
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(ModbusType.Tcp, "192.168.3.12", null, true, 2, 0);
|
||||
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(1, ModbusType.Tcp, "192.168.3.12", null, true, 2, 0);
|
||||
var success = await baseMachine.BaseUtility.GetUtilityMethods<IUtilityMethodTime>().SetTimeAsync(DateTime.Now);
|
||||
Assert.AreEqual(success, true);
|
||||
var time = await baseMachine.BaseUtility.GetUtilityMethods<IUtilityMethodTime>().GetTimeAsync();
|
||||
@@ -36,7 +36,7 @@ namespace Modbus.Net.Tests
|
||||
[TestMethod]
|
||||
public async Task InvokeMachine()
|
||||
{
|
||||
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(ModbusType.Tcp, "192.168.3.10", new List<AddressUnit<int>>
|
||||
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(1, ModbusType.Tcp, "192.168.3.10", new List<AddressUnit<int>>
|
||||
{
|
||||
new AddressUnit<int>
|
||||
{
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Modbus.Net.Tests
|
||||
[TestInitialize]
|
||||
public void Init()
|
||||
{
|
||||
_modbusRtuMachine1 = new ModbusMachine(ModbusType.Rtu, "COM1", null, true, 1, 0);
|
||||
_modbusRtuMachine2 = new ModbusMachine(ModbusType.Rtu, "COM1", null, true, 2, 0);
|
||||
_modbusRtuMachine1 = new ModbusMachine("1", ModbusType.Rtu, "COM1", null, true, 1, 0);
|
||||
_modbusRtuMachine2 = new ModbusMachine("2", ModbusType.Rtu, "COM1", null, true, 2, 0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
@@ -18,11 +18,11 @@ namespace Modbus.Net.Tests
|
||||
[TestInitialize]
|
||||
public void Init()
|
||||
{
|
||||
_modbusTcpMachine = new ModbusMachine(ModbusType.Tcp, "192.168.3.10", null, true, 2, 0);
|
||||
_modbusTcpMachine = new ModbusMachine("1", ModbusType.Tcp, "192.168.3.10", null, true, 2, 0);
|
||||
|
||||
_modbusRtuMachine = new ModbusMachine(ModbusType.Rtu, "COM3", null, true, 2, 0);
|
||||
//_modbusRtuMachine = new ModbusMachine("2", ModbusType.Rtu, "COM3", null, true, 2, 0);
|
||||
|
||||
_modbusAsciiMachine = new ModbusMachine(ModbusType.Ascii, "COM5", null, true, 2, 0);
|
||||
//_modbusAsciiMachine = new ModbusMachine("3", ModbusType.Ascii, "COM5", null, true, 2, 0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -51,17 +51,17 @@ namespace Modbus.Net.Tests
|
||||
};
|
||||
|
||||
_modbusTcpMachine.GetAddresses = addresses;
|
||||
_modbusAsciiMachine.GetAddresses = addresses;
|
||||
_modbusRtuMachine.GetAddresses = addresses;
|
||||
//_modbusAsciiMachine.GetAddresses = addresses;
|
||||
//_modbusRtuMachine.GetAddresses = addresses;
|
||||
await _modbusTcpMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
||||
await _modbusAsciiMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
||||
await _modbusRtuMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
||||
//await _modbusAsciiMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
||||
//await _modbusRtuMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
||||
var ans = await _modbusTcpMachine.GetDatasAsync(MachineGetDataType.Address);
|
||||
var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineGetDataType.Address);
|
||||
var ans3 = await _modbusAsciiMachine.GetDatasAsync(MachineGetDataType.Address);
|
||||
//var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineGetDataType.Address);
|
||||
//var ans3 = await _modbusAsciiMachine.GetDatasAsync(MachineGetDataType.Address);
|
||||
Assert.AreEqual(ans["0X 1.0"].PlcValue, dic1["0X 1.0"]);
|
||||
Assert.AreEqual(ans2["0X 1.0"].PlcValue, dic1["0X 1.0"]);
|
||||
Assert.AreEqual(ans3["0X 1.0"].PlcValue, dic1["0X 1.0"]);
|
||||
//Assert.AreEqual(ans2["0X 1.0"].PlcValue, dic1["0X 1.0"]);
|
||||
//Assert.AreEqual(ans3["0X 1.0"].PlcValue, dic1["0X 1.0"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -316,8 +316,8 @@ namespace Modbus.Net.Tests
|
||||
[TestCleanup]
|
||||
public void MachineClean()
|
||||
{
|
||||
_modbusAsciiMachine.Disconnect();
|
||||
_modbusRtuMachine.Disconnect();
|
||||
//_modbusAsciiMachine.Disconnect();
|
||||
//_modbusRtuMachine.Disconnect();
|
||||
_modbusTcpMachine.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Modbus.Net.Tests
|
||||
[TestInitialize]
|
||||
public void Init()
|
||||
{
|
||||
_opcMachine = new FBoxOpcDaMachine("1","德联科技测试", null, true);
|
||||
_opcMachine = new FBoxOpcDaMachine("1", "1", "德联科技测试", null, true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Modbus.Net.Tests
|
||||
[TestInitialize]
|
||||
public void Init()
|
||||
{
|
||||
_siemensTcpMachine = new SiemensMachine(SiemensType.Tcp, "192.168.3.10", SiemensMachineModel.S7_1200, null, true, 2, 0);
|
||||
_siemensTcpMachine = new SiemensMachine("1", SiemensType.Tcp, "192.168.3.10", SiemensMachineModel.S7_1200, null, true, 2, 0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
@@ -80,10 +80,7 @@ namespace Modbus.Net.Tests
|
||||
}
|
||||
};
|
||||
|
||||
BaseMachine machine = new ModbusMachine(ModbusType.Tcp, "192.168.3.10", addresses, true, 2, 0)
|
||||
{
|
||||
Id = "1"
|
||||
};
|
||||
BaseMachine machine = new ModbusMachine("1", ModbusType.Tcp, "192.168.3.10", addresses, true, 2, 0);
|
||||
|
||||
_taskManager.AddMachine(machine);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user