Test fix and tcp connector disconnect bug fix
This commit is contained in:
@@ -7,32 +7,35 @@ namespace Modbus.Net.Tests
|
||||
[TestClass]
|
||||
public class MachineMethodTest
|
||||
{
|
||||
private string _machineIp = "10.10.18.251";
|
||||
|
||||
[TestMethod]
|
||||
public void GetUtility()
|
||||
{
|
||||
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(1, ModbusType.Tcp, "192.168.3.12", null, true, 2, 0);
|
||||
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(1, ModbusType.Tcp, _machineIp, null, true, 2, 0);
|
||||
var utility = baseMachine.GetUtilityMethods<IUtilityMethodDatas>();
|
||||
var methods = utility.GetType().GetRuntimeMethods();
|
||||
Assert.AreEqual(methods.FirstOrDefault(method => method.Name == "GetDataAsync") != null, true);
|
||||
Assert.AreEqual(methods.FirstOrDefault(method => method.Name == "SetDataAsync") != null, true);
|
||||
Assert.AreEqual(methods.FirstOrDefault(method => method.Name == "GetDatasAsync") != null, true);
|
||||
Assert.AreEqual(methods.FirstOrDefault(method => method.Name == "SetDatasAsync") != null, true);
|
||||
baseMachine.Disconnect();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task InvokeUtility()
|
||||
{
|
||||
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<IUtilityMethodDatas>().SetDatasAsync("4X 1", new object[] { (byte)11 });
|
||||
Assert.AreEqual(success, true);
|
||||
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(1, ModbusType.Tcp, _machineIp, null, true, 2, 0);
|
||||
await baseMachine.BaseUtility.ConnectAsync();
|
||||
var success = await baseMachine.BaseUtility.GetUtilityMethods<IUtilityMethodDatas>().SetDatasAsync("4X 1", new object[] { (ushort)11 });
|
||||
Assert.AreEqual(success.IsSuccess, true);
|
||||
var datas = await baseMachine.BaseUtility.GetUtilityMethods<IUtilityMethodDatas>().GetDatasAsync("4X 1", 1);
|
||||
Assert.AreEqual(datas.Datas[0], 11);
|
||||
Assert.AreEqual(datas.Datas[1], 11);
|
||||
baseMachine.Disconnect();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task InvokeMachine()
|
||||
{
|
||||
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(1, ModbusType.Tcp, "192.168.3.10", new List<AddressUnit<int>>
|
||||
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(1, ModbusType.Tcp, _machineIp, new List<AddressUnit<int>>
|
||||
{
|
||||
new AddressUnit<int>
|
||||
{
|
||||
@@ -52,7 +55,7 @@ namespace Modbus.Net.Tests
|
||||
"0X 1.0", 1
|
||||
}
|
||||
});
|
||||
Assert.AreEqual(success, true);
|
||||
Assert.AreEqual(success.IsSuccess, true);
|
||||
var datas = await baseMachine.GetMachineMethods<IMachineMethodDatas>().GetDatasAsync(MachineDataType.Address);
|
||||
Assert.AreEqual(datas.Datas["0X 1.0"].DeviceValue, 1);
|
||||
success = await baseMachine.GetMachineMethods<IMachineMethodDatas>().SetDatasAsync(
|
||||
@@ -63,7 +66,7 @@ namespace Modbus.Net.Tests
|
||||
"0X 1.0", 0
|
||||
}
|
||||
});
|
||||
Assert.AreEqual(success, true);
|
||||
Assert.AreEqual(success.IsSuccess, true);
|
||||
baseMachine.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user