将PollLevelType类型改为int类型
This commit is contained in:
@@ -30,24 +30,24 @@ public class OptimizedS7BackgroundService : BackgroundService
|
||||
private readonly int _s7PollOnceSleepTimeMs = 50;
|
||||
|
||||
// 存储每个设备的变量按轮询级别分组
|
||||
private readonly ConcurrentDictionary<int, Dictionary<PollLevelType, List<VariableDto>>> _variablesByPollLevel = new();
|
||||
private readonly ConcurrentDictionary<int, Dictionary<int, List<VariableDto>>> _variablesByPollLevel = new();
|
||||
|
||||
// 模拟 PollingIntervals,实际应用中可能从配置或数据库加载
|
||||
private static readonly Dictionary<PollLevelType, TimeSpan> PollingIntervals = new Dictionary<PollLevelType, TimeSpan>
|
||||
private static readonly Dictionary<int, TimeSpan> PollingIntervals = new Dictionary<int, TimeSpan>
|
||||
{
|
||||
{ PollLevelType.TenMilliseconds, TimeSpan.FromMilliseconds((int)PollLevelType.TenMilliseconds) },
|
||||
{ PollLevelType.HundredMilliseconds, TimeSpan.FromMilliseconds((int)PollLevelType.HundredMilliseconds) },
|
||||
{ PollLevelType.FiveHundredMilliseconds, TimeSpan.FromMilliseconds((int)PollLevelType.FiveHundredMilliseconds) },
|
||||
{ PollLevelType.OneSecond, TimeSpan.FromMilliseconds((int)PollLevelType.OneSecond) },
|
||||
{ PollLevelType.FiveSeconds, TimeSpan.FromMilliseconds((int)PollLevelType.FiveSeconds) },
|
||||
{ PollLevelType.TenSeconds, TimeSpan.FromMilliseconds((int)PollLevelType.TenSeconds) },
|
||||
{ PollLevelType.TwentySeconds, TimeSpan.FromMilliseconds((int)PollLevelType.TwentySeconds) },
|
||||
{ PollLevelType.ThirtySeconds, TimeSpan.FromMilliseconds((int)PollLevelType.ThirtySeconds) },
|
||||
{ PollLevelType.OneMinute, TimeSpan.FromMilliseconds((int)PollLevelType.OneMinute) },
|
||||
{ PollLevelType.ThreeMinutes, TimeSpan.FromMilliseconds((int)PollLevelType.ThreeMinutes) },
|
||||
{ PollLevelType.FiveMinutes, TimeSpan.FromMilliseconds((int)PollLevelType.FiveMinutes) },
|
||||
{ PollLevelType.TenMinutes, TimeSpan.FromMilliseconds((int)PollLevelType.TenMinutes) },
|
||||
{ PollLevelType.ThirtyMinutes, TimeSpan.FromMilliseconds((int)PollLevelType.ThirtyMinutes) }
|
||||
{ 10, TimeSpan.FromMilliseconds(10) }, // TenMilliseconds
|
||||
{ 100, TimeSpan.FromMilliseconds(100) }, // HundredMilliseconds
|
||||
{ 500, TimeSpan.FromMilliseconds(500) }, // FiveHundredMilliseconds
|
||||
{ 1000, TimeSpan.FromMilliseconds(1000) }, // OneSecond
|
||||
{ 5000, TimeSpan.FromMilliseconds(5000) }, // FiveSeconds
|
||||
{ 10000, TimeSpan.FromMilliseconds(10000) }, // TenSeconds
|
||||
{ 20000, TimeSpan.FromMilliseconds(20000) }, // TwentySeconds
|
||||
{ 30000, TimeSpan.FromMilliseconds(30000) }, // ThirtySeconds
|
||||
{ 60000, TimeSpan.FromMilliseconds(60000) }, // OneMinute
|
||||
{ 180000, TimeSpan.FromMilliseconds(180000) }, // ThreeMinutes
|
||||
{ 300000, TimeSpan.FromMilliseconds(300000) }, // FiveMinutes
|
||||
{ 600000, TimeSpan.FromMilliseconds(600000) }, // TenMinutes
|
||||
{ 1800000, TimeSpan.FromMilliseconds(1800000) } // ThirtyMinutes
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -223,7 +223,7 @@ public class OptimizedS7BackgroundService : BackgroundService
|
||||
/// <summary>
|
||||
/// 检查是否应该轮询变量
|
||||
/// </summary>
|
||||
private bool ShouldPollVariables(List<VariableDto> variables, PollLevelType pollLevel)
|
||||
private bool ShouldPollVariables(List<VariableDto> variables, int pollLevel)
|
||||
{
|
||||
if (!PollingIntervals.TryGetValue(pollLevel, out var interval))
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user