2014-08-27 update 2 Rename Class
This commit is contained in:
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ModBus.Net
|
namespace ModBus.Net
|
||||||
{
|
{
|
||||||
public abstract class Connector
|
public abstract class BaseConnector
|
||||||
{
|
{
|
||||||
public abstract bool Connect();
|
public abstract bool Connect();
|
||||||
public abstract bool Disconnect();
|
public abstract bool Disconnect();
|
||||||
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ModBus.Net
|
namespace ModBus.Net
|
||||||
{
|
{
|
||||||
public class ComConnector : Connector, IDisposable
|
public class ComConnector : BaseConnector, IDisposable
|
||||||
{
|
{
|
||||||
private SerialPort serialPort1 = new SerialPort();
|
private SerialPort serialPort1 = new SerialPort();
|
||||||
|
|
||||||
|
|||||||
@@ -44,17 +44,17 @@
|
|||||||
<Compile Include="AddressTranslator.cs" />
|
<Compile Include="AddressTranslator.cs" />
|
||||||
<Compile Include="BaseProtocal.cs" />
|
<Compile Include="BaseProtocal.cs" />
|
||||||
<Compile Include="ComConnector.cs" />
|
<Compile Include="ComConnector.cs" />
|
||||||
<Compile Include="ComProtocalLinker.cs" />
|
<Compile Include="RtuProtocalLinker.cs" />
|
||||||
<Compile Include="ConfigurationManager.Designer.cs">
|
<Compile Include="ConfigurationManager.Designer.cs">
|
||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
<DependentUpon>ConfigurationManager.resx</DependentUpon>
|
<DependentUpon>ConfigurationManager.resx</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Connector.cs" />
|
<Compile Include="BaseConnector.cs" />
|
||||||
<Compile Include="CRC16.cs" />
|
<Compile Include="CRC16.cs" />
|
||||||
<Compile Include="IProtocalFormatting.cs" />
|
<Compile Include="IProtocalFormatting.cs" />
|
||||||
<Compile Include="ModbusComProtocal.cs" />
|
<Compile Include="ModbusRtuProtocal.cs" />
|
||||||
<Compile Include="ModbusComProtocalLinker.cs" />
|
<Compile Include="ModbusRtuProtocalLinker.cs" />
|
||||||
<Compile Include="ModbusTcpProtocalLinker.cs" />
|
<Compile Include="ModbusTcpProtocalLinker.cs" />
|
||||||
<Compile Include="ProtocalLinker.cs" />
|
<Compile Include="ProtocalLinker.cs" />
|
||||||
<Compile Include="ProtocalLinkerBytesExtend.cs" />
|
<Compile Include="ProtocalLinkerBytesExtend.cs" />
|
||||||
@@ -62,7 +62,7 @@
|
|||||||
<Compile Include="ModbusProtocal.cs" />
|
<Compile Include="ModbusProtocal.cs" />
|
||||||
<Compile Include="ModbusTcpProtocal.cs" />
|
<Compile Include="ModbusTcpProtocal.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="TcpSocket.cs">
|
<Compile Include="TcpConnector.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="TcpProtocalLinker.cs" />
|
<Compile Include="TcpProtocalLinker.cs" />
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ModBus.Net
|
|
||||||
{
|
|
||||||
public class ModbusComProtocal : ModbusProtocal
|
|
||||||
{
|
|
||||||
public ModbusComProtocal()
|
|
||||||
{
|
|
||||||
_protocalLinker = new ModbusComProtocalLinker();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ModbusComProtocal(string com)
|
|
||||||
{
|
|
||||||
_protocalLinker = new ModbusComProtocalLinker(com);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
21
NA200H/ModBus.Net/ModbusRtuProtocal.cs
Normal file
21
NA200H/ModBus.Net/ModbusRtuProtocal.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ModBus.Net
|
||||||
|
{
|
||||||
|
public class ModbusRtuProtocal : ModbusProtocal
|
||||||
|
{
|
||||||
|
public ModbusRtuProtocal()
|
||||||
|
{
|
||||||
|
_protocalLinker = new ModbusRtuProtocalLinker();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModbusRtuProtocal(string com)
|
||||||
|
{
|
||||||
|
_protocalLinker = new ModbusRtuProtocalLinker(com);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ModBus.Net
|
namespace ModBus.Net
|
||||||
{
|
{
|
||||||
class ModbusComProtocalLinker : ComProtocalLinker
|
class ModbusRtuProtocalLinker : RtuProtocalLinker
|
||||||
{
|
{
|
||||||
public override bool CheckRight(byte[] content)
|
public override bool CheckRight(byte[] content)
|
||||||
{
|
{
|
||||||
@@ -21,12 +21,12 @@ namespace ModBus.Net
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ModbusComProtocalLinker() : base()
|
public ModbusRtuProtocalLinker() : base()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ModbusComProtocalLinker(string com) : base(com)
|
public ModbusRtuProtocalLinker(string com) : base(com)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@ namespace ModBus.Net
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class ProtocalLinker
|
public abstract class ProtocalLinker
|
||||||
{
|
{
|
||||||
protected Connector _baseConnector;
|
protected BaseConnector _baseConnector;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 发送并接收数据
|
/// 发送并接收数据
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ModBus.Net
|
namespace ModBus.Net
|
||||||
{
|
{
|
||||||
public abstract class ComProtocalLinker : ProtocalLinker
|
public abstract class RtuProtocalLinker : ProtocalLinker
|
||||||
{
|
{
|
||||||
protected ComProtocalLinker()
|
protected RtuProtocalLinker()
|
||||||
{
|
{
|
||||||
//初始化连对象
|
//初始化连对象
|
||||||
_baseConnector = new ComConnector(ConfigurationManager.COM);
|
_baseConnector = new ComConnector(ConfigurationManager.COM);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ComProtocalLinker(string com)
|
protected RtuProtocalLinker(string com)
|
||||||
{
|
{
|
||||||
_baseConnector = new ComConnector(com);
|
_baseConnector = new ComConnector(com);
|
||||||
}
|
}
|
||||||
@@ -13,12 +13,12 @@ namespace ModBus.Net
|
|||||||
protected TcpProtocalLinker()
|
protected TcpProtocalLinker()
|
||||||
{
|
{
|
||||||
//初始化连对象
|
//初始化连对象
|
||||||
_baseConnector = new TcpSocket(ConfigurationManager.IP, int.Parse(ConfigurationManager.Port), false);
|
_baseConnector = new TcpConnector(ConfigurationManager.IP, int.Parse(ConfigurationManager.Port), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TcpProtocalLinker(string ip)
|
protected TcpProtocalLinker(string ip)
|
||||||
{
|
{
|
||||||
_baseConnector = new TcpSocket(ip, int.Parse(ConfigurationManager.Port), false);
|
_baseConnector = new TcpConnector(ip, int.Parse(ConfigurationManager.Port), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,7 @@ namespace ModBus.Net
|
|||||||
/// Socket收发类
|
/// Socket收发类
|
||||||
/// 作者:本类来源于CSDN,并由罗圣(Chris L.)根据实际需要修改
|
/// 作者:本类来源于CSDN,并由罗圣(Chris L.)根据实际需要修改
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TcpSocket : Connector, IDisposable
|
public class TcpConnector : BaseConnector, IDisposable
|
||||||
{
|
{
|
||||||
public delegate void ErrorShutdownEventHandler(object sender, EventArgs e);
|
public delegate void ErrorShutdownEventHandler(object sender, EventArgs e);
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ namespace ModBus.Net
|
|||||||
public int m_sendCount = 0;
|
public int m_sendCount = 0;
|
||||||
private TcpClient m_socketClient;
|
private TcpClient m_socketClient;
|
||||||
|
|
||||||
public TcpSocket(string ipaddress, int port, bool isAsync)
|
public TcpConnector(string ipaddress, int port, bool isAsync)
|
||||||
{
|
{
|
||||||
host = ipaddress;
|
host = ipaddress;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
@@ -88,7 +88,7 @@ namespace NA200H.UI.ConsoleApp
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//先初始化一个协议转换器,这里构造Modbus/Rtu协议。
|
//先初始化一个协议转换器,这里构造Modbus/Rtu协议。
|
||||||
BaseProtocal wrapper = new ModbusComProtocal();
|
BaseProtocal wrapper = new ModbusRtuProtocal();
|
||||||
|
|
||||||
//调用方法一:手动构造
|
//调用方法一:手动构造
|
||||||
//第一步:先生成一个输入信息的object数组
|
//第一步:先生成一个输入信息的object数组
|
||||||
|
|||||||
Reference in New Issue
Block a user