Fix a bug in controller
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Modbus.Net;
|
||||
using Modbus.Net.Modbus;
|
||||
using Modbus.Net.Siemens;
|
||||
|
||||
namespace MachineJob.Service
|
||||
{
|
||||
@@ -14,6 +15,7 @@ namespace MachineJob.Service
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
|
||||
List<AddressUnit> _addresses = new List<AddressUnit>
|
||||
{
|
||||
new AddressUnit() { Area = "4X", Address = 1, DataType = typeof(short), Id = "1", Name = "Test1" },
|
||||
@@ -27,12 +29,27 @@ namespace MachineJob.Service
|
||||
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<string> machine = new ModbusMachine<string, string>("ModbusMachine1", ModbusType.Tcp, "192.168.0.172", _addresses, true, 1, 2, Endian.BigEndianLsb);
|
||||
//IMachine<string> machine2 = new ModbusMachine<string, string>("ModbusMachine2", ModbusType.Tcp, "192.168.0.172", _addresses, true, 3, 2, Endian.BigEndianLsb);
|
||||
|
||||
/*
|
||||
List<AddressUnit> _addresses2 = new List<AddressUnit>
|
||||
{
|
||||
new AddressUnit() { Area = "DB1", Address = 0, DataType = typeof(short), Id = "1", Name = "Test1" },
|
||||
new AddressUnit() { Area = "DB1", Address = 2, DataType = typeof(short), Id = "2", Name = "Test2" },
|
||||
new AddressUnit() { Area = "DB1", Address = 4, DataType = typeof(short), Id = "3", Name = "Test3" },
|
||||
new AddressUnit() { Area = "DB1", Address = 6, DataType = typeof(short), Id = "4", Name = "Test4" },
|
||||
new AddressUnit() { Area = "DB1", Address = 8, DataType = typeof(short), Id = "5", Name = "Test5" },
|
||||
new AddressUnit() { Area = "DB1", Address = 10, DataType = typeof(short), Id = "6", Name = "Test6" },
|
||||
new AddressUnit() { Area = "DB1", Address = 12, DataType = typeof(short), Id = "7", Name = "Test7" },
|
||||
new AddressUnit() { Area = "DB1", Address = 14, DataType = typeof(short), Id = "8", Name = "Test8" },
|
||||
new AddressUnit() { Area = "DB1", Address = 16, DataType = typeof(short), Id = "9", Name = "Test9" },
|
||||
new AddressUnit() { Area = "DB1", Address = 18, DataType = typeof(short), Id = "10", Name = "Test10" }
|
||||
};
|
||||
*/
|
||||
IMachine<string> machine = new ModbusMachine<string, string>("ModbusMachine1", ModbusType.Tcp, "192.168.0.161", _addresses, true, 1, 2, Endian.BigEndianLsb);
|
||||
//IMachine<string> machine2 = new SiemensMachine<string, string>("SiemensMachine1", SiemensType.Tcp, "192.168.0.161", SiemensMachineModel.S7_1200, _addresses2, true, 1, 2);
|
||||
|
||||
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.Deal(machine.Id+".Deal", OnSuccess, OnFailure).Result.Run();
|
||||
//await MachineJobSchedulerCreator.CreateScheduler("Trigger2", -1, 5).Result.Apply(machine2.Id + ".Apply", null, MachineDataType.Name).Result.Query(machine2.Id + ".ConsoleQuery", QueryConsole2).Result.To(machine2.Id + ".To", machine2).Result.Deal(machine.Id + ".Deal", OnSuccess, OnFailure).Result.From(machine2.Id, machine2, MachineDataType.Name).Result.Query(machine2.Id + ".ConsoleQuery2", QueryConsole).Result.Run();
|
||||
//await MachineJobSchedulerCreator.CreateScheduler("Trigger2", -1, 5).Result.From(machine2.Id, machine2, MachineDataType.Name).Result.Query(machine2.Id + ".ConsoleQuery", QueryConsole).Result.To(machine2.Id + ".To", machine2).Result.Deal(machine2.Id + ".Deal", OnSuccess, OnFailure).Result.Run();
|
||||
}
|
||||
|
||||
public override async Task StopAsync(CancellationToken cancellationToken)
|
||||
@@ -59,7 +76,7 @@ namespace MachineJob.Service
|
||||
{
|
||||
Console.WriteLine(dataReturnDef.MachineId + " " + value.Key + " " + value.Value.DeviceValue);
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
using (var context = new DatabaseWriteContext())
|
||||
@@ -85,7 +102,7 @@ namespace MachineJob.Service
|
||||
{
|
||||
//ignore
|
||||
}
|
||||
|
||||
|
||||
Random r = new Random();
|
||||
foreach (var value in values)
|
||||
{
|
||||
@@ -94,45 +111,5 @@ namespace MachineJob.Service
|
||||
|
||||
return values.MapGetValuesToSetValues();
|
||||
}
|
||||
|
||||
private Dictionary<string, double> QueryConsole2(DataReturnDef dataReturnDef)
|
||||
{
|
||||
Random r = new Random();
|
||||
var datas = new Dictionary<string, double>()
|
||||
{
|
||||
{
|
||||
"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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user