diff --git a/CapMachine.Wpf/CanDrive/CanCmdData.cs b/CapMachine.Wpf/CanDrive/CanCmdData.cs index f2e8934..1beecc0 100644 --- a/CapMachine.Wpf/CanDrive/CanCmdData.cs +++ b/CapMachine.Wpf/CanDrive/CanCmdData.cs @@ -1,4 +1,4 @@ -using CapMachine.Wpf.Dtos; +using CapMachine.Wpf.Dtos; namespace CapMachine.Wpf.CanDrive { @@ -41,7 +41,10 @@ namespace CapMachine.Wpf.CanDrive if (_SignalCmdValue != value) { _SignalCmdValue = value; - CanCmdDataChangedHandler!.BeginInvoke(this, MsgName!, null, null); + if (CanCmdDataChangedHandler != null) + { + CanCmdDataChangedHandler!.Invoke(this, MsgName!); + } } } diff --git a/CapMachine.Wpf/CanDrive/ToomossCan.cs b/CapMachine.Wpf/CanDrive/ToomossCan.cs index b5a94ec..615d953 100644 --- a/CapMachine.Wpf/CanDrive/ToomossCan.cs +++ b/CapMachine.Wpf/CanDrive/ToomossCan.cs @@ -542,6 +542,7 @@ namespace CapMachine.Wpf.CanDrive /// /// 加载要发送的数据 + /// 一般是激活后才注册事件 /// /// public void LoadCmdDataToDrive(List cmdData) @@ -557,7 +558,7 @@ namespace CapMachine.Wpf.CanDrive // Set the new data and subscribe to events CmdData = cmdData; - foreach (var cmd in CmdData) + foreach (var cmd in cmdData) { cmd.CanCmdDataChangedHandler += CmdData_CanCmdDataChangedHandler; } @@ -589,6 +590,7 @@ namespace CapMachine.Wpf.CanDrive try { if (!IsCycleSend) return; + if (!SchEnable) return; // 基础防御:确保 DBC/ 调度表 / 分组已经初始化 if (DBCHandle == 0 || SchCanMsg == null || GroupMsg == null) @@ -651,6 +653,7 @@ namespace CapMachine.Wpf.CanDrive } } + /// /// 循环发送数据 /// diff --git a/CapMachine.Wpf/CapMachine.Wpf.csproj b/CapMachine.Wpf/CapMachine.Wpf.csproj index 16f359b..38d28f8 100644 --- a/CapMachine.Wpf/CapMachine.Wpf.csproj +++ b/CapMachine.Wpf/CapMachine.Wpf.csproj @@ -1,7 +1,7 @@  - Exe + WinExe net6.0-windows enable enable diff --git a/CapMachine.Wpf/LinDrive/ToomossLin.cs b/CapMachine.Wpf/LinDrive/ToomossLin.cs index 06d5d18..398cf2e 100644 --- a/CapMachine.Wpf/LinDrive/ToomossLin.cs +++ b/CapMachine.Wpf/LinDrive/ToomossLin.cs @@ -776,6 +776,18 @@ namespace CapMachine.Wpf.LinDrive { if (CmdData.Count() == 0) return; + //设置调度表发送次数 + var SetSchRunTimeRet = USB2LIN_EX.LIN_EX_MasterSetSchRunTimes(DevHandle, LINIndex, 0xFFFFFFFF);//次数为0xFFFFFFFF表示一直发送数据 + if (SetSchRunTimeRet < USB2LIN_EX.LIN_EX_SUCCESS) + { + Console.WriteLine("Set Master Run Times failed!"); + return; + } + else + { + Console.WriteLine("Set Master Run Times success!"); + } + //防止有多个不同的消息名称/帧,每个帧单独处理发送 var GroupMsg = CmdData.GroupBy(x => x.MsgName); foreach (var itemMsg in GroupMsg) @@ -803,7 +815,6 @@ namespace CapMachine.Wpf.LinDrive } } - LDFParser.LDF_ExeSchToBus(LDFHandle, new StringBuilder(itemMsg.Key), 1); LDFParser.LDF_SetSchToTable(LDFHandle, new StringBuilder(itemMsg.Key), 1); } @@ -859,7 +870,7 @@ namespace CapMachine.Wpf.LinDrive LDFParser.LDF_SetSchToTable(LDFHandle, new StringBuilder(itemMsg.Key), 1); } - + IsSendOk = true; } catch (Exception ex) { 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/CanDriveService.cs b/CapMachine.Wpf/Services/CanDriveService.cs index 1119f24..a7e5266 100644 --- a/CapMachine.Wpf/Services/CanDriveService.cs +++ b/CapMachine.Wpf/Services/CanDriveService.cs @@ -314,7 +314,7 @@ namespace CapMachine.Wpf.Services if (CmdData.Count > 0) { //把指令数据赋值给CAN 驱动 - ToomossCanDrive.LoadCmdDataToDrive(CmdData); + ToomossCanDrive.CmdData = CmdData; if (ToomossCanDrive.SchEnable) { @@ -337,7 +337,7 @@ namespace CapMachine.Wpf.Services } ToomossCanDrive.ListCANScheduleConfig = ListCANScheduleConfig!; ToomossCanDrive.StartSchedule(); - ToomossCanDrive.StartCycleUpdateCmd(); + //ToomossCanDrive.StartCycleUpdateCmd(); } else { diff --git a/CapMachine.Wpf/Services/PPCService.cs b/CapMachine.Wpf/Services/PPCService.cs index b435222..27406c8 100644 --- a/CapMachine.Wpf/Services/PPCService.cs +++ b/CapMachine.Wpf/Services/PPCService.cs @@ -1,19 +1,11 @@ using CapMachine.Core; -using CapMachine.Shared.Controls; using CapMachine.Wpf.Models.PPCalc; using CapMachine.Wpf.Models.Tag; using CapMachine.Wpf.PPCalculation; +using NLog; using Prism.Events; using Prism.Mvvm; using Prism.Services.Dialogs; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using NLog; namespace CapMachine.Wpf.Services { diff --git a/CapMachine.Wpf/ViewModels/CANConfigViewModel.cs b/CapMachine.Wpf/ViewModels/CANConfigViewModel.cs index 789f3db..a37ea33 100644 --- a/CapMachine.Wpf/ViewModels/CANConfigViewModel.cs +++ b/CapMachine.Wpf/ViewModels/CANConfigViewModel.cs @@ -1,4 +1,4 @@ -using AutoMapper; +using AutoMapper; using CapMachine.Core; using CapMachine.Model; using CapMachine.Model.CANLIN; @@ -489,6 +489,7 @@ namespace CapMachine.Wpf.ViewModels CanDriveService.InitCanConfig(SelectCanLinConfigPro); InitLoadCanConfigPro(); + CanDriveService.ToomossCanDrive.LoadCmdDataToDrive(CanDriveService.CmdData); } else {