using System; using System.Collections.Generic; using System.Threading; using Modbus.Net.Modbus; using Serilog; namespace Modbus.Net.PersistedTests { class Program { static void Main(string[] args) { Log.Logger = new LoggerConfiguration().MinimumLevel.Verbose().WriteTo.Console().CreateLogger(); IMachineProperty machine = new ModbusMachine(1, ModbusType.Tcp, "127.0.0.1", new List() { new AddressUnit() { Id = "1", Area = "4X", Address = 1, Name = "test 1", DataType = typeof(ushort) }, new AddressUnit() { Id = "2", Area = "4X", Address = 2, Name = "test 2", DataType = typeof(ushort) }, new AddressUnit() { Id = "3", Area = "4X", Address = 3, Name = "test 3", DataType = typeof(ushort) }, }, true, 2, 1); TaskManager manager = new TaskManager(20, true); manager.AddMachines(new List> { machine }); Random r = new Random(); manager.InvokeTimerForMachine(1, new TaskItemSetData(() => new Dictionary { { "4X 1.0", r.Next() % 65536 }, { "4X 2.0", r.Next() % 65536 }, { "4X 3.0", r.Next() % 65536 }, }, MachineSetDataType.Address, 10000, 10000)); Thread.Sleep(5000); manager.InvokeTimerAll(new TaskItemGetData(data => { if (data?.ReturnValues != null) { foreach (var dataInner in data.ReturnValues) { Console.WriteLine(dataInner.Key + " " + dataInner.Value.PlcValue); } } }, MachineGetDataType.Address, 10000, 10000)); Console.Read(); Console.Read(); } } }