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 @@
+