diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 0000000..27494df --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,7 @@ +{ + "permissions": { + "allow": [ + "mcp__filesystem__directory_tree" + ] + } +} diff --git a/CapMachine.Wpf/CanDrive/ToomossCan.cs b/CapMachine.Wpf/CanDrive/ToomossCan.cs index 40c2c16..e34cdd4 100644 --- a/CapMachine.Wpf/CanDrive/ToomossCan.cs +++ b/CapMachine.Wpf/CanDrive/ToomossCan.cs @@ -546,7 +546,6 @@ namespace CapMachine.Wpf.CanDrive Marshal.FreeHGlobal(msgPtSend); } } - Console.WriteLine(""); //发送CAN数据 int SendedNum = USB2CAN.CAN_SendMsg(DevHandle, WriteCANIndex, CanMsg, (uint)CanMsg.Length); if (SendedNum >= 0) @@ -594,7 +593,6 @@ namespace CapMachine.Wpf.CanDrive int CanNum = USB2CAN.CAN_GetMsgWithSize(DevHandle, ReadCANIndex, msgPtRead, CanMsgBuffer.Length); if (CanNum > 0) { - Console.WriteLine("Read CanMsgNum = {0}", CanNum); for (int i = 0; i < CanNum; i++) { //CanMsgBuffer[i] = (USB2CAN.CAN_MSG)Marshal.PtrToStructure((IntPtr)((UInt32)msgPtRead + i * Marshal.SizeOf(typeof(USB2CAN.CAN_MSG))), typeof(USB2CAN.CAN_MSG)); //有溢出报错 @@ -603,10 +601,6 @@ namespace CapMachine.Wpf.CanDrive //Console.WriteLine("CanMsg[{0}].ID = 0x{1}", i, CanMsgBuffer[i].ID.ToString("X8")); //Console.WriteLine("CanMsg[{0}].TimeStamp = {1}", i, CanMsgBuffer[i].TimeStamp); //Console.Write("CanMsg[{0}].Data = ", i); - for (int j = 0; j < CanMsgBuffer[i].DataLen; j++) - { - Console.Write("{0} ", CanMsgBuffer[i].Data[j].ToString("X2")); - } //Console.WriteLine(""); //报文给高速记录的服务 @@ -627,8 +621,6 @@ namespace CapMachine.Wpf.CanDrive { //Console.WriteLine("Get CAN data error!"); } - Console.WriteLine(""); - if (CanNum > 0) { lock (_dbcParserLock) @@ -645,7 +637,6 @@ namespace CapMachine.Wpf.CanDrive var valueSb = new StringBuilder(64); CAN_DBCParser.DBC_GetSignalValueStr(DBCHandle, new StringBuilder(item.MsgName), new StringBuilder(item.SignalName), valueSb); item.SignalRtValueSb = valueSb; - Console.Write(valueSb.ToString()); //} } } @@ -717,7 +708,7 @@ namespace CapMachine.Wpf.CanDrive CycleSendCts = cancellationTokenSource;//将取消标记源保存到类的成员变量CycleSendCts,这样在外部调用停止方法时可以访问它 NextExecutionTime = 0;//初始化NextExecutionTime为0,这个变量用于记录下一次执行的目标时间点 - CycleSendTask = Task.Factory.StartNew(async () => + CycleSendTask = Task.Run(async () => { try { @@ -863,7 +854,7 @@ namespace CapMachine.Wpf.CanDrive Stopwatcher.Stop(); } - }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default); + }, token); } diff --git a/CapMachine.Wpf/Services/CanDriveService.cs b/CapMachine.Wpf/Services/CanDriveService.cs index 42fd28c..b31524e 100644 --- a/CapMachine.Wpf/Services/CanDriveService.cs +++ b/CapMachine.Wpf/Services/CanDriveService.cs @@ -255,10 +255,10 @@ namespace CapMachine.Wpf.Services { if (!ToomossCanDrive.IsCycleRevice) return 0; - if (ListCanDbcModel.Any(a => a.Name == Name)) + var dbcModel = ListCanDbcModel.FindFirst(a => a.Name == Name); + if (dbcModel != null && !string.IsNullOrWhiteSpace(dbcModel.SignalRtValue)) { - //double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue, out double Result1); - return double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue.Split(" ")[0], out double Result) == true ? Result : 0; + return double.TryParse(dbcModel.SignalRtValue.Split(" ")[0], out double Result) == true ? Result : 0; } return 0; } @@ -274,10 +274,10 @@ namespace CapMachine.Wpf.Services { if (!ToomossCanDrive.IsCycleRevice) return 0; - if (ListCanDbcModel.Any(a => a.Name == Name)) + var dbcModel = ListCanDbcModel.FindFirst(a => a.Name == Name); + if (dbcModel != null && !string.IsNullOrWhiteSpace(dbcModel.SignalRtValue)) { - //double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue, out double Result1); - return double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue.Split(" ")[0], out double Result) == true ? Result : 0; + return double.TryParse(dbcModel.SignalRtValue.Split(" ")[0], out double Result) == true ? Result : 0; } return 0; }