diff --git a/CapMachine.Model/CANLIN/LINConfigExd.cs b/CapMachine.Model/CANLIN/LINConfigExd.cs
index f681e0e..6120577 100644
--- a/CapMachine.Model/CANLIN/LINConfigExd.cs
+++ b/CapMachine.Model/CANLIN/LINConfigExd.cs
@@ -31,5 +31,12 @@ namespace CapMachine.Model.CANLIN
///
[Column(Name = "LdfPath", IsNullable = false, StringLength = 500)]
public string? LdfPath { get; set; }
+
+
+ ///
+ /// 调度表是否启用
+ ///
+ [Column(Name = "SchEnable")]
+ public bool SchEnable { get; set; }
}
}
diff --git a/CapMachine.Model/CANLIN/LINScheduleConfig.cs b/CapMachine.Model/CANLIN/LINScheduleConfig.cs
index 496ea73..03cfaa9 100644
--- a/CapMachine.Model/CANLIN/LINScheduleConfig.cs
+++ b/CapMachine.Model/CANLIN/LINScheduleConfig.cs
@@ -4,7 +4,7 @@ namespace CapMachine.Model.CANLIN
{
///
/// 调度表的配置
- /// 其实这些调度表是在DBC中有的,但是图莫斯的驱动没有读取到这些信息
+ /// 其实这些调度表是在LDF中有的,但是图莫斯的驱动没有读取到这些信息
/// 那么我们在系统层面进行操作和保存这些信息
///
[Table(Name = "LINScheduleConfig")]
@@ -17,11 +17,29 @@ namespace CapMachine.Model.CANLIN
public long Id { get; set; }
///
- /// 消息名称
+ /// 是否启用
+ ///
+ [Column(Name = "IsActive")]
+ public bool IsActive { get; set; }
+
+ ///
+ /// 帧/报文是否被选中(属于当前调度表内生效的帧)
+ ///
+ [Column(Name = "IsMsgActived")]
+ public bool IsMsgActived { get; set; }
+
+ ///
+ /// 消息名称/帧名称
///
[Column(Name = "MsgName")]
public string? MsgName { get; set; }
+ ///
+ /// 消息名称/帧名称的Index
+ ///
+ [Column(Name = "MsgNameIndex")]
+ public int MsgNameIndex { get; set; }
+
///
/// 消息的周期
///
@@ -40,7 +58,7 @@ namespace CapMachine.Model.CANLIN
/// LDF中可能有多个调度器名称
///
[Column(Name = "SchTabName")]
- public int SchTabName { get; set; }
+ public string? SchTabName { get; set; }
///
diff --git a/CapMachine.Wpf/App.xaml.cs b/CapMachine.Wpf/App.xaml.cs
index f9f643f..9f37b58 100644
--- a/CapMachine.Wpf/App.xaml.cs
+++ b/CapMachine.Wpf/App.xaml.cs
@@ -200,6 +200,9 @@ namespace CapMachine.Wpf
containerRegistry.RegisterDialog();
containerRegistry.RegisterDialog();
+ containerRegistry.RegisterDialog();
+ containerRegistry.RegisterDialog();
+
containerRegistry.RegisterDialog();
diff --git a/CapMachine.Wpf/Dtos/LINConfigExdDto.cs b/CapMachine.Wpf/Dtos/LINConfigExdDto.cs
index 8288ac9..57c1b19 100644
--- a/CapMachine.Wpf/Dtos/LINConfigExdDto.cs
+++ b/CapMachine.Wpf/Dtos/LINConfigExdDto.cs
@@ -43,5 +43,16 @@ namespace CapMachine.Wpf.Dtos
get { return _LdfPath; }
set { _LdfPath = value; RaisePropertyChanged(); }
}
+
+ private bool _SchEnable;
+ ///
+ /// 调度表是否启用
+ ///
+ public bool SchEnable
+ {
+ get { return _SchEnable; }
+ set { _SchEnable = value; RaisePropertyChanged(); }
+ }
+
}
}
diff --git a/CapMachine.Wpf/Dtos/LINScheduleConfigDto.cs b/CapMachine.Wpf/Dtos/LINScheduleConfigDto.cs
new file mode 100644
index 0000000..db23ee5
--- /dev/null
+++ b/CapMachine.Wpf/Dtos/LINScheduleConfigDto.cs
@@ -0,0 +1,105 @@
+using CapMachine.Model.CANLIN;
+using Prism.Mvvm;
+
+namespace CapMachine.Wpf.Dtos
+{
+ public class LINScheduleConfigDto : BindableBase
+ {
+ ///
+ /// 主键
+ ///
+ public long Id { get; set; }
+
+ private bool _IsActive;
+ ///
+ /// 是否激活
+ ///
+ public bool IsActive
+ {
+ get { return _IsActive; }
+ set { _IsActive = value; RaisePropertyChanged(); }
+ }
+
+ private bool _IsMsgActived;
+ ///
+ /// 帧/报文是否被选中(隶属某个调度表)
+ ///
+ public bool IsMsgActived
+ {
+ get { return _IsMsgActived; }
+ set { _IsMsgActived = value; RaisePropertyChanged(); }
+ }
+
+ private string? _MsgName;
+ ///
+ /// 消息名称/帧名称
+ ///
+ public string? MsgName
+ {
+ get { return _MsgName; }
+ set { _MsgName = value; RaisePropertyChanged(); }
+ }
+
+ private int _MsgNameIndex;
+ ///
+ /// 消息名称/帧名称的Index
+ ///
+ public int MsgNameIndex
+ {
+ get { return _MsgNameIndex; }
+ set { _MsgNameIndex = value; RaisePropertyChanged(); }
+ }
+
+ private int _Cycle;
+ ///
+ /// 周期
+ ///
+ public int Cycle
+ {
+ get { return _Cycle; }
+ set { _Cycle = value; RaisePropertyChanged(); }
+ }
+
+ private int _SchTabIndex;
+ ///
+ /// 调度表的Index序列
+ ///
+ public int SchTabIndex
+ {
+ get { return _SchTabIndex; }
+ set { _SchTabIndex = value; RaisePropertyChanged(); }
+ }
+
+ private string? _SchTabName;
+ ///
+ /// 调度表的名称
+ ///
+ public string? SchTabName
+ {
+ get { return _SchTabName; }
+ set { _SchTabName = value; RaisePropertyChanged(); }
+ }
+
+ /////
+ ///// 在更新调度表数据时,我们有一个整体的帧数据指令集合,但是这些帧数据集合,分属于不同的调度表,
+ ///// 这个在开始时生成整体的帧数据指令集合才会把这个MsgIndex分配上,这个不需要保存到数据库中,对接使用
+ /////
+ //public int MsgIndex { get; set; }
+
+ ///
+ /// 程序的ID
+ ///
+ public long CanLinConfigProId { get; set; }
+
+
+ private CanLinConfigPro _CanLinConfigPro;
+ ///
+ /// 所属的程序
+ ///
+ public CanLinConfigPro CanLinConfigPro
+ {
+ get { return _CanLinConfigPro; }
+ set { _CanLinConfigPro = value; RaisePropertyChanged(); }
+ }
+ }
+}
diff --git a/CapMachine.Wpf/LinDrive/LDFParser.cs b/CapMachine.Wpf/LinDrive/LDFParser.cs
index 3334e7f..ae1f214 100644
--- a/CapMachine.Wpf/LinDrive/LDFParser.cs
+++ b/CapMachine.Wpf/LinDrive/LDFParser.cs
@@ -69,5 +69,16 @@ namespace CapMachine.Wpf.LinDrive
public static extern Int32 LDF_ExeFrameToBus(UInt64 LDFHandle, StringBuilder pFrameName, byte FillBitValue);
[DllImport("USB2XXX.dll")]
public static extern Int32 LDF_ExeSchToBus(UInt64 LDFHandle, StringBuilder pSchName, byte FillBitValue);
+
+ [DllImport("USB2XXX.dll")]
+ public static extern Int32 LDF_SetSchToTable(UInt64 LDFHandle, StringBuilder pSchName, byte FillBitValue);
+ [DllImport("USB2XXX.dll")]
+ public static extern Int32 LDF_GetRawMsg(UInt64 LDFHandle, IntPtr pLINMsg, int BufferSize);
+ [DllImport("USB2XXX.dll")]
+ public static extern Int32 LDF_SyncMsgToValue(UInt64 LDFHandle, USB2LIN_EX.LIN_EX_MSG[] pLINMsg, int MsgLen);
+ [DllImport("USB2XXX.dll")]
+ public static extern Int32 LDF_StopSchTable(UInt64 LDFHandle);
+ [DllImport("USB2XXX.dll")]
+ public static extern Int32 LDF_Release(UInt64 LDFHandle);
}
}
diff --git a/CapMachine.Wpf/LinDrive/LinCmdData.cs b/CapMachine.Wpf/LinDrive/LinCmdData.cs
index 8a37f98..77ba84c 100644
--- a/CapMachine.Wpf/LinDrive/LinCmdData.cs
+++ b/CapMachine.Wpf/LinDrive/LinCmdData.cs
@@ -1,4 +1,5 @@
-using System;
+using CapMachine.Wpf.Dtos;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -26,10 +27,40 @@ namespace CapMachine.Wpf.LinDrive
///
public string? SignalName { get; set; }
+ ///
+ /// 指令数据改变Handler
+ /// 改变发送消息名称/帧名称
+ ///
+ public event EventHandler? LinCmdDataChangedHandler;
+
+ private double _SignalCmdValue;
///
/// 指令值
/// 没有的话,则给默认值
///
- public double SignalCmdValue { get; set; }
+ public double SignalCmdValue
+ {
+ get { return _SignalCmdValue; }
+ set
+ {
+ if (_SignalCmdValue != value)
+ {
+ _SignalCmdValue = value;
+ LinCmdDataChangedHandler?.Invoke(this, MsgName!);
+ }
+ }
+ }
+
+ /////
+ ///// 逻辑规则Id
+ /////
+ //public long LogicRuleId { get; set; }
+
+ ///
+ /// CanLinConfig的逻辑转换规则
+ /// 比如:速度下发的数据SV是4000,但是下发到CAN的值是40,可能是其他的逻辑转换规则,这里就是保存其中的逻辑规则
+ ///
+ public LogicRuleDto? LogicRuleDto { get; set; }
+
}
}
diff --git a/CapMachine.Wpf/LinDrive/LinLdfModel.cs b/CapMachine.Wpf/LinDrive/LinLdfModel.cs
index 9ec3e57..09876d3 100644
--- a/CapMachine.Wpf/LinDrive/LinLdfModel.cs
+++ b/CapMachine.Wpf/LinDrive/LinLdfModel.cs
@@ -62,7 +62,7 @@ namespace CapMachine.Wpf.LinDrive
}
}
- private StringBuilder _SignalRtValueSb = new StringBuilder(10);
+ private StringBuilder _SignalRtValueSb = new StringBuilder(16);
///
/// 信号实时值 StringBuilder
///
@@ -71,12 +71,24 @@ namespace CapMachine.Wpf.LinDrive
get { return _SignalRtValueSb; }
set
{
- //if (_SignalRtValueSb != value)
- //{
- SignalRtValue = value.ToString();
- _SignalRtValueSb = value;
- //}
+ if (value == null)
+ {
+ if (_SignalRtValue != string.Empty)
+ {
+ _SignalRtValueSb.Clear();
+ SignalRtValue = string.Empty;
+ }
+ return;
+ }
+ // 复制内容到内部可变缓冲区,避免多个模型共享同一个 StringBuilder 实例
+ var str = value.ToString();
+ if (!string.Equals(_SignalRtValue, str, StringComparison.Ordinal))
+ {
+ _SignalRtValueSb.Clear();
+ _SignalRtValueSb.Append(str);
+ SignalRtValue = str;
+ }
}
}
diff --git a/CapMachine.Wpf/LinDrive/ToomossLin.cs b/CapMachine.Wpf/LinDrive/ToomossLin.cs
index c5c1368..a058c4c 100644
--- a/CapMachine.Wpf/LinDrive/ToomossLin.cs
+++ b/CapMachine.Wpf/LinDrive/ToomossLin.cs
@@ -1,4 +1,6 @@
-using CapMachine.Wpf.CanDrive;
+using CapMachine.Model.CANLIN;
+using CapMachine.Wpf.CanDrive;
+using CapMachine.Wpf.Dtos;
using CapMachine.Wpf.Services;
using ImTools;
using Microsoft.VisualBasic;
@@ -26,16 +28,19 @@ namespace CapMachine.Wpf.LinDrive
/// 设备Handles集合
///
public Int32[] DevHandles { get; set; } = new Int32[20];
+
///
/// 设备Handles
/// 设备句柄,本质为设备序号的低4字节,可以通过调用USB_ScanDevice函数获得
///
public Int32 DevHandle { get; set; } = 0;
+
///
/// Lin的Index
/// LIN通道索引号,填0或者1,若只有一个通道LIN,则填0.
///
public Byte LINIndex { get; set; } = 0;
+
///
/// Lin的连接State
///
@@ -55,22 +60,59 @@ namespace CapMachine.Wpf.LinDrive
{
ContainerProvider = containerProvider;
HighSpeedDataService = ContainerProvider.Resolve();
+ LoggerService = ContainerProvider.Resolve();
+
//Stopwatch.Frequency表示高精度计时器每秒的计数次数(ticks/秒)每毫秒的ticks数 = 每秒的ticks数 ÷ 1000
TicksPerMs = Stopwatch.Frequency / 1000.0;
}
+ ///
+ /// Logger 实例
+ ///
+ public ILogService LoggerService { get; set; }
+
///
/// HighSpeedDataService 实例
///
public HighSpeedDataService HighSpeedDataService { get; set; }
+ ///
+ /// 接收优化上下文:缓存帧与信号的 StringBuilder,避免循环中重复分配
+ ///
+ private class SignalReadCtx
+ {
+ public string SignalName { get; set; }
+ public StringBuilder SignalNameSB { get; set; }
+ public LinLdfModel ModelRef { get; set; }
+ }
+
+ private class FrameReadCtx
+ {
+ public string MsgName { get; set; }
+ public StringBuilder MsgNameSB { get; set; }
+ public bool IsMasterFrame { get; set; }
+ public List Signals { get; set; } = new List();
+ }
+
+ private List RecvFrameCtxs = new List();
+
+ // 接收缓冲池(重用,避免每轮分配)
+ private IntPtr RecvMsgBufferPtr = IntPtr.Zero;
+ private int RecvMsgBufferCapacity = 1024;
+ private readonly int LinMsgSize = Marshal.SizeOf(typeof(USB2LIN_EX.LIN_EX_MSG));
+ // 控制台调试输出开关(默认关闭,防止日志风暴)
+ public bool EnableConsoleDebugLog { get; set; } = false;
+ // 保护接收缓冲的并发锁(接收读与关闭释放之间的互斥)
+ private readonly object RecvBufferSync = new object();
+
///
/// 开始LDF文件写入
///
public ObservableCollection StartLdf(string LdfPath)
{
LDF_Parser(LdfPath);
+ BuildRecvFrameCtxs();
return ListLinLdfModel;
}
@@ -152,6 +194,17 @@ namespace CapMachine.Wpf.LinDrive
///
public UInt64 LDFHandle { get; set; }
+ ///
+ /// LIN波特率(从LDF读取)
+ ///
+ public int LINBaudRate { get; private set; }
+
+ ///
+ /// 当前正在适配器中运行的调度表名称(用于增量刷新)
+ /// 同一个时刻只能运行一个调度表
+ ///
+ public string ActiveSchName { get; private set; }
+
///
/// LDF消息集合
/// 包括读取的实时值和数据
@@ -163,6 +216,36 @@ namespace CapMachine.Wpf.LinDrive
///
public List CmdData { get; set; } = new List();
+ ///
+ /// 加载要发送的数据(订阅数据变化事件)
+ /// 一般是激活后才注册事件
+ ///
+ ///
+ public void LoadCmdDataToDrive(List cmdData)
+ {
+ // 取消订阅旧数据源事件
+ if (CmdData != null && CmdData.Count > 0)
+ {
+ foreach (var cmd in CmdData)
+ {
+ cmd.LinCmdDataChangedHandler -= CmdData_LinCmdDataChangedHandler;
+ }
+ }
+
+ // 设置新数据源并订阅事件
+ CmdData = cmdData ?? new List();
+ foreach (var cmd in CmdData)
+ {
+ cmd.LinCmdDataChangedHandler += CmdData_LinCmdDataChangedHandler;
+ }
+ }
+
+ ///
+ /// 当前激活调度表下,启用的帧/报文名称集合(来自 ListLINScheduleConfig 的 IsMsgActived)。
+ /// 为空(null) 表示不过滤,使用所有 CmdData 中的帧;非空则仅对包含在集合内的帧做信号更新与下发。
+ ///
+ private HashSet? ActiveMsgNames;
+
///
/// ******************【1】*********************
/// 是否存在Dll文件
@@ -240,7 +323,23 @@ namespace CapMachine.Wpf.LinDrive
//读取LDF文件信息
Console.WriteLine("ProtocolVersion = {0}", LDFParser.LDF_GetProtocolVersion(LDFHandle));
- Console.WriteLine("LINSpeed = {0}", LDFParser.LDF_GetLINSpeed(LDFHandle));
+ LINBaudRate = LDFParser.LDF_GetLINSpeed(LDFHandle);
+ Console.WriteLine("LINSpeed = {0}", LINBaudRate);
+
+ // 使用LDF中的波特率初始化LIN通道(主机模式)
+ var initRet = USB2LIN_EX.LIN_EX_Init(DevHandle, LINIndex, LINBaudRate, USB2LIN_EX.LIN_EX_MASTER);
+ if (initRet < USB2LIN_EX.LIN_EX_SUCCESS)
+ {
+ Console.WriteLine("LIN通道初始化失败!");
+ LdfParserState = false;
+ return;
+ }
+ else
+ {
+ Console.WriteLine("LIN通道初始化成功");
+ // 可选:开启适配器供电以驱动从节点(若硬件支持)
+ try { USB2LIN_EX.LIN_EX_CtrlPowerOut(DevHandle, LINIndex, 1); } catch { }
+ }
//读取主机名称
StringBuilder MasterName = new StringBuilder(64);
@@ -292,10 +391,49 @@ namespace CapMachine.Wpf.LinDrive
}
}
+ // 构建接收优化上下文,避免每次循环 GroupBy 与临时对象分配
+ BuildRecvFrameCtxs();
+
//解析成功
LdfParserState = true;
}
+ ///
+ /// 构建接收优化上下文
+ ///
+ private void BuildRecvFrameCtxs()
+ {
+ if (ListLinLdfModel == null || ListLinLdfModel.Count == 0)
+ {
+ RecvFrameCtxs = new List();
+ return;
+ }
+
+ var grouped = ListLinLdfModel.GroupBy(x => x.MsgName);
+ var list = new List();
+ foreach (var g in grouped)
+ {
+ var first = g.First();
+ var frame = new FrameReadCtx
+ {
+ MsgName = g.Key,
+ MsgNameSB = new StringBuilder(g.Key),
+ IsMasterFrame = (first.IsMasterFrame != null && first.IsMasterFrame.Contains("是"))
+ };
+ foreach (var model in g)
+ {
+ frame.Signals.Add(new SignalReadCtx
+ {
+ SignalName = model.SignalName,
+ SignalNameSB = new StringBuilder(model.SignalName),
+ ModelRef = model
+ });
+ }
+ list.Add(frame);
+ }
+ RecvFrameCtxs = list;
+ }
+
///
/// 发送LIN数据
@@ -343,42 +481,79 @@ namespace CapMachine.Wpf.LinDrive
await Task.Delay(ReviceCycle);
try
{
- var GroupMsg = ListLinLdfModel.GroupBy(x => x.MsgName);
- foreach (var itemMsg in GroupMsg)
+ var frames = RecvFrameCtxs;
+ if (frames == null || frames.Count == 0)
{
- var data = itemMsg.FirstOrDefault();
- //非主机发送的指令帧就可以读取数据,因为函数 LDF_ExeFrameToBus【执行帧到总线,若该帧的发布者是主机,那么就是主机写数据,否则就是主机读数据】
- //那么主机发送和读取都是同一个函数。会导致跟Master主机也会在这里执行写入,导致冲突,出现错误。所以做一个排出
- if (data != null && !data.IsMasterFrame!.Contains("是"))
+ IsReviceOk = true;
+ continue;
+ }
+
+ foreach (var frame in frames)
+ {
+ // 仅对从机发布的帧执行读取
+ if (frame.IsMasterFrame)
+ continue;
+
+ // 主机读操作,读取从机返回的数据值
+ LDFParser.LDF_ExeFrameToBus(LDFHandle, frame.MsgNameSB, 1);
+ foreach (var sig in frame.Signals)
{
- //主机读操作,读取从机返回的数据值
- LDFParser.LDF_ExeFrameToBus(LDFHandle, new StringBuilder(itemMsg.Key), 1);
- foreach (var itemSignal in itemMsg)
+ LDFParser.LDF_GetSignalValueStr(LDFHandle, frame.MsgNameSB, sig.SignalNameSB, ReadValueStr);
+ sig.ModelRef.SignalRtValueSb = ReadValueStr;
+ }
+ }
+
+ // 从适配器读取原始LIN报文,并写入高速记录服务
+ lock (RecvBufferSync)
+ {
+ if (RecvMsgBufferPtr == IntPtr.Zero)
+ {
+ RecvMsgBufferPtr = Marshal.AllocHGlobal(LinMsgSize * RecvMsgBufferCapacity);
+ if (EnableConsoleDebugLog) LoggerService?.Info("申请 LIN RecvMsgBufferPtr");
+ }
+ var msgPtRead = RecvMsgBufferPtr;
+ int linNum = LDFParser.LDF_GetRawMsg(LDFHandle, msgPtRead, RecvMsgBufferCapacity);
+ if (linNum > 0)
+ {
+ for (int i = 0; i < linNum; i++)
{
- //LDFParser.LDF_ExeFrameToBus(LDFHandle, new StringBuilder(itemMsg.Key), 1);
- LDFParser.LDF_GetSignalValueStr(LDFHandle, new StringBuilder(itemMsg.Key), new StringBuilder(itemSignal.SignalName), ReadValueStr);
- itemSignal.SignalRtValueSb = ReadValueStr;
+ var msgPtr = (IntPtr)(msgPtRead + i * LinMsgSize);
+ var linMsg = (USB2LIN_EX.LIN_EX_MSG)Marshal.PtrToStructure(msgPtr, typeof(USB2LIN_EX.LIN_EX_MSG));
+ // 仅使用有效数据长度
+ int dataLen = linMsg.DataLen <= 0 ? 0 : Math.Min(linMsg.Data?.Length ?? 0, linMsg.DataLen);
+ string dataHex = dataLen > 0 ? BitConverter.ToString(linMsg.Data, 0, dataLen) : string.Empty;
+ if (EnableConsoleDebugLog)
+ {
+ Console.WriteLine($"LINMsg[{i}] PID=0x{linMsg.PID:X2} Type={linMsg.MsgType} CheckType={linMsg.CheckType} DataLen={linMsg.DataLen} Data={dataHex}");
+ }
+
+ // 推送到高速数据记录服务
+ HighSpeedDataService.AppendOrUpdateMsg(new Models.HighSpeed.CommMsg()
+ {
+ Category = "LIN",
+ MsgInfo = "0x" + linMsg.PID.ToString("X2"),
+ MsgData = dataHex,
+ Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
+ });
+
}
}
-
+ else if (linNum < 0 && EnableConsoleDebugLog)
+ {
+ Console.WriteLine("Get LIN raw data error!");
+ }
}
- //StringBuilder ValueStr = new StringBuilder(64);
- //LDFParser.LDF_ExeFrameToBus(LDFHandle, new StringBuilder("ID_DATA"), 1);
- //LDFParser.LDF_GetSignalValueStr(LDFHandle, new StringBuilder("ID_DATA"), new StringBuilder("Supplier_ID"), ValueStr);
- //Console.WriteLine("ID_DATA.Supplier_ID={0}", ValueStr);
- //LDFParser.LDF_GetSignalValueStr(LDFHandle, new StringBuilder("ID_DATA"), new StringBuilder("Machine_ID"), ValueStr);
- //Console.WriteLine("ID_DATA.Machine_ID={0}", ValueStr);
- //LDFParser.LDF_GetSignalValueStr(LDFHandle, new StringBuilder("ID_DATA"), new StringBuilder("Chip_ID"), ValueStr);
- //Console.WriteLine("ID_DATA.Chip_ID={0}", ValueStr);
-
+ IsReviceOk = true;
}
catch (Exception ex)
{
- //LogService.Info($"时间:{DateTime.Now.ToString()}-【Meter】-{ex.Message}");
+ IsReviceOk = false;
+ LoggerService.Info($"{ex.Message}");
}
}
+ IsReviceOk = false;
});
}
@@ -454,6 +629,23 @@ namespace CapMachine.Wpf.LinDrive
}
+ private bool _IsReviceOk;
+ ///
+ /// 接收报文是否OK
+ ///
+ public bool IsReviceOk
+ {
+ get { return _IsReviceOk; }
+ set
+ {
+ if (_IsReviceOk != value)
+ {
+ RaisePropertyChanged();
+ _IsReviceOk = value;
+ }
+ }
+ }
+
#region 精确发送报文数据
@@ -543,6 +735,8 @@ namespace CapMachine.Wpf.LinDrive
// 严重延迟,重新校准
NextExecutionTime = Stopwatcher.ElapsedTicks;
Console.WriteLine("定时发送延迟过大,重新校准时间");
+
+ LoggerService.Info("定时发送延迟过大,重新校准时间");
}
// 使用Stopwatch记录实际的执行间隔,而不是DateTime
@@ -551,7 +745,6 @@ namespace CapMachine.Wpf.LinDrive
//Console.WriteLine($"--当前时间(毫秒): {DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}");
-
// 执行发送CAN逻辑
{
@@ -578,33 +771,39 @@ namespace CapMachine.Wpf.LinDrive
}
}
-
+ IsSendOk = true;
}
}
catch (TaskCanceledException)
{
+ IsSendOk = false;
// 任务被取消,正常退出
break;
}
catch (Exception ex)
{
+ IsSendOk = false;
Console.WriteLine($"LIN周期发送异常: {ex.Message}");
// 短暂暂停避免异常情况下CPU占用过高
await Task.Delay(10, token);
}
}
+
+ IsSendOk = false;
}
catch (Exception ex)
{
+ IsSendOk = false;
// 确保在任何情况下(正常退出、异常、取消)都会停止计时器
Stopwatcher.Stop();
-
+ LoggerService.Info("接收出现异常");
// 清理其他可能的资源
Console.WriteLine("LIN周期发送任务已结束,资源已清理");
}
finally
{
+ IsSendOk = false;
// 确保在任何情况下(正常退出、异常、取消)都会停止计时器
Stopwatcher.Stop();
}
@@ -625,6 +824,372 @@ namespace CapMachine.Wpf.LinDrive
#endregion
+ #region 调度器发送报文
+
+ ///
+ /// 指令数据变化时,更新调度表的线程锁
+ ///
+ private readonly object SchUpdateLock = new object();
+
+ private bool _SchEnable;
+ ///
+ /// 调度表使能
+ ///
+ public bool SchEnable
+ {
+ get { return _SchEnable; }
+ set
+ {
+ _SchEnable = value;
+ RaisePropertyChanged();
+ }
+ }
+
+ ///
+ /// 定时扫描更新数据 扫描Task
+ ///
+ private static Task CycleUpdateCmdTask { get; set; }
+
+ ///
+ /// 定时更新时间
+ /// 定时更新调度表的周期
+ ///
+ private int UpdateCycle { get; set; } = 5000;
+
+ ///
+ /// 调度表数量
+ ///
+ public int SchCount { get; set; }
+
+ ///
+ /// LIN 调度表的配置信息
+ ///
+ public List ListLINScheduleConfig { get; set; }
+
+ ///
+ /// 获取LIN的LINScheduleConfig
+ ///
+ ///
+ public List GetLINScheduleConfigs()
+ {
+ List LINScheduleConfigs = new List();
+ SchCount = GetSchCount();
+ for (int i = 0; i < SchCount; i++)
+ {
+ var SchName = GetSchName(i);
+ var FrameCount = GetSchFrameCount(SchName);
+ for (int j = 0; j < FrameCount; j++)
+ {
+ LINScheduleConfigs.Add(new LINScheduleConfig()
+ {
+ SchTabName = GetSchName(i),
+ SchTabIndex = i,
+ MsgName = GetSchFrameName(SchName, j),
+ MsgNameIndex = j,
+ Cycle = 100,
+ IsActive = false,
+ });
+ }
+ }
+ return LINScheduleConfigs;
+ }
+
+ ///
+ /// 获取调度的帧的信号个数
+ /// 消息/报文的个数
+ /// 一个调度表包含多个帧/消息/报文
+ ///
+ ///
+ public int GetSchFrameCount(string SchName)
+ {
+ return LDFParser.LDF_GetSchFrameQuantity(LDFHandle, new StringBuilder(SchName));
+ }
+
+ ///
+ /// 获取调度的帧的名称
+ ///
+ ///
+ public string GetSchFrameName(string SchName, int FrameIndex)
+ {
+ StringBuilder FrameName = new StringBuilder();
+ LDFParser.LDF_GetSchFrameName(LDFHandle, new StringBuilder(SchName), FrameIndex, FrameName);
+ return FrameName.ToString();
+ }
+
+ ///
+ /// 获取调度表数量
+ ///
+ ///
+ public int GetSchCount()
+ {
+ SchCount = LDFParser.LDF_GetSchQuantity(LDFHandle);
+ return SchCount;
+ }
+
+ ///
+ /// 获取调度表数量
+ ///
+ ///
+ public string GetSchName(int index)
+ {
+ StringBuilder pSchName = new StringBuilder();
+ var SchResult = LDFParser.LDF_GetSchName(LDFHandle, index, pSchName);
+ return pSchName.ToString();
+ }
+
+ Random Random = new Random();
+
+ ///
+ /// 开始调度表执行
+ /// 同一个时刻只能运行一个调度表,如果有多个调度表,只能选择一个运行,
+ /// ********** 如果控制指令分布在不同的调度表中,需要更改LDF文件的配置,把控制的报文放在同一个调度表中 **********
+ ///
+ public void StartSchedule()
+ {
+ if (LDFHandle == 0)
+ return;
+
+ // 1) 将要执行的调度表烧入适配器并自动运行(若不指定,则启动全部调度表)
+ // 优先使用 ListLINScheduleConfig 指定的调度表名;否则默认取第一个
+ string selectedSch = string.Empty;
+ if (ListLINScheduleConfig != null && ListLINScheduleConfig.Count > 0)
+ {
+ selectedSch = ListLINScheduleConfig.FirstOrDefault(a => a.IsActive && !string.IsNullOrEmpty(a.SchTabName))?.SchTabName
+ ?? ListLINScheduleConfig.FirstOrDefault(a => !string.IsNullOrEmpty(a.SchTabName))?.SchTabName;
+ }
+
+ if (string.IsNullOrEmpty(selectedSch))
+ {
+ // 回退为索引0的调度表
+ if (GetSchCount() > 0)
+ {
+ selectedSch = GetSchName(0);
+ LoggerService?.Info($"未指定调度表,默认启动调度表[{selectedSch}],注意当前调度表可能需要的调度表");
+ }
+ }
+
+ //当前激活的调度表
+ 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(actives) : new HashSet();
+ }
+ 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)
+ {
+ LoggerService?.Info($"启动调度表[{ActiveSchName}]失败, 返回:{ret}");
+ }
+ else
+ {
+ Console.WriteLine($"调度表[{ActiveSchName}]已启动(自动执行)");
+ LoggerService?.Info($"调度表[{ActiveSchName}]已启动(自动执行)");
+ }
+
+ // 4) 置位调度更新开关(事件驱动刷新,不再自动启动周期刷新任务)
+ //SchEnable = true;
+ // 不再自动启动周期更新任务,改为数据变化事件驱动刷新
+ // if (CycleUpdateCmdTask == null || CycleUpdateCmdTask.IsCompleted) { StartCycleUpdateCmd(); }
+ }
+
+
+ ///
+ /// 循环更新调度表的指令数据
+ /// 定时更新数据到调度表中
+ /// 被数值更新事件驱动的方法取代了
+ ///
+ public void StartCycleUpdateCmd()
+ {
+ CycleUpdateCmdTask = Task.Run(async () =>
+ {
+ while (IsCycleSend)
+ {
+ await Task.Delay(UpdateCycle);
+ try
+ {
+
+ if (CmdData.Count() == 0) return;
+
+ //防止有多个不同的消息名称/帧,每个帧单独处理发送
+ 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("速"))
+ {
+ itemSignal.SignalCmdValue = 1250 + Random.NextDouble() * 1000;
+ }
+ //主机写操作,发送数据给从机
+ LDFParser.LDF_SetSignalValue(LDFHandle, new StringBuilder(itemMsg.Key), new StringBuilder(itemSignal.SignalName), itemSignal.SignalCmdValue);
+ }
+
+ ////【0】参数注意
+ //LDFParser.LDF_ExeFrameToBus(LDFHandle, new StringBuilder(itemMsg.Key), 0);
+
+ //读取当前的指令帧数据,LDF_ExeFrameToBus执行后就可以读取本身的数据
+ foreach (var item in ListLinLdfModel)
+ {
+ 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;
+ }
+ }
+
+ // 调度表已在适配器中自动执行,这里仅更新信号值即可
+ }
+
+ // 将更新后的信号值下发到适配器的自动调度表(刷新离线表的数据)
+ if (!string.IsNullOrEmpty(ActiveSchName))
+ {
+ var retPush = LDFParser.LDF_SetSchToTable(LDFHandle, new StringBuilder(ActiveSchName), 0);
+ if (retPush < 0)
+ {
+ LoggerService?.Info($"刷新调度表[{ActiveSchName}]失败, 返回:{retPush}");
+ }
+ }
+
+ IsSendOk = true;
+ }
+ catch (Exception ex)
+ {
+ IsSendOk = false;
+ LoggerService.Info($"时间:{DateTime.Now.ToString()}-【MSG】-{ex.Message}");
+ }
+ }
+
+ IsSendOk = false;
+ });
+ }
+
+ ///
+ /// 指令数据发生变化事件回调
+ ///
+ ///
+ /// 消息/帧名称
+ private void CmdData_LinCmdDataChangedHandler(object? sender, string e)
+ {
+ UpdateSchDataByCmdDataChanged(e);
+ }
+
+ ///
+ /// 指令数据变化时,按消息名增量刷新调度表数据
+ ///
+ /// 发生变化的帧名称
+ private void UpdateSchDataByCmdDataChanged(string changedMsgName)
+ {
+ try
+ {
+ // 与CAN保持一致:仅在循环发送开启且调度表使能时才更新
+ if (!IsCycleSend) return;
+ if (!SchEnable) return;
+
+ // 基础防御
+ if (LDFHandle == 0) return;
+ if (string.IsNullOrEmpty(ActiveSchName)) return;
+ if (string.IsNullOrEmpty(changedMsgName)) return;
+
+ // 若配置了激活帧过滤,则不在集合内的帧不更新
+ if (ActiveMsgNames != null && ActiveMsgNames.Count > 0 && !ActiveMsgNames.Contains(changedMsgName))
+ return;
+
+ lock (SchUpdateLock)
+ {
+ // 仅更新对应消息/帧的信号值
+ var relatedCmds = CmdData.Where(x => string.Equals(x.MsgName, changedMsgName, StringComparison.Ordinal));
+ foreach (var cmd in relatedCmds)
+ {
+ LDFParser.LDF_SetSignalValue(LDFHandle, new StringBuilder(changedMsgName), new StringBuilder(cmd.SignalName), cmd.SignalCmdValue);
+ }
+
+ //读取当前的指令帧数据,执行后就可以读取本身的数据
+ foreach (var item in ListLinLdfModel)
+ {
+ if (CmdData.Any(a => a.MsgName == item.MsgName))
+ {
+ LDFParser.LDF_GetSignalValueStr(LDFHandle, new StringBuilder(item.MsgName), new StringBuilder(item.SignalName), ReadValueStr);
+ item.SignalRtValueSb = ReadValueStr;
+ }
+ }
+
+ // 将更新后的信号值推送到适配器当前运行的调度表(离线表刷新)
+ var retPush = LDFParser.LDF_SetSchToTable(LDFHandle, new StringBuilder(ActiveSchName), 0);
+ if (retPush < 0)
+ {
+ IsSendOk = false;
+ LoggerService?.Info($"刷新调度表[{ActiveSchName}]失败, 返回:{retPush}");
+ }
+ else
+ {
+ IsSendOk = true;
+ //Console.WriteLine($"Update LIN Schedule Success -- Sch:[{ActiveSchName}] Msg:[{changedMsgName}]");
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ IsSendOk = false;
+ LoggerService?.Info($"时间:{DateTime.Now.ToString()}-【LIN_SCH】-{ex.Message}");
+ }
+ }
+
+ ///
+ /// 停止调度表自动执行
+ ///
+ public void StopSchedule()
+ {
+ try
+ {
+ IsCycleSend = false;
+ SchEnable = false;
+ ActiveMsgNames = null; // 清空激活帧过滤集合
+ if (LDFHandle != 0)
+ {
+ LDFParser.LDF_StopSchTable(LDFHandle);
+ }
+ }
+ catch (Exception ex)
+ {
+ LoggerService?.Info($"停止调度表异常: {ex.Message}");
+ }
+ }
+
+
+ #endregion
///
/// 关闭设备
@@ -632,6 +1197,27 @@ namespace CapMachine.Wpf.LinDrive
public void CloseDevice()
{
//关闭设备
+ try
+ {
+ // 停止调度并释放LDF资源
+ if (LDFHandle != 0)
+ {
+ try { LDFParser.LDF_StopSchTable(LDFHandle); } catch { }
+ try { LDFParser.LDF_Release(LDFHandle); } catch { }
+ LDFHandle = 0;
+ }
+ // 释放接收缓冲区
+ lock (RecvBufferSync)
+ {
+ if (RecvMsgBufferPtr != IntPtr.Zero)
+ {
+ try { Marshal.FreeHGlobal(RecvMsgBufferPtr); }
+ catch { }
+ finally { RecvMsgBufferPtr = IntPtr.Zero; }
+ }
+ }
+ }
+ catch { }
USB_DEVICE.USB_CloseDevice(DevHandle);
OpenState = false;
LdfParserState = false;
diff --git a/CapMachine.Wpf/LinDrive/USB2LIN_EX.cs b/CapMachine.Wpf/LinDrive/USB2LIN_EX.cs
index 73bea4a..dbcc0b7 100644
--- a/CapMachine.Wpf/LinDrive/USB2LIN_EX.cs
+++ b/CapMachine.Wpf/LinDrive/USB2LIN_EX.cs
@@ -1,9 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading.Tasks;
+using System.Runtime.InteropServices;
namespace CapMachine.Wpf.LinDrive
{
@@ -95,7 +90,12 @@ namespace CapMachine.Wpf.LinDrive
public static extern Int32 LIN_EX_MasterStopSch(Int32 DevHandle, Byte LINIndex);
[DllImport("USB2XXX.dll")]
public static extern Int32 LIN_EX_MasterGetSch(Int32 DevHandle, Byte LINIndex, IntPtr pLINMsg);
-
+ [DllImport("USB2XXX.dll")]
+ public static extern Int32 LIN_EX_MasterSetSchRunTimes(Int32 DevHandle, Byte LINIndex, UInt32 RunTimes);
+ [DllImport("USB2XXX.dll")]
+ public static extern Int64 LIN_EX_GetStartTime(Int32 DevHandle, Byte LINIndex);
+ [DllImport("USB2XXX.dll")]
+ public static extern Int32 LIN_EX_ResetStartTime(Int32 DevHandle, Byte LINIndex);
[DllImport("USB2XXX.dll")]
public static extern Int32 LIN_EX_MasterOfflineSch(Int32 DevHandle, Byte LINIndex, Int32 BaudRate, LIN_EX_MSG[] pLINMsg, Int32 MsgLen);
[DllImport("USB2XXX.dll")]
diff --git a/CapMachine.Wpf/Services/LinDriveService.cs b/CapMachine.Wpf/Services/LinDriveService.cs
index bd4c4f9..100e36c 100644
--- a/CapMachine.Wpf/Services/LinDriveService.cs
+++ b/CapMachine.Wpf/Services/LinDriveService.cs
@@ -1,15 +1,10 @@
using CapMachine.Model.CANLIN;
-using CapMachine.Wpf.CanDrive;
+using CapMachine.Wpf.Dtos;
using CapMachine.Wpf.LinDrive;
using ImTools;
using Prism.Ioc;
using Prism.Mvvm;
-using System;
-using System.Collections.Generic;
using System.Collections.ObjectModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace CapMachine.Wpf.Services
{
@@ -20,15 +15,19 @@ namespace CapMachine.Wpf.Services
{
public HighSpeedDataService HighSpeedDataService { get; }
+ public LogicRuleService LogicRuleService { get; }
+
///
/// 实例化函数
///
- public LinDriveService(HighSpeedDataService highSpeedDataService, IContainerProvider containerProvider)
+ public LinDriveService(HighSpeedDataService highSpeedDataService, IContainerProvider containerProvider, LogicRuleService logicRuleService)
{
ToomossLinDrive = new ToomossLin(containerProvider);
//高速数据服务
HighSpeedDataService = highSpeedDataService;
+ LogicRuleService = logicRuleService;
+
//ToomossLinDrive.StartLinDrive();
}
@@ -123,6 +122,11 @@ namespace CapMachine.Wpf.Services
///
public List CmdData { get; set; } = new List();
+ ///
+ /// 调度表LIN配置信息
+ ///
+ public List ListLINScheduleConfig { get; set; } = new List();
+
///
/// 增加发送的指令数据
///
@@ -171,16 +175,32 @@ namespace CapMachine.Wpf.Services
///
public void UpdateSpeedCmdData(double SpeedData)
{
+ //if (SpeedLinCmdData != null)
+ //{
+ // SpeedLinCmdData.SignalCmdValue = SpeedData;
+ //}
+
if (SpeedLinCmdData != null)
{
- SpeedLinCmdData.SignalCmdValue = SpeedData;
- }
- //if (EnableLinCmdData != null)
- //{
- // EnableLinCmdData.SignalCmdValue = 1;
- //}
- }
+ //首先是否判断是有斜率
+ if (SpeedLinCmdData.LogicRuleDto == null)
+ {
+ //没有启动逻辑规则处理
+ SpeedLinCmdData.SignalCmdValue = SpeedData;
+ }
+ else
+ {
+ //LogicRuleService.ApplyExpressionFast(SpeedData, SpeedCanCmdData.LogicRuleDto);
+ SpeedLinCmdData.SignalCmdValue = LogicRuleService.ApplyExpressionFast(SpeedData, SpeedLinCmdData.LogicRuleDto);
+ //Console.WriteLine($"实时转换后转速值:{SpeedCanCmdData.SignalCmdValue}-SV值:{SpeedData}");
+ }
+ //if (EnableLinCmdData != null)
+ //{
+ // EnableLinCmdData.SignalCmdValue = 1;
+ //}
+ }
+ }
///
/// 更新压缩机使能数据
@@ -225,9 +245,25 @@ namespace CapMachine.Wpf.Services
///
public void UpdateCapPTCPwCmdData(double PTCPw)
{
+ //if (PTCPwCanCmdData != null)
+ //{
+ // PTCPwCanCmdData.SignalCmdValue = PTCPw;
+ //}
+
if (PTCPwCanCmdData != null)
{
- PTCPwCanCmdData.SignalCmdValue = PTCPw;
+ //首先是否判断是有斜率
+ if (PTCPwCanCmdData.LogicRuleDto == null)
+ {
+ //没有启动逻辑规则处理
+ PTCPwCanCmdData.SignalCmdValue = PTCPw;
+ }
+ else
+ {
+ //LogicRuleService.ApplyExpressionFast(SpeedData, SpeedCanCmdData.LogicRuleDto);
+ PTCPwCanCmdData.SignalCmdValue = LogicRuleService.ApplyExpressionFast(PTCPw, PTCPwCanCmdData.LogicRuleDto);
+ //Console.WriteLine($"实时转换后转速值:{SpeedCanCmdData.SignalCmdValue}-SV值:{SpeedData}");
+ }
}
}
@@ -237,10 +273,27 @@ namespace CapMachine.Wpf.Services
///
public void UpdateCapPTCFlowCmdData(double Flow)
{
+ //if (PTCFlowCanCmdData != null)
+ //{
+ // PTCFlowCanCmdData.SignalCmdValue = Flow;
+ //}
+
if (PTCFlowCanCmdData != null)
{
- PTCFlowCanCmdData.SignalCmdValue = Flow;
+ //首先是否判断是有斜率
+ if (PTCFlowCanCmdData.LogicRuleDto == null)
+ {
+ //没有启动逻辑规则处理
+ PTCFlowCanCmdData.SignalCmdValue = Flow;
+ }
+ else
+ {
+ //LogicRuleService.ApplyExpressionFast(SpeedData, SpeedCanCmdData.LogicRuleDto);
+ PTCFlowCanCmdData.SignalCmdValue = LogicRuleService.ApplyExpressionFast(Flow, PTCFlowCanCmdData.LogicRuleDto);
+ //Console.WriteLine($"实时转换后转速值:{SpeedCanCmdData.SignalCmdValue}-SV值:{SpeedData}");
+ }
}
+
}
///
@@ -249,10 +302,27 @@ namespace CapMachine.Wpf.Services
///
public void UpdateCapPTCWaterTempCmdData(double WaterTemp)
{
+ //if (PTCWaterTempCanCmdData != null)
+ //{
+ // PTCWaterTempCanCmdData.SignalCmdValue = WaterTemp;
+ //}
+
if (PTCWaterTempCanCmdData != null)
{
- PTCWaterTempCanCmdData.SignalCmdValue = WaterTemp;
+ //首先是否判断是有斜率
+ if (PTCWaterTempCanCmdData.LogicRuleDto == null)
+ {
+ //没有启动逻辑规则处理
+ PTCWaterTempCanCmdData.SignalCmdValue = WaterTemp;
+ }
+ else
+ {
+ //LogicRuleService.ApplyExpressionFast(SpeedData, SpeedCanCmdData.LogicRuleDto);
+ PTCWaterTempCanCmdData.SignalCmdValue = LogicRuleService.ApplyExpressionFast(WaterTemp, PTCWaterTempCanCmdData.LogicRuleDto);
+ //Console.WriteLine($"实时转换后转速值:{SpeedCanCmdData.SignalCmdValue}-SV值:{SpeedData}");
+ }
}
+
}
///
@@ -288,14 +358,52 @@ namespace CapMachine.Wpf.Services
{
if (ToomossLinDrive.OpenState)
{
+ //来回取反设置
if (ToomossLinDrive.IsCycleSend == false)
{
if (CmdData.Count > 0)
{
- ToomossLinDrive.IsCycleSend = true;
+ ////订阅 CmdData 的数据变化事件,确保基于数据变化刷新调度表
+ //ToomossLinDrive.LoadCmdDataToDrive(CmdData);
+
ToomossLinDrive.CmdData = CmdData;
- ToomossLinDrive.StartPrecisionCycleSendMsg();
+
+ //ToomossLinDrive.IsCycleSend = true;
+ //ToomossLinDrive.StartPrecisionCycleSendMsg();
//ToomossLinDrive.StartCycleSendMsg();
+
+ if (ToomossLinDrive.SchEnable)
+ {
+ //使用调度表的话,需要在调度表中配置信息后才可以进行操作
+ var GroupMsg = ToomossLinDrive.CmdData.GroupBy(a => a.MsgName).ToList();
+ foreach (var itemMsg in GroupMsg)
+ {
+ if (!ListLINScheduleConfig.ToList().Any(a => a.MsgName == itemMsg.Key))
+ {
+ System.Windows.MessageBox.Show($"你使能了调度表,但是调度表中没有设置【{itemMsg.Key}】信息,请设置后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
+ return;
+ }
+ }
+
+ if (ListLINScheduleConfig == null && ListLINScheduleConfig!.Count() == 0)
+ {
+ System.Windows.MessageBox.Show("调度表配置为空数据,请检查!将无法发送数据", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
+ return;
+ }
+
+ ToomossLinDrive.ListLINScheduleConfig = ListLINScheduleConfig!;
+ ToomossLinDrive.StartSchedule();
+ //ToomossLinDrive.StartCycleUpdateCmd();
+ }
+ else
+ {
+ //使用软件调度发送数据
+ ToomossLinDrive.StartPrecisionCycleSendMsg();
+ //ToomossCanDrive.StartCycleSendMsg();
+ }
+
+ ToomossLinDrive.IsCycleSend = true;
+
}
else
{
@@ -305,6 +413,11 @@ namespace CapMachine.Wpf.Services
else
{
ToomossLinDrive.IsCycleSend = false;
+ //如果是调度表的话,需要关闭调度表
+ if (ToomossLinDrive.SchEnable)
+ {
+ ToomossLinDrive.StopSchedule();
+ }
}
}
diff --git a/CapMachine.Wpf/ViewModels/DialogLINSchConfigViewModel.cs b/CapMachine.Wpf/ViewModels/DialogLINSchConfigViewModel.cs
new file mode 100644
index 0000000..3557829
--- /dev/null
+++ b/CapMachine.Wpf/ViewModels/DialogLINSchConfigViewModel.cs
@@ -0,0 +1,581 @@
+using AutoMapper;
+using CapMachine.Core;
+using CapMachine.Model.CANLIN;
+using CapMachine.Wpf.Dtos;
+using CapMachine.Wpf.Services;
+using Prism.Commands;
+using Prism.Services.Dialogs;
+using System.Collections.ObjectModel;
+using System.Windows;
+using System.Linq;
+using System.ComponentModel;
+using System;
+
+namespace CapMachine.Wpf.ViewModels
+{
+ public class DialogLINSchConfigViewModel : DialogViewModel
+ {
+ public DialogLINSchConfigViewModel(IFreeSql freeSql, IMapper mapper, LinDriveService linDriveService)
+ {
+ Title = "调度表 LIN 配置";
+ FreeSql = freeSql;
+ Mapper = mapper;
+ LinDriveService = linDriveService;
+
+ //默认只能用1号调度器
+ SchTabIndexCbxItems = new ObservableCollection()
+ {
+ new CbxItems(){
+ Key="0",
+ Text="0",
+ },
+ //new CbxItems(){
+ // Key="1",
+ // Text="1",
+ //},
+ //new CbxItems(){
+ // Key="2",
+ // Text="2",
+ //},
+ //new CbxItems(){
+ // Key="3",
+ // Text="3",
+ //},
+ //new CbxItems(){
+ // Key="4",
+ // Text="4",
+ //},
+ };
+
+ // 初始化树结构集合
+ SchTabTree = new ObservableCollection();
+
+ }
+
+ public IFreeSql FreeSql { get; }
+ public IMapper Mapper { get; }
+ public LinDriveService LinDriveService { get; }
+
+ private string name;
+ ///
+ /// 名称
+ ///
+ public string Name
+ {
+ get { return name; }
+ set { name = value; RaisePropertyChanged(); }
+ }
+
+ private ObservableCollection _ListLINScheduleConfigDto = new ObservableCollection();
+ ///
+ /// LIN 调度表数据集合
+ ///
+ public ObservableCollection ListLINScheduleConfigDto
+ {
+ get { return _ListLINScheduleConfigDto; }
+ set { _ListLINScheduleConfigDto = value; RaisePropertyChanged(); }
+ }
+
+ ///
+ /// 消息/帧报文信息集合
+ ///
+ public List ListMsg { get; set; }
+
+ private ObservableCollection _MsgCbxItems;
+ ///
+ /// 消息名称 集合信息
+ ///
+ public ObservableCollection MsgCbxItems
+ {
+ get { return _MsgCbxItems; }
+ set { _MsgCbxItems = value; RaisePropertyChanged(); }
+ }
+
+ ///
+ /// 选中的程序的Id
+ ///
+ public long SelectCanLinConfigProId { get; set; }
+
+
+ private ObservableCollection _SchTabIndexCbxItems;
+ ///
+ /// 调度器序号 集合信息
+ ///
+ public ObservableCollection SchTabIndexCbxItems
+ {
+ get { return _SchTabIndexCbxItems; }
+ set { _SchTabIndexCbxItems = value; RaisePropertyChanged(); }
+ }
+
+ private LINScheduleConfigDto _CurSelectedItem;
+ ///
+ /// 选中的数据
+ ///
+ public LINScheduleConfigDto CurSelectedItem
+ {
+ get { return _CurSelectedItem; }
+ set { _CurSelectedItem = value; RaisePropertyChanged(); }
+ }
+
+ //================ TreeView 数据源与选择逻辑 ================
+ // 说明:
+ // 1) SchTabTree 为 XAML 中 TreeView 的 ItemsSource,父节点为调度表 LinSchTabNode,子节点为 LinMsgNode。
+ // 2) 仅允许“单选”一个调度表(父节点)。父节点上的 CheckBox 为 TwoWay 绑定 ViewModel 模型的 IsSelected 属性。
+ // 3) 我们在 BuildTree() 完成后,通过 AttachNodeHandlers() 给父节点订阅 PropertyChanged,
+ // 当 IsSelected 变化时,统一走 OnSelectSchTab() 做单选互斥与子节点联动,避免在 XAML 上用行为触发器造成递归。
+ private ObservableCollection _SchTabTree;
+ ///
+ /// 调度表-消息 树结构数据源(父:SchTabName,子:消息/帧)
+ ///
+ public ObservableCollection SchTabTree
+ {
+ get { return _SchTabTree; }
+ set { _SchTabTree = value; RaisePropertyChanged(); }
+ }
+
+ // 防止选择联动时的递归重入。
+ // 在 OnSelectSchTab() 中统一设置 _isUpdatingSelection = true,
+ // 以避免模型属性变化再次触发 Node_PropertyChanged() / OnSelectSchTab() 形成递归导致 StackOverflow。
+ private bool _isUpdatingSelection = false;
+
+ private DelegateCommand _SelectSchTabCmd;
+ ///
+ /// 选择/激活 调度表命令(单选),联动选中其下所有消息
+ ///
+ public DelegateCommand SelectSchTabCmd
+ {
+ get
+ {
+ if (_SelectSchTabCmd == null)
+ {
+ _SelectSchTabCmd = new DelegateCommand(OnSelectSchTab);
+ }
+ return _SelectSchTabCmd;
+ }
+ set { _SelectSchTabCmd = value; }
+ }
+
+ ///
+ /// 激活选中的调度表(父节点单选),并联动:
+ /// 1) 取消其它调度表的选中;
+ /// 2) 仅控制子节点可编辑状态(不强制选中/取消),子节点勾选独立由用户控制;
+ /// 3) 同步底层 ListLINScheduleConfigDto 的 IsActive(只允许一个调度表 Active)。
+ /// 通过 _isUpdatingSelection 防重入,避免模型 -> 视图 -> 模型 的递归通知。
+ ///
+ ///
+ private void OnSelectSchTab(LinSchTabNode node)
+ {
+ if (node == null) return;
+ if (_isUpdatingSelection) return;
+ try
+ {
+ _isUpdatingSelection = true;
+
+ // 单选:当前节点选中时,取消其它调度表选中
+ if (node.IsSelected)
+ {
+ foreach (var n in SchTabTree)
+ {
+ bool isTarget = ReferenceEquals(n, node);
+ n.IsSelected = isTarget;
+ // 仅控制可编辑性
+ foreach (var c in n.Children) c.CanEdit = isTarget;
+ }
+ }
+ else
+ {
+ // 取消选中:仅禁止子节点编辑,保留勾选状态
+ foreach (var c in node.Children) c.CanEdit = false;
+ }
+
+ // 同步 DTO 激活状态:按当前树中第一个被选中的调度表名写回
+ var active = SchTabTree?.FirstOrDefault(n => n.IsSelected);
+ foreach (var dto in ListLINScheduleConfigDto)
+ {
+ dto.IsActive = active != null && string.Equals(dto.SchTabName, active.SchTabName, StringComparison.Ordinal);
+ }
+ }
+ finally
+ {
+ _isUpdatingSelection = false;
+ }
+ }
+
+ ///
+ /// 基于当前 ListLINScheduleConfigDto 构建树结构。
+ /// - 将 DTO 以 SchTabName 分组,生成父节点;
+ /// - 子节点为每条消息/帧(MsgName, MsgNameIndex),IsSelected 与 DTO.IsActive 同步;
+ /// - 若出现多个分组均被标记 IsActive,则仅保留第一个为选中,其它重置为未选中(保证单选约束);
+ /// - 构建完成后调用 AttachNodeHandlers() 订阅父节点的 PropertyChanged,实现勾选即联动。
+ ///
+ private void BuildTree()
+ {
+ var newTree = new ObservableCollection();
+ if (ListLINScheduleConfigDto != null && ListLINScheduleConfigDto.Any())
+ {
+ var groups = ListLINScheduleConfigDto
+ .GroupBy(x => x.SchTabName ?? string.Empty)
+ .OrderBy(g => g.Key);
+
+ foreach (var g in groups)
+ {
+ var node = new LinSchTabNode
+ {
+ SchTabName = g.Key,
+ IsSelected = g.Any(x => x.IsActive),
+ Children = new ObservableCollection(
+ g.Select(x => new LinMsgNode
+ {
+ SchTabName = g.Key,
+ MsgName = x.MsgName ?? string.Empty,
+ MsgNameIndex = x.MsgNameIndex,
+ IsSelected = x.IsMsgActived,
+ CanEdit = g.Any(t => t.IsActive) // 仅激活的调度表可编辑
+ }))
+ };
+ newTree.Add(node);
+ }
+
+ // 如果没有任何 IsActive,确保默认不选;若存在多个组被标记,保持第一个,其他置为 false
+ var activeOnes = newTree.Where(n => n.IsSelected).ToList();
+ if (activeOnes.Count > 1)
+ {
+ var keep = activeOnes.First();
+ foreach (var n in activeOnes.Skip(1)) n.IsSelected = false;
+ foreach (var dto in ListLINScheduleConfigDto)
+ {
+ dto.IsActive = string.Equals(dto.SchTabName, keep.SchTabName, StringComparison.Ordinal);
+ }
+ }
+ }
+ SchTabTree = newTree;
+
+ // 绑定节点属性变化事件:
+ // - 父节点 IsSelected 变化 -> Node_PropertyChanged() -> OnSelectSchTab()
+ // - 子节点 IsSelected 变化 -> Child_PropertyChanged() -> 回写 DTO.IsMsgActived
+ // 这样可以不依赖 XAML EventTrigger,减少 UI 侧的递归触发风险。
+ AttachNodeHandlers(SchTabTree);
+ }
+
+ ///
+ /// 订阅父节点集合的 PropertyChanged。
+ /// 注意:子节点当前仅用于显示,不处理其 PropertyChanged。
+ ///
+ private void AttachNodeHandlers(IEnumerable nodes)
+ {
+ if (nodes == null) return;
+ foreach (var n in nodes)
+ {
+ n.PropertyChanged -= Node_PropertyChanged;
+ n.PropertyChanged += Node_PropertyChanged;
+ if (n.Children != null && n.Children.Any())
+ {
+ foreach (var c in n.Children)
+ {
+ c.PropertyChanged -= Child_PropertyChanged;
+ c.PropertyChanged += Child_PropertyChanged;
+ }
+ }
+ }
+ }
+
+ ///
+ /// 父节点属性变更回调:当 IsSelected 变化时,统一交由 OnSelectSchTab() 处理单选与联动。
+ ///
+ private void Node_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
+ {
+ if (e.PropertyName == nameof(LinSchTabNode.IsSelected))
+ {
+ OnSelectSchTab(sender as LinSchTabNode);
+ }
+ }
+
+ ///
+ /// 子节点属性变更:当 IsSelected 变化时,回写对应 DTO.IsMsgActived。
+ /// 仅当其父节点为选中状态时允许写回(CanEdit=true)。
+ ///
+ private void Child_PropertyChanged(object? sender, PropertyChangedEventArgs e)
+ {
+ if (e.PropertyName != nameof(LinMsgNode.IsSelected)) return;
+ if (_isUpdatingSelection) return;
+
+ try
+ {
+ _isUpdatingSelection = true;
+
+ var child = sender as LinMsgNode;
+ if (child == null) return;
+
+ // 查找父节点
+ var parent = SchTabTree?.FirstOrDefault(n => n.Children.Contains(child));
+ if (parent == null) return;
+
+ // 仅在父节点选中(可编辑)时回写 DTO
+ if (!parent.IsSelected || !child.CanEdit) return;
+
+ var dto = ListLINScheduleConfigDto?.FirstOrDefault(d =>
+ string.Equals(d.SchTabName ?? string.Empty, parent.SchTabName ?? string.Empty, StringComparison.Ordinal)
+ && string.Equals(d.MsgName ?? string.Empty, child.MsgName ?? string.Empty, StringComparison.Ordinal)
+ && d.MsgNameIndex == child.MsgNameIndex);
+ if (dto != null)
+ {
+ dto.IsMsgActived = child.IsSelected;
+ }
+ }
+ finally
+ {
+ _isUpdatingSelection = false;
+ }
+ }
+
+
+ private DelegateCommand
public IDialogService DialogService { get; }
+ private ObservableCollection _WriteRuleCbxItems;
+ ///
+ /// 写入的规格集合
+ ///
+ public ObservableCollection WriteRuleCbxItems
+ {
+ get { return _WriteRuleCbxItems; }
+ set { _WriteRuleCbxItems = value; RaisePropertyChanged(); }
+ }
+
+
+ #region 规则
+
+
+ ///
+ /// 逻辑更改事件
+ ///
+ ///
+ ///
+ private void LogicRuleChangeEventCall(string msg)
+ {
+ //InitWriteRuleCbx();
+ }
+
+ ///
+ /// 初始化写规则下拉框
+ ///
+ private void InitWriteRuleCbx()
+ {
+ WriteRuleCbxItems = new ObservableCollection();
+ //选择的读写规则
+ foreach (var itemRule in LogicRuleService.LogicRuleDtos)
+ {
+ WriteRuleCbxItems.Add(new CbxItems()
+ {
+ Key = itemRule.Id.ToString(),
+ Text = itemRule.Name
+ });
+ }
+ }
+
+
+ #endregion
#region LinConfigPro
@@ -118,7 +175,8 @@ namespace CapMachine.Wpf.ViewModels
//LIN配置集合数据
canLinConfigPros = FreeSql.Select().Where(a => a.CANLINInfo == CANLIN.LIN)
.Include(a => a.LINConfigExd)
- .IncludeMany(a => a.CanLinConfigContents)
+ .IncludeMany(a => a.CanLinConfigContents, then => then.Include(b => b.LogicRule))
+ .IncludeMany(a => a.LinScheduleConfigs)
.ToList();
ListCanLinConfigPro = new ObservableCollection(canLinConfigPros);
@@ -145,6 +203,7 @@ namespace CapMachine.Wpf.ViewModels
MsgName = item.MsgFrameName,
SignalName = item.SignalName,
SignalCmdValue = double.TryParse(item.DefautValue, out double result) == true ? result : 0,
+ LogicRuleDto = Mapper.Map(item.LogicRule),
});
//LinDriveService.CmdData.Add(new LinCmdData()
//{
@@ -156,11 +215,30 @@ namespace CapMachine.Wpf.ViewModels
}
}
+ else
+ {
+ ListWriteCanLinRWConfigDto = new ObservableCollection();
+ }
+
var ReadData = SelectCanLinConfigPro.CanLinConfigContents!.Where(a => a.RWInfo == RW.Read).ToList();
if (ReadData != null && ReadData.Count > 0)
{
ListReadCanLinRWConfigDto = new ObservableCollection(Mapper.Map>(ReadData));
}
+ else
+ {
+ ListReadCanLinRWConfigDto = new ObservableCollection();
+ }
+
+ //调度表配置信息
+ if (SelectCanLinConfigPro.LinScheduleConfigs != null && SelectCanLinConfigPro.LinScheduleConfigs.Count() > 0)
+ {
+ ListLINScheduleConfigDto = new ObservableCollection(Mapper.Map>(SelectCanLinConfigPro.LinScheduleConfigs));
+ }
+ else
+ {
+ ListLINScheduleConfigDto = new ObservableCollection();
+ }
//匹配选中的SelectCanLinConfigPro.CanLinConfigContents和ListLinLdfModel
MatchSeletedAndLinLdfModel();
@@ -408,6 +486,8 @@ namespace CapMachine.Wpf.ViewModels
LinDriveService.InitLinConfig(SelectCanLinConfigPro);
InitLoadLinConfigPro();
+ // 订阅 CmdData 的数据变化事件,用于基于数据变化刷新调度表
+ LinDriveService.ToomossLinDrive.LoadCmdDataToDrive(LinDriveService.CmdData);
}
else
{
@@ -496,6 +576,7 @@ namespace CapMachine.Wpf.ViewModels
MsgName = item.MsgFrameName,
SignalName = item.SignalName,
SignalCmdValue = double.TryParse(item.DefautValue, out double result) == true ? result : 0,
+ LogicRuleDto = Mapper.Map(item.LogicRule),
});
//LinDriveService.CmdData.Add(new LinCmdData()
@@ -508,13 +589,33 @@ namespace CapMachine.Wpf.ViewModels
}
}
+ else
+ {
+ ListWriteCanLinRWConfigDto = new ObservableCollection();
+ }
var ReadData = SelectCanLinConfigPro.CanLinConfigContents!.Where(a => a.RWInfo == RW.Read).ToList();
if (ReadData != null && ReadData.Count > 0)
{
ListReadCanLinRWConfigDto = new ObservableCollection(Mapper.Map>(ReadData));
}
+ else
+ {
+ ListReadCanLinRWConfigDto = new ObservableCollection();
+ }
SelectCanLinConfigProConfigName = SelectCanLinConfigPro.ConfigName;
+
+ //调度表配置信息
+ if (SelectCanLinConfigPro.LinScheduleConfigs != null && SelectCanLinConfigPro.LinScheduleConfigs.Count() > 0)
+ {
+ ListLINScheduleConfigDto = new ObservableCollection(Mapper.Map>(SelectCanLinConfigPro.LinScheduleConfigs));
+ }
+ else
+ {
+ ListLINScheduleConfigDto = new ObservableCollection();
+ }
+
+
return;
}
//先判断是否是正确的集合数据,防止DataGrid的数据源刷新导致的触发事件
@@ -792,6 +893,58 @@ namespace CapMachine.Wpf.ViewModels
set { _SelectedLINConfigExdDto = value; RaisePropertyChanged(); }
}
+ private ObservableCollection _DataBaudRateCbxItems;
+ ///
+ /// CAN 数据波特率
+ ///
+ public ObservableCollection DataBaudRateCbxItems
+ {
+ get { return _DataBaudRateCbxItems; }
+ set { _DataBaudRateCbxItems = value; RaisePropertyChanged(); }
+ }
+
+
+ private DelegateCommand _SchEnableCmd;
+ ///
+ /// 调度表的使能 操作的指令
+ ///
+ public DelegateCommand SchEnableCmd
+ {
+ set
+ {
+ _SchEnableCmd = value;
+ }
+ get
+ {
+ if (_SchEnableCmd == null)
+ {
+ _SchEnableCmd = new DelegateCommand((Par) => SchEnableCmdCall(Par));
+ }
+ return _SchEnableCmd;
+ }
+ }
+ ///
+ /// 调度表的使能信息
+ ///
+ ///
+ ///
+ private void SchEnableCmdCall(object par)
+ {
+ var dd = SelectedLINConfigExdDto.SchEnable;
+ var Result = (bool)par;
+ if (Result)
+ {
+ LinDriveService.ToomossLinDrive.SchEnable = true;
+
+ }
+ else
+ {
+ LinDriveService.ToomossLinDrive.SchEnable = false;
+
+ }
+ }
+
+
private DelegateCommand _LinOpCmd;
///
/// LIN操作的指令
@@ -835,7 +988,7 @@ namespace CapMachine.Wpf.ViewModels
//系统使用了LIN
ConfigService.CanLinRunStateModel.CurSysSelectedCanLin = CanLinEnum.Lin;
}
-
+
//LIN LDF配置 有LDF配置的话,则直接加载LDF信息
if (!string.IsNullOrEmpty(SelectCanLinConfigPro.LINConfigExd.LdfPath))
{
@@ -877,6 +1030,7 @@ namespace CapMachine.Wpf.ViewModels
.Set(a => a.LdfPath, SelectedLINConfigExdDto.LdfPath)
.Set(a => a.Cycle, SelectedLINConfigExdDto.Cycle)
.Set(a => a.BaudRate, SelectedLINConfigExdDto.BaudRate)
+ .Set(a => a.SchEnable, SelectedLINConfigExdDto.SchEnable)
.Where(a => a.Id == SelectedLINConfigExdDto.Id)
.ExecuteUpdated();
}
@@ -938,6 +1092,12 @@ namespace CapMachine.Wpf.ViewModels
break;
case "CycleSend"://循环发送你
+
+ //有可能加载完毕后不手动改变状态,导致值没有传输,所以这里赋值
+ LinDriveService.ToomossLinDrive.SchEnable = SelectedLINConfigExdDto.SchEnable;
+ //无论有没有调度表,都要把这个配置给LinDriveService
+ LinDriveService.ListLINScheduleConfig = ListLINScheduleConfigDto.ToList();
+
//循环发送数据
LinDriveService.CycleSendMsg();
@@ -992,6 +1152,17 @@ namespace CapMachine.Wpf.ViewModels
}
+ private ObservableCollection _ListLINScheduleConfigDto;
+ ///
+ ///调度表集合
+ ///
+ public ObservableCollection ListLINScheduleConfigDto
+ {
+ get { return _ListLINScheduleConfigDto; }
+ set { _ListLINScheduleConfigDto = value; RaisePropertyChanged(); }
+ }
+
+
//private string _SelectedWriteName;
/////
///// 选中的写入的Name
@@ -1106,6 +1277,7 @@ namespace CapMachine.Wpf.ViewModels
//直接修改
FreeSql.Update(item.Id)
.Set(a => a.Name, item.Name)
+ .Set(a => a.LogicRuleId, item.LogicRuleId)
.Set(a => a.DefautValue, item.DefautValue)
.ExecuteAffrows();
//ListWriteCanLinRWConfigDto.Remove(SelectedWriteCanLinRWConfigDto);
@@ -1117,8 +1289,6 @@ namespace CapMachine.Wpf.ViewModels
InitLoadLinConfigPro();
}
-
-
break;
case "Delete":
if (SelectedWriteCanLinRWConfigDto != null)
@@ -1136,6 +1306,47 @@ namespace CapMachine.Wpf.ViewModels
System.Windows.MessageBox.Show("请选中后再进行【删除】操作?", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
}
+ break;
+ case "WriteSch"://调度表
+
+ //LinDriveService.ToomossLinDrive.LinTest();
+
+ //LinDriveService.ToomossLinDrive.StartSchedule();
+ //break;
+ //
+ if (LinDriveService.ToomossLinDrive.OpenState)
+ {
+ //弹窗
+ DialogService.ShowDialog("DialogLINSchConfigView", new DialogParameters() {
+ {"ListMsg", LinDriveService.CmdData.GroupBy(a=>a.MsgName).Select(a=>a.Key).ToList() },
+ { "ListLINScheduleConfigDto",ListLINScheduleConfigDto},
+ { "SelectCanLinConfigProId",SelectCanLinConfigPro.Id},
+
+ }, (par) =>
+ {
+ if (par.Result == ButtonResult.OK)
+ {
+ ////程序名称
+ ListLINScheduleConfigDto = par.Parameters.GetValue>("ReturnValue");
+ //把更新后的最新值给当前的主集合中
+ SelectCanLinConfigPro.LinScheduleConfigs = Mapper.Map>(ListLINScheduleConfigDto.ToList());
+
+ }
+ else if (par.Result == ButtonResult.Cancel)
+ {
+ //取消
+
+ }
+
+ });
+ }
+ else
+ {
+ System.Windows.MessageBox.Show("未发现写入的执行的命令数据,无法配置?", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
+ }
+
+
+
break;
default:
break;
diff --git a/CapMachine.Wpf/ViewModels/LinSchTabNode.cs b/CapMachine.Wpf/ViewModels/LinSchTabNode.cs
new file mode 100644
index 0000000..efca108
--- /dev/null
+++ b/CapMachine.Wpf/ViewModels/LinSchTabNode.cs
@@ -0,0 +1,109 @@
+using Prism.Mvvm;
+using System.Collections.ObjectModel;
+
+namespace CapMachine.Wpf.ViewModels
+{
+ ///
+ /// 调度表节点(父节点)。
+ /// 与 XAML 中父级 的 绑定:
+ /// - 显示字段:
+ /// - 选择字段:(TwoWay 绑定至 CheckBox)
+ /// - 子集合:(用于展开显示消息/帧子节点)
+ ///
+ /// 使用 Prism 的
+ /// 以避免值未发生变化时重复触发 PropertyChanged 引起的联动递归。
+ ///
+ public class LinSchTabNode : BindableBase
+ {
+ ///
+ /// 调度表名称(父节点标题)。
+ ///
+ private string _SchTabName;
+ public string SchTabName
+ {
+ get => _SchTabName;
+ set => SetProperty(ref _SchTabName, value);
+ }
+
+ private bool _IsSelected;
+ ///
+ /// 是否被激活/选中(父节点单选)。
+ /// 该属性与 XAML 中父节点的 CheckBox 进行 TwoWay 绑定,
+ /// 其变更由 ViewModel 监听并处理“单选联动”和“子节点跟随”。
+ ///
+ public bool IsSelected
+ {
+ get => _IsSelected;
+ set => SetProperty(ref _IsSelected, value);
+ }
+
+ ///
+ /// 子节点集合(消息/帧条目)。
+ ///
+ private ObservableCollection _Children = new ObservableCollection();
+ public ObservableCollection Children
+ {
+ get => _Children;
+ set => SetProperty(ref _Children, value);
+ }
+ }
+
+ ///
+ /// 消息/帧 节点(子节点)。
+ /// 与 XAML 中父级 绑定:
+ /// - 显示字段: /
+ /// - 选择字段:(当前设计作为“显示联动”,非编辑入口)
+ ///
+ public class LinMsgNode : BindableBase
+ {
+ ///
+ /// 所属的调度表名称(便于回写 DTO 时定位)。
+ ///
+ private string _SchTabName;
+ public string SchTabName
+ {
+ get => _SchTabName;
+ set => SetProperty(ref _SchTabName, value);
+ }
+
+ ///
+ /// 消息/帧名称。
+ ///
+ private string _MsgName;
+ public string MsgName
+ {
+ get => _MsgName;
+ set => SetProperty(ref _MsgName, value);
+ }
+
+ ///
+ /// 消息/帧 Index。
+ ///
+ private int _MsgNameIndex;
+ public int MsgNameIndex
+ {
+ get => _MsgNameIndex;
+ set => SetProperty(ref _MsgNameIndex, value);
+ }
+
+ private bool _IsSelected;
+ ///
+ /// 是否被选中(随父节点联动显示)。
+ ///
+ public bool IsSelected
+ {
+ get => _IsSelected;
+ set => SetProperty(ref _IsSelected, value);
+ }
+
+ ///
+ /// 子节点勾选是否可用(仅当父调度表被选中时可编辑)。
+ ///
+ private bool _CanEdit;
+ public bool CanEdit
+ {
+ get => _CanEdit;
+ set => SetProperty(ref _CanEdit, value);
+ }
+ }
+}
diff --git a/CapMachine.Wpf/Views/DialogLINSchConfigView.xaml b/CapMachine.Wpf/Views/DialogLINSchConfigView.xaml
new file mode 100644
index 0000000..ffcb25f
--- /dev/null
+++ b/CapMachine.Wpf/Views/DialogLINSchConfigView.xaml
@@ -0,0 +1,210 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/CapMachine.Wpf/Views/DialogLINSchConfigView.xaml.cs b/CapMachine.Wpf/Views/DialogLINSchConfigView.xaml.cs
new file mode 100644
index 0000000..451f38c
--- /dev/null
+++ b/CapMachine.Wpf/Views/DialogLINSchConfigView.xaml.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace CapMachine.Wpf.Views
+{
+ ///
+ /// DialogLINSchConfigView.xaml 的交互逻辑
+ ///
+ public partial class DialogLINSchConfigView : UserControl
+ {
+ public DialogLINSchConfigView()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/CapMachine.Wpf/Views/LINConfigView.xaml b/CapMachine.Wpf/Views/LINConfigView.xaml
index bec5411..9216a88 100644
--- a/CapMachine.Wpf/Views/LINConfigView.xaml
+++ b/CapMachine.Wpf/Views/LINConfigView.xaml
@@ -406,7 +406,14 @@
FontSize="18"
Text="" />
-
+
+
@@ -573,6 +580,84 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -631,6 +716,24 @@
Margin="0,0,15,0"
HorizontalAlignment="Right"
Orientation="Horizontal">
+