// See https://aka.ms/new-console-template for more information using MachineJob; using Modbus.Net; using Modbus.Net.Modbus; List _addresses = new List { new AddressUnit() { Area = "4X", Address = 1, DataType = typeof(short), Id = "1", Name = "Test1" }, new AddressUnit() { Area = "4X", Address = 2, DataType = typeof(short), Id = "2", Name = "Test2" }, new AddressUnit() { Area = "4X", Address = 3, DataType = typeof(short), Id = "3", Name = "Test3" }, new AddressUnit() { Area = "4X", Address = 4, DataType = typeof(short), Id = "4", Name = "Test4" }, new AddressUnit() { Area = "4X", Address = 5, DataType = typeof(short), Id = "5", Name = "Test5" }, new AddressUnit() { Area = "4X", Address = 6, DataType = typeof(short), Id = "6", Name = "Test6" }, new AddressUnit() { Area = "4X", Address = 7, DataType = typeof(short), Id = "7", Name = "Test7" }, new AddressUnit() { Area = "4X", Address = 8, DataType = typeof(short), Id = "8", Name = "Test8" }, new AddressUnit() { Area = "4X", Address = 9, DataType = typeof(short), Id = "9", Name = "Test9" }, new AddressUnit() { Area = "4X", Address = 10, DataType = typeof(short), Id = "10", Name = "Test10" } }; IMachine machine = new ModbusMachine("ModbusMachine1", ModbusType.Tcp, "192.168.0.172", _addresses, true, 1, 2, Endian.BigEndianLsb); IMachine machine2 = new ModbusMachine("ModbusMachine2", ModbusType.Tcp, "192.168.0.172:503", _addresses, true, 3, 2, Endian.BigEndianLsb); await MachineJobSchedulerCreator.CreateScheduler("Trigger1", -1, 5).Result.From(machine.Id, machine, MachineDataType.Name).Result.Query(machine.Id + ".ConsoleQuery", QueryConsole).Result.To(machine.Id + ".To", machine).Result.To(machine2.Id + ".To", machine2).Result.Run(); //await MachineJobSchedulerCreator.CreateScheduler("Trigger2", -1, 5).Result.Apply(machine2.Id + ".Apply", null, MachineDataType.Name).Result.Query(machine.Id + ".ConsoleQuery2", QueryConsole2).Result.To(machine2.Id + ".To2", machine2).Result.From(machine2.Id, machine2, MachineDataType.Name).Result.Query(machine.Id + ".ConsoleQuery", QueryConsole).Result.Run(); Console.ReadLine(); Dictionary QueryConsole(DataReturnDef dataReturnDef) { var values = dataReturnDef.ReturnValues; foreach (var value in values) { Console.WriteLine(dataReturnDef.MachineId + " " + value.Key + " " + value.Value.DeviceValue); } try { using (var context = new DatabaseWriteContext()) { context.DatabaseWrites.Add(new DatabaseWriteEntity { Value1 = values["Test1"].DeviceValue, Value2 = values["Test2"].DeviceValue, Value3 = values["Test3"].DeviceValue, Value4 = values["Test4"].DeviceValue, Value5 = values["Test5"].DeviceValue, Value6 = values["Test6"].DeviceValue, Value7 = values["Test7"].DeviceValue, Value8 = values["Test8"].DeviceValue, Value9 = values["Test9"].DeviceValue, Value10 = values["Test10"].DeviceValue, UpdateTime = DateTime.Now, }); context.SaveChanges(); } } catch { //ignore } Random r = new Random(); foreach (var value in values) { value.Value.DeviceValue = r.Next(65536) - 32768; } return values.MapGetValuesToSetValues(); } Dictionary QueryConsole2(DataReturnDef dataReturnDef) { Random r = new Random(); var datas = new Dictionary() { { "Test1", r.Next(65536) - 32768 }, { "Test2", r.Next(65536) - 32768 }, { "Test3", r.Next(65536) - 32768 }, { "Test4", r.Next(65536) - 32768 }, { "Test5", r.Next(65536) - 32768 }, { "Test6", r.Next(65536) - 32768 }, { "Test7", r.Next(65536) - 32768 }, { "Test8", r.Next(65536) - 32768 }, { "Test9", r.Next(65536) - 32768 }, { "Test10", r.Next(65536) - 32768 } }; return datas; }