Jelajahi Sumber

再次 故障消息 bug修改

LC 2 bulan lalu
induk
melakukan
25efd6efb8

+ 1 - 1
Config/Config.json

@@ -43,7 +43,7 @@
       "RopeNumber": 2,
       "RopeName": "起升钢丝绳3#",
       "IpAddress": "192.168.1.127",
-      "SerialNo": "2509002",
+      "SerialNo": "2508001",
       "Supplier": "宁夏恒力",
       "RopeCoreType": 1,
       "WireMaterialType": 1,

+ 4 - 5
Converters/ConnectivityFaultToColorConverter.cs

@@ -1,7 +1,6 @@
-using SWRIS.Enums;
-using SWRIS.Models;
+using SWRIS.Models;
 using System;
-using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.Globalization;
 using System.Linq;
 using System.Windows.Data;
@@ -17,13 +16,13 @@ namespace SWRIS.Converters
 
         public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
         {
-            if (values.Length < 2 || !(values[0] is bool isConnected) || !(values[1] is Dictionary<FaultType, FaultDataModel> faults))
+            if (values.Length < 2 || !(values[0] is bool isConnected) || !(values[1] is bool isFaulting))
                 return OfflineBrush;
 
             if (!isConnected)
                 return OfflineBrush;
 
-            if (faults != null && faults.Any(f => f.Value != null)) // 检查非空故障
+            if (isFaulting)
                 return FaultBrush;
 
             return OnlineBrush;

+ 1 - 33
MainWindow.xaml.cs

@@ -209,39 +209,7 @@ namespace SWRIS
         private void TcpServer_FaultDataReceived(object sender, FaultDataReceivedEventArgs e)
         {
             var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
-            if (equipmentData != null)
-            {
-                if (equipmentData.Faults.TryGetValue(e.FaultData.FaultType, out var faultData))
-                {
-                    if (e.FaultData.FaultCode == 0)
-                    {
-                        equipmentData.Faults.Remove(e.FaultData.FaultType);
-                    }
-                    else
-                    {
-                        equipmentData.Faults[e.FaultData.FaultType] = e.FaultData;
-                    }
-                }
-                else
-                {
-                    equipmentData.Faults.Add(e.FaultData.FaultType, e.FaultData);
-                }
-
-                Application.Current.Dispatcher.Invoke(() =>
-                {
-                    if (equipmentData.Messages.Any())
-                    {
-                        equipmentData.Messages.Clear();
-                    }
-                    foreach (var fault in equipmentData.Faults)
-                    {
-                        if (fault.Value != null)
-                        {
-                            equipmentData.Messages.Add(fault.Value.ToString());
-                        }
-                    }
-                });
-            }
+            equipmentData?.AddFault(e.FaultData);
         }
         /// <summary>
         /// 接收实时数据

+ 47 - 11
Models/EquipmentDataModel.cs

@@ -23,7 +23,6 @@ namespace SWRIS.Models
         private double ropeLength = 100f; // 默认长度为100米
         private RunningStatus runningStatus = RunningStatus.Stopped;
         private DirectionState direction;
-        private FaultType? faultType;
         private double speed;
         private double position;
         private double absolutePosition;
@@ -43,6 +42,7 @@ namespace SWRIS.Models
         private double samplingStep;
         private DebugMessageModel debugMessage = new DebugMessageModel(string.Empty);
         private bool isAlerting = false;
+        private bool isFaulting = false;
         private bool isSpeedStable = true;
         private double variationThreshold = 0.25;
         private bool isHeartbeatReceived;
@@ -50,7 +50,7 @@ namespace SWRIS.Models
         private bool disableAlarm;
         private int[] inUseSensor = new int[] { 1, 2, 3, 4 };
 
- 
+
         /// <summary>
         /// 钢丝绳绳号
         /// </summary>
@@ -136,15 +136,6 @@ namespace SWRIS.Models
             get => direction;
             set { direction = value; OnPropertyChanged(nameof(Direction)); }
         }
-        /// <summary>
-        /// 故障类型
-        /// </summary>
-        public FaultType? FaultType
-        {
-            get => faultType;
-            set { faultType = value; OnPropertyChanged(nameof(FaultType)); }
-        }
-
         /// <summary>
         /// 速度
         /// </summary>
@@ -305,6 +296,14 @@ namespace SWRIS.Models
             get => isAlerting;
             set { isAlerting = value; OnPropertyChanged(nameof(IsAlerting)); }
         }
+        /// <summary>
+        /// 是否故障中
+        /// </summary>
+        public bool IsFaulting
+        {
+            get => isFaulting;
+            set { isFaulting = value; OnPropertyChanged(nameof(IsFaulting)); }
+        }
         public bool IsHeartbeatReceived
         {
             get => isHeartbeatReceived;
@@ -350,13 +349,50 @@ namespace SWRIS.Models
             get => inUseSensor;
             set { inUseSensor = value; OnPropertyChanged(nameof(InUseSensor)); }
         }
