Skip to content

Commit

Permalink
1、#4
Browse files Browse the repository at this point in the history
2、新增AllenBradleyClient
  • Loading branch information
zhaopeiym committed May 6, 2021
1 parent c01ba65 commit 79e5b1a
Show file tree
Hide file tree
Showing 35 changed files with 2,848 additions and 1,214 deletions.
133 changes: 98 additions & 35 deletions IoTClient.Tests/Modbus_Tests/ModBusRtuClient_tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,6 @@ public ModbusRtuClient_tests()
client = new ModbusRtuClient("COM3", 9600, 8, StopBits.One, Parity.None);
}

[Fact]
public void 批量读取()
{
var list = new List<ModbusInput>();
list.Add(new ModbusInput()
{
Address = "2",
DataType = DataTypeEnum.Int16,
FunctionCode = 3,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "2",
DataType = DataTypeEnum.Int16,
FunctionCode = 4,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "5",
DataType = DataTypeEnum.Int16,
FunctionCode = 3,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "199",
DataType = DataTypeEnum.Int16,
FunctionCode = 3,
StationNumber = 1
});
var result = client.BatchRead(list);
}

[Fact]
public async Task 短连接自动开关()
{
Expand Down Expand Up @@ -119,5 +84,103 @@ public async Task 长连接主动开关()

client.Close();
}

[Fact]
public void 批量读取()
{
var list = new List<ModbusInput>();
list.Add(new ModbusInput()
{
Address = "2",
DataType = DataTypeEnum.Int16,
FunctionCode = 3,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "2",
DataType = DataTypeEnum.Int16,
FunctionCode = 4,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "5",
DataType = DataTypeEnum.Int16,
FunctionCode = 3,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "199",
DataType = DataTypeEnum.Int16,
FunctionCode = 3,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "200",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "201",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "202",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "203",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "204",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "205",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "206",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "207",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "208",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
var result = client.BatchRead(list);
}
}
}
73 changes: 64 additions & 9 deletions IoTClient.Tests/Modbus_Tests/ModBusTcpClient_tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task 短连接自动开关()
ulong ulong_number = (ulong)Math.Abs(rnd.Next(int.MinValue, int.MaxValue));
float float_number = rnd.Next(int.MinValue, int.MaxValue) / 100;
double double_number = (double)rnd.Next(int.MinValue, int.MaxValue) / 100;
bool coil = int_number % 2 == 0;
bool coil = int_number % 2 == 0;
#endregion

//写入地址:0 值为:short_number 站号:stationNumber 功能码:默认16(也可以自己传入对应的功能码)
Expand Down Expand Up @@ -124,14 +124,6 @@ public async Task 长连接主动开关()
[Fact]
public void 批量读取()
{
Dictionary<string, DataTypeEnum> addresses = new Dictionary<string, DataTypeEnum>();
addresses.Add("2", DataTypeEnum.Int16);
addresses.Add("5", DataTypeEnum.Int16);
addresses.Add("13", DataTypeEnum.Int16);
addresses.Add("19", DataTypeEnum.Int16);
addresses.Add("198", DataTypeEnum.Int16);
addresses.Add("199", DataTypeEnum.Int16);

var list = new List<ModbusInput>();
list.Add(new ModbusInput()
{
Expand Down Expand Up @@ -161,6 +153,69 @@ public void 批量读取()
FunctionCode = 3,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "200",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "201",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "202",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "203",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "204",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "205",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "206",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "207",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
list.Add(new ModbusInput()
{
Address = "208",
DataType = DataTypeEnum.Bool,
FunctionCode = 2,
StationNumber = 1
});
var result = client.BatchRead(list);
}
}
Expand Down
Loading

0 comments on commit 79e5b1a

Please sign in to comment.