This commit is contained in:
parallelbgls
2017-12-27 17:05:43 +08:00
parent 9b49f5af50
commit aa5aad7da0

View File

@@ -12,7 +12,7 @@ namespace Modbus.Net.PersistedTests
{
Log.Logger = new LoggerConfiguration().MinimumLevel.Verbose().WriteTo.Console().CreateLogger();
IMachineProperty<int> machine = new ModbusMachine<int, string>(1, ModbusType.Ascii, "COM5",
IMachineProperty<int> machine = new ModbusMachine<int, string>(1, ModbusType.Rtu, "COM1",
new List<AddressUnit>()
{
new AddressUnit()
@@ -40,9 +40,65 @@ namespace Modbus.Net.PersistedTests
DataType = typeof(ushort)
},
}, true, 2, 1);
IMachineProperty<int> machine2 = new ModbusMachine<int, string>(2, ModbusType.Rtu, "COM1",
new List<AddressUnit>()
{
new AddressUnit()
{
Id = "1",
Area = "4X",
Address = 11,
Name = "test 1",
DataType = typeof(ushort)
},
new AddressUnit()
{
Id = "2",
Area = "4X",
Address = 12,
Name = "test 2",
DataType = typeof(ushort)
},
new AddressUnit()
{
Id = "3",
Area = "4X",
Address = 13,
Name = "test 3",
DataType = typeof(ushort)
},
}, true, 3, 1);
IMachineProperty<int> machine3 = new ModbusMachine<int, string>(3, ModbusType.Rtu, "COM1",
new List<AddressUnit>()
{
new AddressUnit()
{
Id = "1",
Area = "4X",
Address = 21,
Name = "test 1",
DataType = typeof(ushort)
},
new AddressUnit()
{
Id = "2",
Area = "4X",
Address = 22,
Name = "test 2",
DataType = typeof(ushort)
},
new AddressUnit()
{
Id = "3",
Area = "4X",
Address = 23,
Name = "test 3",
DataType = typeof(ushort)
},
}, true, 4, 1);
TaskManager<int> manager = new TaskManager<int>(20, true);
manager.AddMachines<string>(new List<IMachineProperty<int>>{machine});
manager.AddMachines<string>(new List<IMachineProperty<int>> { machine, machine2, machine3 });
Random r = new Random();
manager.InvokeTimerForMachine(1, new TaskItemSetData(() => new Dictionary<string, double>
{
@@ -79,7 +135,7 @@ namespace Modbus.Net.PersistedTests
{
"4X 23.0", r.Next() % 65536
},
}, MachineSetDataType.Address, 10000, 10000));
}, MachineSetDataType.Address, 10000, 10000));
Thread.Sleep(5000);
manager.InvokeTimerAll(new TaskItemGetData(data =>
{
@@ -87,7 +143,7 @@ namespace Modbus.Net.PersistedTests
{
Console.WriteLine(dataInner.Key + " " + dataInner.Value.PlcValue);
}
}, MachineGetDataType.Address, 10000, 10000));
Console.Read();