Fix
This commit is contained in:
@@ -37,7 +37,7 @@ namespace Modbus.Net
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task<MachineGetJobScheduler<TMachineMethod, TMachineKey, TReturnUnit>> CreateScheduler(string triggerKey, int count = 0, int intervalSecond = 1)
|
public static async Task<MachineGetJobScheduler<TMachineMethod, TMachineKey, TReturnUnit>> CreateScheduler(string triggerKey, int count = 0, int intervalSecond = 1)
|
||||||
{
|
{
|
||||||
return await CreateScheduler(triggerKey, count, (double)intervalSecond);
|
return await CreateSchedulerMillisecond(triggerKey, count, intervalSecond * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -48,16 +48,11 @@ namespace Modbus.Net
|
|||||||
/// <param name="intervalMilliSecond">间隔毫秒数</param>
|
/// <param name="intervalMilliSecond">间隔毫秒数</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task<MachineGetJobScheduler<TMachineMethod, TMachineKey, TReturnUnit>> CreateSchedulerMillisecond(string triggerKey, int count = 0, int intervalMilliSecond = 1000)
|
public static async Task<MachineGetJobScheduler<TMachineMethod, TMachineKey, TReturnUnit>> CreateSchedulerMillisecond(string triggerKey, int count = 0, int intervalMilliSecond = 1000)
|
||||||
{
|
|
||||||
return await CreateScheduler(triggerKey, count, intervalMilliSecond / 1000.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task<MachineGetJobScheduler<TMachineMethod, TMachineKey, TReturnUnit>> CreateScheduler(string triggerKey, int count = 0, double interval = 1)
|
|
||||||
{
|
{
|
||||||
IScheduler scheduler = await StdSchedulerFactory.GetDefaultScheduler();
|
IScheduler scheduler = await StdSchedulerFactory.GetDefaultScheduler();
|
||||||
|
|
||||||
ITrigger trigger;
|
ITrigger trigger;
|
||||||
if (interval <= 0)
|
if (intervalMilliSecond <= 0)
|
||||||
{
|
{
|
||||||
trigger = TriggerBuilder.Create()
|
trigger = TriggerBuilder.Create()
|
||||||
.WithIdentity(triggerKey, "Modbus.Net.DataQuery.Group." + triggerKey)
|
.WithIdentity(triggerKey, "Modbus.Net.DataQuery.Group." + triggerKey)
|
||||||
@@ -68,17 +63,17 @@ namespace Modbus.Net
|
|||||||
trigger = TriggerBuilder.Create()
|
trigger = TriggerBuilder.Create()
|
||||||
.WithIdentity(triggerKey, "Modbus.Net.DataQuery.Group." + triggerKey)
|
.WithIdentity(triggerKey, "Modbus.Net.DataQuery.Group." + triggerKey)
|
||||||
.StartNow()
|
.StartNow()
|
||||||
.WithSimpleSchedule(b => b.WithInterval(TimeSpan.FromSeconds(interval)).WithRepeatCount(count))
|
.WithSimpleSchedule(b => b.WithInterval(TimeSpan.FromMilliseconds(intervalMilliSecond)).WithRepeatCount(count))
|
||||||
.Build();
|
.Build();
|
||||||
else
|
else
|
||||||
trigger = TriggerBuilder.Create()
|
trigger = TriggerBuilder.Create()
|
||||||
.WithIdentity(triggerKey, "Modbus.Net.DataQuery.Group." + triggerKey)
|
.WithIdentity(triggerKey, "Modbus.Net.DataQuery.Group." + triggerKey)
|
||||||
.StartNow()
|
.StartNow()
|
||||||
.WithSimpleSchedule(b => b.WithInterval(TimeSpan.FromSeconds(interval)).RepeatForever())
|
.WithSimpleSchedule(b => b.WithInterval(TimeSpan.FromMilliseconds(intervalMilliSecond)).RepeatForever())
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
IJobListener listener;
|
IJobListener listener;
|
||||||
if (interval <= 0)
|
if (intervalMilliSecond <= 0)
|
||||||
{
|
{
|
||||||
listener = new JobChainingJobLIstenerWithDataMapRepeated("Modbus.Net.DataQuery.Chain." + triggerKey, new string[2] { "Value", "SetValue" }, count);
|
listener = new JobChainingJobLIstenerWithDataMapRepeated("Modbus.Net.DataQuery.Chain." + triggerKey, new string[2] { "Value", "SetValue" }, count);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,11 @@ namespace Modbus.Net
|
|||||||
return Parallel.ForEach(machines, (machine, state, index) =>
|
return Parallel.ForEach(machines, (machine, state, index) =>
|
||||||
{
|
{
|
||||||
Task.Factory.StartNew(async () =>
|
Task.Factory.StartNew(async () =>
|
||||||
|
{
|
||||||
|
if (intervalSecond > 0)
|
||||||
{
|
{
|
||||||
Thread.Sleep((int)(intervalSecond * 1000.0 / _machineCount * index));
|
Thread.Sleep((int)(intervalSecond * 1000.0 / _machineCount * index));
|
||||||
|
}
|
||||||
var getJobScheduler = await MachineJobSchedulerCreator<TMachineMethod, TMachineKey, TReturnUnit>.CreateScheduler("Trigger" + index, count, intervalSecond);
|
var getJobScheduler = await MachineJobSchedulerCreator<TMachineMethod, TMachineKey, TReturnUnit>.CreateScheduler("Trigger" + index, count, intervalSecond);
|
||||||
await machineJobTemplate(machine, getJobScheduler);
|
await machineJobTemplate(machine, getJobScheduler);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace MachineJob.Service
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
{
|
{
|
||||||
//1. 直接Coding
|
//1. 直接Coding
|
||||||
//List<AddressUnit> _addresses = new List<AddressUnit>
|
//List<AddressUnit> _addresses = new List<AddressUnit>
|
||||||
@@ -67,12 +67,10 @@ namespace MachineJob.Service
|
|||||||
//}, -1, 10));
|
//}, -1, 10));
|
||||||
|
|
||||||
//5. 不设置固定时间,连续触发Job
|
//5. 不设置固定时间,连续触发Job
|
||||||
foreach (var machine in machines)
|
return Task.Run(() => MultipleMachinesJobScheduler.RunScheduler(machines, async (machine, scheduler) =>
|
||||||
{
|
{
|
||||||
var scheduler = await MachineJobSchedulerCreator<IMachineMethodDatas, string, double>.CreateScheduler(machine.Id, -1, 0);
|
await scheduler.From(machine.Id + ".From", machine, MachineDataType.Name).Result.Query(machine.Id + ".ConsoleQuery", QueryConsole).Result.To(machine.Id + ".To", machine).Result.Deal(machine.Id + ".Deal", OnSuccess, OnFailure).Result.Run();
|
||||||
var job = scheduler.From(machine.Id + ".From", machine, MachineDataType.Name).Result.Query(machine.Id + ".ConsoleQuery", QueryConsole).Result.To(machine.Id + ".To", machine).Result.Deal(machine.Id + ".Deal", OnSuccess, OnFailure).Result;
|
}, -1, 0));
|
||||||
await job.Run();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task StopAsync(CancellationToken cancellationToken)
|
public override Task StopAsync(CancellationToken cancellationToken)
|
||||||
@@ -107,7 +105,7 @@ namespace MachineJob.Service
|
|||||||
{
|
{
|
||||||
using (var context = new DatabaseWriteContext())
|
using (var context = new DatabaseWriteContext())
|
||||||
{
|
{
|
||||||
context.DatabaseWrites.Add(new DatabaseWriteEntity
|
context.DatabaseWrites?.Add(new DatabaseWriteEntity
|
||||||
{
|
{
|
||||||
Value1 = values["Test1"].DeviceValue,
|
Value1 = values["Test1"].DeviceValue,
|
||||||
Value2 = values["Test2"].DeviceValue,
|
Value2 = values["Test2"].DeviceValue,
|
||||||
|
|||||||
Reference in New Issue
Block a user