From 919becb72fcdea6bc37cbd820539dfb29af936f2 Mon Sep 17 00:00:00 2001 From: Tyrone CT Date: Thu, 19 Jun 2025 21:25:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=8D=E5=86=99=E5=88=B0PLC=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E6=9B=B4=E6=94=B9=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CapMachine.Wpf/Models/Tag/TagManager.cs | 35 ++++++++++++++++ .../Services/MachineRtDataService.cs | 28 ++++++++----- CapMachine.Wpf/Views/MonitorView.xaml | 40 +++++++++---------- 3 files changed, 72 insertions(+), 31 deletions(-) diff --git a/CapMachine.Wpf/Models/Tag/TagManager.cs b/CapMachine.Wpf/Models/Tag/TagManager.cs index 9a03d96..2a3a6c7 100644 --- a/CapMachine.Wpf/Models/Tag/TagManager.cs +++ b/CapMachine.Wpf/Models/Tag/TagManager.cs @@ -81,6 +81,41 @@ namespace CapMachine.Wpf.Models.Tag } + + /// + /// 需要提前知道这个标签是CapTag标签,否则为空 + /// 尝试获取CapTag标签的PVModel模型 + /// 压缩机通信的标签 + /// + /// 标签名称 + /// 输出的pVModel模型,如果获取失败则为null + /// 是否成功获取PV模型 + public bool TryGetCapPVModel(string tagName, out QuickAttrCell? pVModel) + { + lock (PvLock) + { + pVModel = null; + + if (string.IsNullOrEmpty(tagName)) + return false; + + // 尝试从字典中获取标签 + if (DicTags.TryGetValue(tagName, out var tag)) + { + // 尝试将标签转换为ShortControlTag + if (tag is CapTag 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 ca4d447..5fc7c04 100644 --- a/CapMachine.Wpf/Services/MachineRtDataService.cs +++ b/CapMachine.Wpf/Services/MachineRtDataService.cs @@ -1588,7 +1588,7 @@ namespace CapMachine.Wpf.Services Precision = 1, Unit = "℃", DataType = TagDataType.Double, - PVModel = new QuickAttrCell() { Address = "VW310", EngValue = 0, EngValueStr = "", }, + PVModel = new QuickAttrCell() { Address = "VW312", EngValue = 0, EngValueStr = "", }, RWInfo = RWInfo.CapRead, }); @@ -2279,6 +2279,7 @@ namespace CapMachine.Wpf.Services new PlcExdConfigCell(){ Name="吸排气阀",Address="V490",Precision=1}, new PlcExdConfigCell(){ Name="EV",Address="V492",Precision=1}, new PlcExdConfigCell(){ Name="压缩机使能",Address="V484",Precision=1}, + new PlcExdConfigCell(){ Name="参数编号",Address="V488",Precision=1}, new PlcExdConfigCell(){ Name="PTC使能",Address="V486",Precision=1}, }; @@ -2597,7 +2598,7 @@ namespace CapMachine.Wpf.Services if (TagManger.TryGetPVModel(itemCanLinGroup.Key, out MeterValueAttrCell? CanpVModel)) { CanpVModel!.EngValue = CanDriveService.GetDbcSpeedValueBySpeedName("通讯转速"); - SiemensDrive.Write(CanpVModel!.Address, (short)CanDriveService.GetDbcSpeedValueBySpeedName("通讯转速")); + SiemensDrive.Write(CanpVModel!.Address!.Replace("W", ""), (short)CanDriveService.GetDbcSpeedValueBySpeedName("通讯转速")); //pVModel.EngSrcValue = 0; } break; @@ -2606,7 +2607,7 @@ namespace CapMachine.Wpf.Services if (TagManger.TryGetPVModel(itemCanLinGroup.Key, out MeterValueAttrCell? LinpVModel)) { LinpVModel!.EngValue = LinDriveService.GetLdfSpeedValueBySpeedName("通讯转速"); - SiemensDrive.Write(LinpVModel!.Address, (short)LinDriveService.GetLdfSpeedValueBySpeedName("通讯转速")); + SiemensDrive.Write(LinpVModel!.Address!.Replace("W", ""), (short)LinDriveService.GetLdfSpeedValueBySpeedName("通讯转速")); } break; default: @@ -2617,10 +2618,10 @@ namespace CapMachine.Wpf.Services } //只处理CANLIN的数据 - if (itemCanLinGroup.Value.Group == "CANLIN") + if (itemCanLinGroup.Value.Group == "压缩机") { //尝试获取模型信息 - if (TagManger.TryGetPVModel(itemCanLinGroup.Key, out MeterValueAttrCell? pVModel)) + if (TagManger.TryGetCapPVModel(itemCanLinGroup.Key, out QuickAttrCell? pVModel)) { switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin) { @@ -2628,13 +2629,13 @@ namespace CapMachine.Wpf.Services //取得压缩机的CANLIN数据到数据集合中 pVModel!.EngValue = CanDriveService.GetDbcValueByName(itemCanLinGroup.Value.NameNoUnit); //写入到PLC中 - SiemensDrive.Write(pVModel!.Address, (short)(CanDriveService.GetDbcValueByName(itemCanLinGroup.Value.NameNoUnit) * pVModel.Precision)); + SiemensDrive.Write(pVModel!.Address!.Replace("W", ""), (short)(CanDriveService.GetDbcValueByName(itemCanLinGroup.Value.NameNoUnit))); break; case CanLinEnum.Lin: //取得压缩机的CANLIN数据 pVModel!.EngValue = LinDriveService.GetLdfValueByName(itemCanLinGroup.Value.NameNoUnit); //写入到PLC中 - SiemensDrive.Write(pVModel!.Address, (short)(LinDriveService.GetLdfValueByName(itemCanLinGroup.Value.NameNoUnit) * pVModel.Precision)); + SiemensDrive.Write(pVModel!.Address!.Replace("W", ""), (short)(LinDriveService.GetLdfValueByName(itemCanLinGroup.Value.NameNoUnit))); break; case CanLinEnum.No: break; @@ -3083,6 +3084,7 @@ namespace CapMachine.Wpf.Services break; } + //拓展参数 if (ProRunChannelData.ListStepExd != null && ProRunChannelData.ListStepExd.Count() > 0) { @@ -3102,7 +3104,8 @@ namespace CapMachine.Wpf.Services default: break; } - continue; + //Console.WriteLine($"{ProRunChannelData.MeterName}拓展参数------------:{itemStepExd.Name}:{itemStepExd.Value}"); + //continue; } var DataAdrees = ListPlcExdConfigCell.FirstOrDefault(a => a.Name == itemStepExd.Name); @@ -3111,12 +3114,15 @@ namespace CapMachine.Wpf.Services switch (itemStepExd.ValueType) { case ExdValueType.Bool: - var ResultBool = SiemensDrive.Write(DataAdrees.Address, (bool)itemStepExd.Value! == true ? 1 : 0); - if (!ResultBool.IsSuccess) Console.WriteLine($"{ProRunChannelData.MeterName}:{itemStepExd.Name}写入失败"); + //Console.WriteLine($"{ProRunChannelData.MeterName}拓展参数------------:{itemStepExd.Name}-{DataAdrees.Address}:{itemStepExd.Value}"); + var BoolVar = (bool)itemStepExd.Value!; + var ResultBool = SiemensDrive.Write(DataAdrees.Address, (short)(BoolVar! == true ? 1 : 0)); + if (!ResultBool.IsSuccess) Console.WriteLine($"{ProRunChannelData.MeterName} 拓展参数------------:{itemStepExd.Name}写入失败"); break; case ExdValueType.Short: + //Console.WriteLine($"{ProRunChannelData.MeterName}拓展参数------------:{itemStepExd.Name}-{DataAdrees.Address}:{itemStepExd.Value}"); var ResultShort = SiemensDrive.Write(DataAdrees.Address, (short)itemStepExd.Value!); - if (!ResultShort.IsSuccess) Console.WriteLine($"{ProRunChannelData.MeterName}:{itemStepExd.Name}写入失败"); + if (!ResultShort.IsSuccess) Console.WriteLine($"{ProRunChannelData.MeterName} 拓展参数------------:{itemStepExd.Name}写入失败"); break; case ExdValueType.Double: break; diff --git a/CapMachine.Wpf/Views/MonitorView.xaml b/CapMachine.Wpf/Views/MonitorView.xaml index ca8f167..e997c9a 100644 --- a/CapMachine.Wpf/Views/MonitorView.xaml +++ b/CapMachine.Wpf/Views/MonitorView.xaml @@ -1004,7 +1004,7 @@ VerticalAlignment="Center" CellTitle="转速" CellUnit="{Binding SpeedTag.Unit}" - CellValue="{Binding SpeedTag.EngPvValueStr}" /> + CellValue="{Binding SpeedTag.PVModel.EngValueStr}" /> + CellValue="{Binding ComCapBusVolTag.PVModel.EngValueStr}" /> + CellValue="{Binding ComCapBusCurTag.PVModel.EngValueStr}" /> + CellValue="{Binding ComCapPwTag.PVModel.EngValueStr}" /> + CellValue="{Binding ExPressTag.PVModel.EngValueStr}" /> + CellValue="{Binding ExTempTag.PVModel.EngValueStr}" /> + CellValue="{Binding InhPressTag.PVModel.EngValueStr}" /> + CellValue="{Binding InhTempTag.PVModel.EngValueStr}" />