LIN SCH 更改

This commit is contained in:
2025-10-15 09:54:46 +08:00
parent db6acc2741
commit ad1d3e081f
6 changed files with 164 additions and 54 deletions

View File

@@ -186,6 +186,12 @@ namespace CapMachine.Wpf.LinDrive
/// </summary>
public List<LinCmdData> CmdData { get; set; } = new List<LinCmdData>();
/// <summary>
/// 当前激活调度表下,启用的帧/报文名称集合(来自 ListLINScheduleConfig 的 IsMsgActived
/// 为空(null) 表示不过滤,使用所有 CmdData 中的帧;非空则仅对包含在集合内的帧做信号更新与下发。
/// </summary>
private HashSet<string>? ActiveMsgNames;
/// <summary>
/// ******************【1】*********************
/// 是否存在Dll文件
@@ -809,25 +815,7 @@ namespace CapMachine.Wpf.LinDrive
if (LDFHandle == 0)
return;
// 1) 先将当前指令值写入对应帧(可选,用于初始化
if (CmdData != null && CmdData.Count > 0)
{
var groupMsg = CmdData.GroupBy(x => x.MsgName);
foreach (var itemMsg in groupMsg)
{
foreach (var itemSignal in itemMsg)
{
//测试的速度数据
//if (!string.IsNullOrEmpty(itemSignal.ConfigName) && itemSignal.ConfigName.Contains("速"))
//{
// itemSignal.SignalCmdValue = 1000;
//}
LDFParser.LDF_SetSignalValue(LDFHandle, new StringBuilder(itemMsg.Key), new StringBuilder(itemSignal.SignalName), itemSignal.SignalCmdValue);
}
}
}
// 2) 将要执行的调度表烧入适配器并自动运行(若不指定,则启动全部调度表)
// 1) 将要执行的调度表烧入适配器并自动运行(若不指定,则启动全部调度表
// 优先使用 ListLINScheduleConfig 指定的调度表名;否则默认取第一个
string selectedSch = string.Empty;
if (ListLINScheduleConfig != null && ListLINScheduleConfig.Count > 0)
@@ -848,6 +836,40 @@ namespace CapMachine.Wpf.LinDrive
//当前激活的调度表
ActiveSchName = selectedSch;
// 计算当前激活调度表下的“被选中帧”集合IsMsgActived=true
if (!string.IsNullOrEmpty(ActiveSchName) && ListLINScheduleConfig != null)
{
var actives = ListLINScheduleConfig
.Where(d => d.IsActive && d.IsMsgActived && string.Equals(d.SchTabName ?? string.Empty, ActiveSchName ?? string.Empty, StringComparison.Ordinal))
.Select(d => d.MsgName)
.Where(n => !string.IsNullOrEmpty(n))
.Distinct()
.ToList();
ActiveMsgNames = actives.Count > 0 ? new HashSet<string>(actives) : new HashSet<string>();
}
else
{
ActiveMsgNames = null; // 不过滤
}
// 2) 先将当前指令值写入对应帧(可选,用于初始化,仅对被选中的帧)
if (CmdData != null && CmdData.Count > 0)
{
var groupMsg = CmdData.GroupBy(x => x.MsgName);
foreach (var itemMsg in groupMsg)
{
// 若设置了激活的帧集合,则进行过滤
if (ActiveMsgNames != null && !ActiveMsgNames.Contains(itemMsg.Key))
continue;
foreach (var itemSignal in itemMsg)
{
LDFParser.LDF_SetSignalValue(LDFHandle, new StringBuilder(itemMsg.Key), new StringBuilder(itemSignal.SignalName), itemSignal.SignalCmdValue);
}
}
}
// 3) 下发选中调度表到表格并自动执行
var ret = LDFParser.LDF_SetSchToTable(LDFHandle, new StringBuilder(ActiveSchName), 0);
if (ret < 0)
{
@@ -859,22 +881,7 @@ namespace CapMachine.Wpf.LinDrive
LoggerService?.Info($"调度表[{ActiveSchName}]已启动(自动执行)");
}
//SchCount = GetSchCount();
//for (int i = 0; i < SchCount; i++)
//{
// var schName = GetSchName(i);
// var ret = LDFParser.LDF_SetSchToTable(LDFHandle, new StringBuilder(schName), 0);
// if (ret < 0)
// {
// LoggerService?.Info($"启动调度表[{schName}]失败, 返回:{ret}");
// }
// else
// {
// Console.WriteLine($"调度表[{schName}]已启动(自动执行)");
// }
//}
// 3) 置位调度更新开关,启动参数更新任务
// 4) 置位调度更新开关,启动参数更新任务
//SchEnable = true;
if (CycleUpdateCmdTask == null || CycleUpdateCmdTask.IsCompleted)
{
@@ -903,6 +910,9 @@ namespace CapMachine.Wpf.LinDrive
var GroupMsg = CmdData.GroupBy(x => x.MsgName);
foreach (var itemMsg in GroupMsg)
{
// 若设置了激活的帧集合,则进行过滤
if (ActiveMsgNames != null && !ActiveMsgNames.Contains(itemMsg.Key))
continue;
foreach (var itemSignal in itemMsg)
{
if (itemSignal.ConfigName.Contains("速"))
@@ -919,7 +929,8 @@ namespace CapMachine.Wpf.LinDrive
//读取当前的指令帧数据LDF_ExeFrameToBus执行后就可以读取本身的数据
foreach (var item in ListLinLdfModel)
{
if (CmdData.Any(a => a.MsgName == item.MsgName))
if (CmdData.Any(a => a.MsgName == item.MsgName)
&& (ActiveMsgNames == null || ActiveMsgNames.Contains(item.MsgName)))
{
LDFParser.LDF_GetSignalValueStr(LDFHandle, new StringBuilder(item.MsgName), new StringBuilder(item.SignalName), ReadValueStr);
item.SignalRtValueSb = ReadValueStr;
@@ -960,6 +971,7 @@ namespace CapMachine.Wpf.LinDrive
try
{
IsCycleSend = false;
ActiveMsgNames = null; // 清空激活帧过滤集合
if (LDFHandle != 0)
{
LDFParser.LDF_StopSchTable(LDFHandle);