From 6a2ce24cbbd7a8d4d6e72adad427c1fe264ad623 Mon Sep 17 00:00:00 2001 From: Tyrone CT Date: Wed, 9 Jul 2025 10:12:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E7=AD=BE=E5=8F=98=E9=87=8F=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CapMachine.Wpf/Models/Tag/TagManager.cs | 36 +++++++++++++++++++ .../Services/MachineRtDataService.cs | 5 +-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/CapMachine.Wpf/Models/Tag/TagManager.cs b/CapMachine.Wpf/Models/Tag/TagManager.cs index e0d33c7..3401d43 100644 --- a/CapMachine.Wpf/Models/Tag/TagManager.cs +++ b/CapMachine.Wpf/Models/Tag/TagManager.cs @@ -116,6 +116,42 @@ namespace CapMachine.Wpf.Models.Tag } + /// + /// ******* 从ShortValueTag中获取PVModel模型-定制的 ******** + /// 需要提前知道这个标签是CapTag标签,否则为空 + /// 尝试获取CapTag标签的PVModel模型 + /// 压缩机通信的标签 + /// + /// 标签名称 + /// 输出的pVModel模型,如果获取失败则为null + /// 是否成功获取PV模型 + public bool TryGetCapPVModelByShortValueTag(string tagName, out MeterValueAttrCell? pVModel) + { + lock (PvLock) + { + pVModel = null; + + if (string.IsNullOrEmpty(tagName)) + return false; + + // 尝试从字典中获取标签 + if (DicTags.TryGetValue(tagName, out var tag)) + { + // 尝试将标签转换为ShortValueTag + if (tag is ShortValueTag capTag) + { + pVModel = capTag.PVModel; + return true; + } + return false; + } + return false; + } + + } + + + /// /// 尝试获取标签的PVModel模型 diff --git a/CapMachine.Wpf/Services/MachineRtDataService.cs b/CapMachine.Wpf/Services/MachineRtDataService.cs index 98718ba..b03ff0a 100644 --- a/CapMachine.Wpf/Services/MachineRtDataService.cs +++ b/CapMachine.Wpf/Services/MachineRtDataService.cs @@ -1413,7 +1413,7 @@ namespace CapMachine.Wpf.Services while (ThreadEnable) { - await Task.Delay(20); + await Task.Delay(100); //await Task.CompletedTask; DiagnosticsTime.Reset(); @@ -1467,7 +1467,7 @@ namespace CapMachine.Wpf.Services if (itemCanLinGroup.Value.Group == "压缩机") { //尝试获取模型信息 - if (TagManger.TryGetCapPVModel(itemCanLinGroup.Key, out QuickAttrCell? pVModel)) + if (TagManger.TryGetCapPVModelByShortValueTag(itemCanLinGroup.Key, out MeterValueAttrCell? pVModel)) { switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin) { @@ -1490,6 +1490,7 @@ namespace CapMachine.Wpf.Services SiemensDrive.Write(pVModel!.Address!.Replace("W", ""), (short)(LinDriveService.GetLdfValueByName(itemCanLinGroup.Value.NameNoUnit) * itemCanLinGroup.Value.Precision)); break; case CanLinEnum.No: + break; default: break;