Merge
This commit is contained in:
@@ -12,9 +12,8 @@ namespace Modbus.Net.Modbus
|
||||
/// </summary>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
public ModbusAsciiInTcpProtocol(byte slaveAddress, byte masterAddress, Endian endian)
|
||||
: this(ConfigurationManager.AppSettings["IP"], slaveAddress, masterAddress, endian)
|
||||
public ModbusAsciiInTcpProtocal(byte slaveAddress, byte masterAddress)
|
||||
: this(ConfigurationManager.AppSettings["IP"], slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -24,9 +23,8 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="ip">ip地址</param>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
public ModbusAsciiInTcpProtocol(string ip, byte slaveAddress, byte masterAddress, Endian endian)
|
||||
: base(slaveAddress, masterAddress, endian)
|
||||
public ModbusAsciiInTcpProtocal(string ip, byte slaveAddress, byte masterAddress)
|
||||
: base(slaveAddress, masterAddress)
|
||||
{
|
||||
ProtocolLinker = new ModbusAsciiInTcpProtocolLinker(ip, slaveAddress);
|
||||
}
|
||||
@@ -38,9 +36,8 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="port">端口</param>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
public ModbusAsciiInTcpProtocol(string ip, int port, byte slaveAddress, byte masterAddress, Endian endian)
|
||||
: base(slaveAddress, masterAddress, endian)
|
||||
public ModbusAsciiInTcpProtocal(string ip, int port, byte slaveAddress, byte masterAddress)
|
||||
: base(slaveAddress, masterAddress)
|
||||
{
|
||||
ProtocolLinker = new ModbusTcpProtocolLinker(ip, port);
|
||||
}
|
||||
|
||||
@@ -12,9 +12,8 @@ namespace Modbus.Net.Modbus
|
||||
/// </summary>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
public ModbusAsciiProtocol(byte slaveAddress, byte masterAddress, Endian endian)
|
||||
: this(ConfigurationManager.AppSettings["COM"], slaveAddress, masterAddress, endian)
|
||||
public ModbusAsciiProtocal(byte slaveAddress, byte masterAddress)
|
||||
: this(ConfigurationManager.AppSettings["COM"], slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -24,9 +23,8 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="com">串口地址</param>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
public ModbusAsciiProtocol(string com, byte slaveAddress, byte masterAddress, Endian endian)
|
||||
: base(slaveAddress, masterAddress, endian)
|
||||
public ModbusAsciiProtocal(string com, byte slaveAddress, byte masterAddress)
|
||||
: base(slaveAddress, masterAddress)
|
||||
{
|
||||
ProtocolLinker = new ModbusAsciiProtocolLinker(com, slaveAddress);
|
||||
}
|
||||
|
||||
@@ -98,9 +98,8 @@ namespace Modbus.Net.Modbus
|
||||
/// </summary>
|
||||
/// <param name="slaveAddress">从站地址</param>
|
||||
/// <param name="masterAddress">主站地址</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
protected ModbusProtocol(byte slaveAddress, byte masterAddress, Endian endian)
|
||||
: base(slaveAddress, masterAddress, endian)
|
||||
protected ModbusProtocal(byte slaveAddress, byte masterAddress)
|
||||
: base(slaveAddress, masterAddress, Endian.BigEndianLsb)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,8 @@ namespace Modbus.Net.Modbus
|
||||
/// </summary>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
public ModbusRtuInTcpProtocol(byte slaveAddress, byte masterAddress, Endian endian)
|
||||
: this(ConfigurationManager.AppSettings["IP"], slaveAddress, masterAddress, endian)
|
||||
public ModbusRtuInTcpProtocal(byte slaveAddress, byte masterAddress)
|
||||
: this(ConfigurationManager.AppSettings["IP"], slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -25,9 +24,8 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="ip">ip地址</param>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
public ModbusRtuInTcpProtocol(string ip, byte slaveAddress, byte masterAddress, Endian endian)
|
||||
: base(slaveAddress, masterAddress, endian)
|
||||
public ModbusRtuInTcpProtocal(string ip, byte slaveAddress, byte masterAddress)
|
||||
: base(slaveAddress, masterAddress)
|
||||
{
|
||||
ProtocolLinker = new ModbusTcpProtocolLinker(ip);
|
||||
}
|
||||
@@ -39,9 +37,8 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="port">端口号</param>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
public ModbusRtuInTcpProtocol(string ip, int port, byte slaveAddress, byte masterAddress, Endian endian)
|
||||
: base(slaveAddress, masterAddress, endian)
|
||||
public ModbusRtuInTcpProtocal(string ip, int port, byte slaveAddress, byte masterAddress)
|
||||
: base(slaveAddress, masterAddress)
|
||||
{
|
||||
ProtocolLinker = new ModbusRtuInTcpProtocolLinker(ip, port);
|
||||
}
|
||||
|
||||
@@ -12,9 +12,8 @@ namespace Modbus.Net.Modbus
|
||||
/// </summary>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
public ModbusRtuProtocol(byte slaveAddress, byte masterAddress, Endian endian)
|
||||
: this(ConfigurationManager.AppSettings["COM"], slaveAddress, masterAddress, endian)
|
||||
public ModbusRtuProtocal(byte slaveAddress, byte masterAddress)
|
||||
: this(ConfigurationManager.AppSettings["COM"], slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -24,9 +23,8 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="com">串口</param>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
public ModbusRtuProtocol(string com, byte slaveAddress, byte masterAddress, Endian endian)
|
||||
: base(slaveAddress, masterAddress, endian)
|
||||
public ModbusRtuProtocal(string com, byte slaveAddress, byte masterAddress)
|
||||
: base(slaveAddress, masterAddress)
|
||||
{
|
||||
ProtocolLinker = new ModbusRtuProtocolLinker(com, slaveAddress);
|
||||
}
|
||||
|
||||
@@ -12,9 +12,8 @@ namespace Modbus.Net.Modbus
|
||||
/// </summary>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
public ModbusTcpProtocol(byte slaveAddress, byte masterAddress, Endian endian)
|
||||
: this(ConfigurationManager.AppSettings["IP"], slaveAddress, masterAddress, endian)
|
||||
public ModbusTcpProtocal(byte slaveAddress, byte masterAddress)
|
||||
: this(ConfigurationManager.AppSettings["IP"], slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -24,9 +23,8 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="ip">ip地址</param>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
public ModbusTcpProtocol(string ip, byte slaveAddress, byte masterAddress, Endian endian)
|
||||
: base(slaveAddress, masterAddress, endian)
|
||||
public ModbusTcpProtocal(string ip, byte slaveAddress, byte masterAddress)
|
||||
: base(slaveAddress, masterAddress)
|
||||
{
|
||||
ProtocolLinker = new ModbusTcpProtocolLinker(ip);
|
||||
}
|
||||
@@ -38,9 +36,8 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="port">端口</param>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
/// <param name="endian">端格式</param>
|
||||
public ModbusTcpProtocol(string ip, int port, byte slaveAddress, byte masterAddress, Endian endian)
|
||||
: base(slaveAddress, masterAddress, endian)
|
||||
public ModbusTcpProtocal(string ip, int port, byte slaveAddress, byte masterAddress)
|
||||
: base(slaveAddress, masterAddress)
|
||||
{
|
||||
ProtocolLinker = new ModbusTcpProtocolLinker(ip, port);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Modbus.Net.Modbus
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写单个单元的方法接口
|
||||
/// 写单个数据方法接口
|
||||
/// </summary>
|
||||
public interface IUtilityMethodWriteSingle : IUtilityMethod
|
||||
{
|
||||
@@ -148,18 +148,18 @@ namespace Modbus.Net.Modbus
|
||||
case ModbusType.Rtu:
|
||||
{
|
||||
Wrapper = ConnectionString == null
|
||||
? new ModbusRtuProtocol(SlaveAddress, MasterAddress, Endian)
|
||||
: new ModbusRtuProtocol(ConnectionString, SlaveAddress, MasterAddress, Endian);
|
||||
? new ModbusRtuProtocal(SlaveAddress, MasterAddress, Endian)
|
||||
: new ModbusRtuProtocal(ConnectionString, SlaveAddress, MasterAddress, Endian);
|
||||
break;
|
||||
}
|
||||
//Tcp协议
|
||||
case ModbusType.Tcp:
|
||||
{
|
||||
Wrapper = ConnectionString == null
|
||||
? new ModbusTcpProtocol(SlaveAddress, MasterAddress, Endian)
|
||||
? new ModbusTcpProtocal(SlaveAddress, MasterAddress, Endian)
|
||||
: (ConnectionStringPort == null
|
||||
? new ModbusTcpProtocol(ConnectionString, SlaveAddress, MasterAddress, Endian)
|
||||
: new ModbusTcpProtocol(ConnectionStringIp, ConnectionStringPort.Value, SlaveAddress,
|
||||
? new ModbusTcpProtocal(ConnectionString, SlaveAddress, MasterAddress, Endian)
|
||||
: new ModbusTcpProtocal(ConnectionStringIp, ConnectionStringPort.Value, SlaveAddress,
|
||||
MasterAddress, Endian));
|
||||
break;
|
||||
}
|
||||
@@ -167,18 +167,18 @@ namespace Modbus.Net.Modbus
|
||||
case ModbusType.Ascii:
|
||||
{
|
||||
Wrapper = ConnectionString == null
|
||||
? new ModbusAsciiProtocol(SlaveAddress, MasterAddress, Endian)
|
||||
: new ModbusAsciiProtocol(ConnectionString, SlaveAddress, MasterAddress, Endian);
|
||||
? new ModbusAsciiProtocal(SlaveAddress, MasterAddress, Endian)
|
||||
: new ModbusAsciiProtocal(ConnectionString, SlaveAddress, MasterAddress, Endian);
|
||||
break;
|
||||
}
|
||||
//Rtu协议
|
||||
case ModbusType.RtuInTcp:
|
||||
{
|
||||
Wrapper = ConnectionString == null
|
||||
? new ModbusRtuInTcpProtocol(SlaveAddress, MasterAddress, Endian)
|
||||
? new ModbusRtuInTcpProtocal(SlaveAddress, MasterAddress, Endian)
|
||||
: (ConnectionStringPort == null
|
||||
? new ModbusRtuInTcpProtocol(ConnectionString, SlaveAddress, MasterAddress, Endian)
|
||||
: new ModbusRtuInTcpProtocol(ConnectionStringIp, ConnectionStringPort.Value, SlaveAddress,
|
||||
? new ModbusRtuInTcpProtocal(ConnectionString, SlaveAddress, MasterAddress, Endian)
|
||||
: new ModbusRtuInTcpProtocal(ConnectionStringIp, ConnectionStringPort.Value, SlaveAddress,
|
||||
MasterAddress, Endian));
|
||||
break;
|
||||
}
|
||||
@@ -186,10 +186,10 @@ namespace Modbus.Net.Modbus
|
||||
case ModbusType.AsciiInTcp:
|
||||
{
|
||||
Wrapper = ConnectionString == null
|
||||
? new ModbusAsciiInTcpProtocol(SlaveAddress, MasterAddress, Endian)
|
||||
? new ModbusAsciiInTcpProtocal(SlaveAddress, MasterAddress, Endian)
|
||||
: (ConnectionStringPort == null
|
||||
? new ModbusAsciiInTcpProtocol(ConnectionString, SlaveAddress, MasterAddress, Endian)
|
||||
: new ModbusAsciiInTcpProtocol(ConnectionStringIp, ConnectionStringPort.Value, SlaveAddress,
|
||||
? new ModbusAsciiInTcpProtocal(ConnectionString, SlaveAddress, MasterAddress, Endian)
|
||||
: new ModbusAsciiInTcpProtocal(ConnectionStringIp, ConnectionStringPort.Value, SlaveAddress,
|
||||
MasterAddress, Endian));
|
||||
break;
|
||||
}
|
||||
|
||||
60
Tests/Modbus.Net.Tests/EndianTest.cs
Normal file
60
Tests/Modbus.Net.Tests/EndianTest.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Modbus.Net.Modbus;
|
||||
|
||||
namespace Modbus.Net.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class EndianTest
|
||||
{
|
||||
private BaseMachine _modbusTcpMachine;
|
||||
|
||||
private BaseMachine _modbusTcpMachine2;
|
||||
|
||||
[TestInitialize]
|
||||
public void Init()
|
||||
{
|
||||
_modbusTcpMachine = new ModbusMachine(ModbusType.Tcp, "127.0.0.1", null, true, 1, 0);
|
||||
|
||||
_modbusTcpMachine2 = new ModbusMachine(ModbusType.Tcp, "127.0.0.1", null, true, 1, 0, Endian.LittleEndianLsb);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ModbusEndianSingle()
|
||||
{
|
||||
Random r = new Random();
|
||||
|
||||
var addresses = new List<AddressUnit>
|
||||
{
|
||||
new AddressUnit
|
||||
{
|
||||
Id = "0",
|
||||
Area = "4X",
|
||||
Address = 1,
|
||||
SubAddress = 0,
|
||||
CommunicationTag = "A1",
|
||||
DataType = typeof(ushort)
|
||||
}
|
||||
};
|
||||
|
||||
var dic1 = new Dictionary<string, double>()
|
||||
{
|
||||
{
|
||||
"4X 1", r.Next(0, UInt16.MaxValue)
|
||||
}
|
||||
};
|
||||
|
||||
_modbusTcpMachine.GetAddresses = addresses;
|
||||
_modbusTcpMachine2.GetAddresses = addresses;
|
||||
await _modbusTcpMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
||||
var ans = await _modbusTcpMachine.GetDatasAsync(MachineGetDataType.Address);
|
||||
var ans2 = await _modbusTcpMachine2.GetDatasAsync(MachineGetDataType.Address);
|
||||
Assert.AreEqual(ans["4X 1.0"].PlcValue, dic1["4X 1"]);
|
||||
Assert.AreEqual(ans2["4X 1.0"].PlcValue, (ushort)dic1["4X 1"] % 256 * 256 + (ushort)dic1["4X 1"] / 256);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,7 @@
|
||||
</Otherwise>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="EndianTest.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ModbusTest.cs" />
|
||||
<Compile Include="SiemensTest.cs" />
|
||||
|
||||
Reference in New Issue
Block a user