Fix
This commit is contained in:
@@ -37,7 +37,7 @@ namespace Modbus.Net
|
||||
/// <returns></returns>
|
||||
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>
|
||||
@@ -48,16 +48,11 @@ namespace Modbus.Net
|
||||
/// <param name="intervalMilliSecond">间隔毫秒数</param>
|
||||
/// <returns></returns>
|
||||
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();
|
||||
|
||||
ITrigger trigger;
|
||||
if (interval <= 0)
|
||||
if (intervalMilliSecond <= 0)
|
||||
{
|
||||
trigger = TriggerBuilder.Create()
|
||||
.WithIdentity(triggerKey, "Modbus.Net.DataQuery.Group." + triggerKey)
|
||||
@@ -68,17 +63,17 @@ namespace Modbus.Net
|
||||
trigger = TriggerBuilder.Create()
|
||||
.WithIdentity(triggerKey, "Modbus.Net.DataQuery.Group." + triggerKey)
|
||||
.StartNow()
|
||||
.WithSimpleSchedule(b => b.WithInterval(TimeSpan.FromSeconds(interval)).WithRepeatCount(count))
|
||||
.WithSimpleSchedule(b => b.WithInterval(TimeSpan.FromMilliseconds(intervalMilliSecond)).WithRepeatCount(count))
|
||||
.Build();
|
||||
else
|
||||
trigger = TriggerBuilder.Create()
|
||||
.WithIdentity(triggerKey, "Modbus.Net.DataQuery.Group." + triggerKey)
|
||||
.StartNow()
|
||||
.WithSimpleSchedule(b => b.WithInterval(TimeSpan.FromSeconds(interval)).RepeatForever())
|
||||
.WithSimpleSchedule(b => b.WithInterval(TimeSpan.FromMilliseconds(intervalMilliSecond)).RepeatForever())
|
||||
.Build();
|
||||
|
||||
IJobListener listener;
|
||||
if (interval <= 0)
|
||||
if (intervalMilliSecond <= 0)
|
||||
{
|
||||
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) =>
|
||||
{
|
||||
Task.Factory.StartNew(async () =>
|
||||
{
|
||||
if (intervalSecond > 0)
|
||||
{
|
||||
Thread.Sleep((int)(intervalSecond * 1000.0 / _machineCount * index));
|
||||
}
|
||||
var getJobScheduler = await MachineJobSchedulerCreator<TMachineMethod, TMachineKey, TReturnUnit>.CreateScheduler("Trigger" + index, count, intervalSecond);
|
||||
await machineJobTemplate(machine, getJobScheduler);
|
||||
});
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace MachineJob.Service
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
protected override Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
//1. 直接Coding
|
||||
//List<AddressUnit> _addresses = new List<AddressUnit>
|
||||
@@ -67,12 +67,10 @@ namespace MachineJob.Service
|
||||
//}, -1, 10));
|
||||
|
||||
//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);
|
||||
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;
|
||||
await job.Run();
|
||||
}
|
||||
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();
|
||||
}, -1, 0));
|
||||
}
|
||||
|
||||
public override Task StopAsync(CancellationToken cancellationToken)
|
||||
@@ -107,7 +105,7 @@ namespace MachineJob.Service
|
||||
{
|
||||
using (var context = new DatabaseWriteContext())
|
||||
{
|
||||
context.DatabaseWrites.Add(new DatabaseWriteEntity
|
||||
context.DatabaseWrites?.Add(new DatabaseWriteEntity
|
||||
{
|
||||
Value1 = values["Test1"].DeviceValue,
|
||||
Value2 = values["Test2"].DeviceValue,
|
||||
|
||||
Reference in New Issue
Block a user