+
         public ObservableCollection<AlarmDataModel> Alarms { get; set; } = new ObservableCollection<AlarmDataModel>();
         public Dictionary<FaultType, FaultDataModel> Faults { get; set; } = new Dictionary<FaultType, FaultDataModel>();
         public ObservableCollection<string> Messages { get; set; } = new ObservableCollection<string>();
         public ObservableCollection<LimitModel> Limits { get; set; } = new ObservableCollection<LimitModel>();
         public Coordinates[] ChartSource { get; internal set; }
         public Queue<double> RecentSpeeds { get; internal set; } = new Queue<double>();
+        public void AddFault(FaultDataModel faultData)
+        {
+            if (Faults.ContainsKey(faultData.FaultType))
+            {
+                if (faultData.FaultCode == 0)
+                {
+                    Faults.Remove(faultData.FaultType);
+                }
+                else
+                {
+                    Faults[faultData.FaultType] = faultData;
+                }
+            }
+            else if (faultData.FaultCode != 0)
+            {
+                Faults.Add(faultData.FaultType, faultData);
+            }
 
+            Application.Current.Dispatcher.Invoke(() =>
+            {
+                if (Messages.Any())
+                {
+                    Messages.Clear();
+                }
+                foreach (var fault in Faults)
+                {
+                    if (fault.Value != null)
+                    {
+                        Messages.Add(fault.Value.ToString());
+                    }
+                }
+            });
+            if (Messages.Any())
+                IsFaulting = true;
+            else
+                IsFaulting = false;
+        }
         public void AddSpeedData(double speed)
         {
             // 更新数据窗口

+ 4 - 1
Models/FaultDataModel.cs

@@ -31,7 +31,10 @@ namespace SWRIS.Models
             }
             else
             {
-                return $"第[{string.Join(",",FaultySensors)}]路传感器故障";
+                if (FaultySensors.Length == 0)
+                    return null;
+                else
+                    return $"第[{string.Join(",", FaultySensors)}]路传感器故障";
             }
         }
 

+ 5 - 11
Models/ViewModel/TwoRopesViewModel.cs

@@ -4,7 +4,7 @@
     {
         private EquipmentDataModel firstEquipmentData;
         private EquipmentDataModel secondEquipmentData;
-       
+
         public EquipmentModel FirstEquipment { get; set; }
         public EquipmentModel SecondEquipment { get; set; }
         public EquipmentDataModel FirstEquipmentData
@@ -12,11 +12,8 @@
             get => firstEquipmentData;
             set
             {
-                if (firstEquipmentData != value)
-                {
-                    firstEquipmentData = value;
-                    OnPropertyChanged(nameof(FirstEquipmentData));
-                }
+                firstEquipmentData = value;
+                OnPropertyChanged(nameof(FirstEquipmentData));
             }
         }
         public EquipmentDataModel SecondEquipmentData
@@ -24,11 +21,8 @@
             get => secondEquipmentData;
             set
             {
-                if (secondEquipmentData != value)
-                {
-                    secondEquipmentData = value;
-                    OnPropertyChanged(nameof(SecondEquipmentData));
-                }
+                secondEquipmentData = value;
+                OnPropertyChanged(nameof(SecondEquipmentData));
             }
         }
     }

+ 2 - 2
Pages/RealTime/TwoRopesPage.xaml

@@ -58,7 +58,7 @@
                             <Rectangle.Fill>
                                 <MultiBinding Converter="{StaticResource ConnectivityFaultConverter}">
                                     <Binding Path="IsConnect"/>
-                                    <Binding Path="Faults"/>
+                                    <Binding Path="IsFaulting"/>
                                 </MultiBinding>
                             </Rectangle.Fill>
                         </Rectangle>
@@ -173,7 +173,7 @@
                             <Rectangle.Fill>
                                 <MultiBinding Converter="{StaticResource ConnectivityFaultConverter}">
                                     <Binding Path="IsConnect"/>
-                                    <Binding Path="Faults"/>
+                                    <Binding Path="IsFaulting"/>
                                 </MultiBinding>
                             </Rectangle.Fill>
                         </Rectangle>

+ 1 - 4
Pages/RealTime/TwoRopesPage.xaml.cs

@@ -1,12 +1,9 @@
-using HslCommunication.Profinet.Panasonic.Helper;
-using SWRIS.Events;
+using SWRIS.Events;
 using SWRIS.Extensions;
 using SWRIS.Models.ViewModel;
 using SWRIS.Repository;
 using System.Linq;
-using System.Threading;
 using System.Threading.Tasks;
-using System.Windows;
 using System.Windows.Controls;
 
 namespace SWRIS.Pages.RealTime