CAN的更改

This commit is contained in:
2025-05-09 16:13:11 +08:00
parent df4b481bbb
commit 03fd92ac86
8 changed files with 176 additions and 131 deletions

View File

@@ -296,75 +296,85 @@ namespace CapMachine.Wpf.Services
/// <exception cref="NotImplementedException"></exception>
private async void ListenRecoredChannelAction()
{
while (await RecoredChannelInfo.Reader.WaitToReadAsync())
{
if (RecoredChannelInfo.Reader.TryRead(out var recordChannelData))
try
{
////第一次计时
//stopwatch.Start(); //启动Stopwatch
//新增数据
CacheRecordData.Add(recordChannelData);
MaxCacheCellCount++;
//先判断缓存的单元大小,防止每次都检查删除,数据达到时间范围外的话,则删除,即是600次后进行一次判断删除
if (MaxCacheCellCount >= 600)
if (RecoredChannelInfo.Reader.TryRead(out var recordChannelData))
{
//不在缓存的时间范围内的话,则删除数据
if (CacheRecordData.Where(a => a.CreateTime <= DateTime.Now.AddSeconds(-ConfigService.ChartRtDataCacheTimeSec)).Any())
////第一次计时
//stopwatch.Start(); //启动Stopwatch
//新增数据
CacheRecordData.Add(recordChannelData);
MaxCacheCellCount++;
//先判断缓存的单元大小,防止每次都检查删除,数据达到时间范围外的话,则删除,即是600次后进行一次判断删除
if (MaxCacheCellCount >= 600)
{
CacheRecordData.RemoveAll(a => a.CreateTime <= DateTime.Now.AddSeconds(-ConfigService.ChartRtDataCacheTimeSec));
//不在缓存的时间范围内的话,则删除数据
if (CacheRecordData.Where(a => a.CreateTime <= DateTime.Now.AddSeconds(-ConfigService.ChartRtDataCacheTimeSec)).Any())
{
CacheRecordData.RemoveAll(a => a.CreateTime <= DateTime.Now.AddSeconds(-ConfigService.ChartRtDataCacheTimeSec));
}
MaxCacheCellCount = 0;
}
MaxCacheCellCount = 0;
//ConcurrentQueueData.
//Prism发布数据
_EventAggregator.GetEvent<RecordDataEvent>().Publish(recordChannelData.DeepClone());
//判断集合的数据是否达到要求
//if (CacheRecordData.Count >= MaxCacheCount)
//{
//CacheRecordData可能存在多个表格数据依据表名进行分类
//考虑多个表结构
//var GroupTableData = CacheRecordData.GroupBy(a => a.TableName).ToList();
//foreach (var ItemData in GroupTableData)
//{
//表名称
//var TableName = ItemData.Key;
//当前表格的数据
//var Datas = ItemData.Select(item => item.Data).ToList();
//var Datas = recordChannelData.Select(item => item.Data).ToList();
//List<CsvRecordModel> models = Datas.Select(dict => ConvertToCsvRecordModel(dict)).ToList();
//转换到CSV的数据
var models = ConvertToCsvRecordModel(recordChannelData.Data);
//填充工况名称
models.WorkCond = ConfigService.CurExpInfo.Name;
//数据库保存
//zeroDbContext.Insert(Datas);
//CSV文件保存
SaveToCsv(new List<CsvRecordModel>() { models });
//}
//CacheRecordData.Clear();
//Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:fff")}-{LineName}-保存成功!");
//}
//stopwatch.Stop(); //停止Stopwatch
//Console.WriteLine("保存数据耗时::{0}", stopwatch.Elapsed.TotalSeconds.ToString());
//stopwatch.Reset();
}
//ConcurrentQueueData.
//Prism发布数据
_EventAggregator.GetEvent<RecordDataEvent>().Publish(recordChannelData.DeepClone());
//判断集合的数据是否达到要求
//if (CacheRecordData.Count >= MaxCacheCount)
//{
//CacheRecordData可能存在多个表格数据依据表名进行分类
//考虑多个表结构
//var GroupTableData = CacheRecordData.GroupBy(a => a.TableName).ToList();
//foreach (var ItemData in GroupTableData)
//{
//表名称
//var TableName = ItemData.Key;
//当前表格的数据
//var Datas = ItemData.Select(item => item.Data).ToList();
//var Datas = recordChannelData.Select(item => item.Data).ToList();
//List<CsvRecordModel> models = Datas.Select(dict => ConvertToCsvRecordModel(dict)).ToList();
//转换到CSV的数据
var models = ConvertToCsvRecordModel(recordChannelData.Data);
//填充工况名称
models.WorkCond = ConfigService.CurExpInfo.Name;
//数据库保存
//zeroDbContext.Insert(Datas);
//CSV文件保存
SaveToCsv(new List<CsvRecordModel>() { models });
//}
//CacheRecordData.Clear();
//Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:fff")}-{LineName}-保存成功!");
//}
//stopwatch.Stop(); //停止Stopwatch
//Console.WriteLine("保存数据耗时::{0}", stopwatch.Elapsed.TotalSeconds.ToString());
//stopwatch.Reset();
}
catch (Exception ex)
{
LogService.Error($"时间:{DateTime.Now.ToString()}-【ListenRecoredChannelAction】-{ex.Message}");
}
}
}
/// <summary>
@@ -459,7 +469,7 @@ namespace CapMachine.Wpf.Services
catch (Exception ex)
{
//CycleTimer.Start(); //执行完毕后再开启器
LogService.Info($"时间:{DateTime.Now.ToString()}-【PwAnalyze-CycleAction】-{ex.Message}");
LogService.Error($"时间:{DateTime.Now.ToString()}-【PwAnalyze-CycleAction】-{ex.Message}");
}
}