From 634e11c325d6548587ebf54af021848a802ade1f Mon Sep 17 00:00:00 2001 From: wanglei Date: Sat, 5 Dec 2026 20:02:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E5=88=AB=E5=88=B7=E6=96=B0=E5=92=8C?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=B0=94=E7=BC=B8=20A/B=20=E4=BD=8D=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PLCSharpWpf/VVMs/Cylinders/Cylinder.cs | 4 +-- PLCSharpWpf/VVMs/Cylinders/CylinderModel.cs | 3 ++ PLCSharpWpf/VVMs/Cylinders/Cylinders.xaml | 2 +- .../PLCSharp.Tests/CylinderRegressionTests.cs | 28 +++++++++++++++++++ Tests/PLCSharp.Tests/PLCSharp.Tests.csproj | 1 + 5 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 Tests/PLCSharp.Tests/CylinderRegressionTests.cs diff --git a/PLCSharpWpf/VVMs/Cylinders/Cylinder.cs b/PLCSharpWpf/VVMs/Cylinders/Cylinder.cs index 42159ce..426d6c4 100644 --- a/PLCSharpWpf/VVMs/Cylinders/Cylinder.cs +++ b/PLCSharpWpf/VVMs/Cylinders/Cylinder.cs @@ -323,13 +323,13 @@ namespace PLCSharp.VVMs.Cylinders private bool _StatusBOut; /// - /// A位输出状态 + /// B位输出状态 /// [NotMapped] public bool StatusBOut { get { return _StatusBOut; } - set { SetProperty(ref _StatusAOut, value); } + set { SetProperty(ref _StatusBOut, value); } } private string _FaultCode; diff --git a/PLCSharpWpf/VVMs/Cylinders/CylinderModel.cs b/PLCSharpWpf/VVMs/Cylinders/CylinderModel.cs index 7155d1f..9db09cd 100644 --- a/PLCSharpWpf/VVMs/Cylinders/CylinderModel.cs +++ b/PLCSharpWpf/VVMs/Cylinders/CylinderModel.cs @@ -82,6 +82,9 @@ namespace PLCSharp.VVMs.Cylinders list[i].DQB = controller.DQ.FirstOrDefault(d => d.Name == list[i].OutB); } + list[i].StatusAOut = !string.IsNullOrEmpty(list[i].OutA) && list[i].DQA?.Status == true; + list[i].StatusBOut = !string.IsNullOrEmpty(list[i].OutB) && list[i].DQB?.Status == true; + //气缸功能块 FB(list[i]); diff --git a/PLCSharpWpf/VVMs/Cylinders/Cylinders.xaml b/PLCSharpWpf/VVMs/Cylinders/Cylinders.xaml index 972a53a..8ec6e1d 100644 --- a/PLCSharpWpf/VVMs/Cylinders/Cylinders.xaml +++ b/PLCSharpWpf/VVMs/Cylinders/Cylinders.xaml @@ -102,7 +102,7 @@ FontSize="14" FontWeight="Bold" Content="B 位" Command="{Binding CylinderAction}" - Background="{Binding SelectedCylinder.StatusAOut, Converter={StaticResource BoolToValueConverter}, ConverterParameter=Lime, FallbackValue=Gray}" + Background="{Binding SelectedCylinder.StatusBOut, Converter={StaticResource BoolToValueConverter}, ConverterParameter=Lime, FallbackValue=Gray}" CommandParameter="B" /> diff --git a/Tests/PLCSharp.Tests/CylinderRegressionTests.cs b/Tests/PLCSharp.Tests/CylinderRegressionTests.cs new file mode 100644 index 0000000..8edeebd --- /dev/null +++ b/Tests/PLCSharp.Tests/CylinderRegressionTests.cs @@ -0,0 +1,28 @@ +using PLCSharp.VVMs.Cylinders; +using System.Xml.Linq; + +namespace PLCSharp.Tests; + +public class CylinderRegressionTests +{ + [Fact] + public void OutputStatesAndButtonBindingsAreIndependent() + { + var cylinder = new Cylinder { StatusBOut = true }; + Assert.True(cylinder.StatusBOut); + Assert.False(cylinder.StatusAOut); + cylinder.StatusAOut = true; + cylinder.StatusBOut = false; + Assert.True(cylinder.StatusAOut); + Assert.False(cylinder.StatusBOut); + + using var resource = typeof(CylinderRegressionTests).Assembly.GetManifestResourceStream("Cylinders.xaml"); + var view = XDocument.Load(resource!); + foreach (var side in new[] { "A", "B" }) + { + var button = view.Descendants(view.Root!.Name.Namespace + "Button") + .Single(b => (string?)b.Attribute("CommandParameter") == side); + Assert.Contains($"SelectedCylinder.Status{side}Out,", (string?)button.Attribute("Background")); + } + } +} diff --git a/Tests/PLCSharp.Tests/PLCSharp.Tests.csproj b/Tests/PLCSharp.Tests/PLCSharp.Tests.csproj index 4d58a0f..9c8a434 100644 --- a/Tests/PLCSharp.Tests/PLCSharp.Tests.csproj +++ b/Tests/PLCSharp.Tests/PLCSharp.Tests.csproj @@ -11,6 +11,7 @@ +