Просмотр исходного кода

验证数值的大小及范围

LC 1 неделя назад
Родитель
Сommit
b2cd08c49b
4 измененных файлов с 40 добавлено и 53 удалено
  1. 10 10
      Mapping.cs
  2. 25 41
      Models/ViewModel/EquipmentSettingViewModel.cs
  3. 2 2
      Pages/ParameterDialog.xaml
  4. 3 0
      README.md

+ 10 - 10
Mapping.cs

@@ -52,32 +52,32 @@ namespace SWRIS
             var targetParam = equipmentModel.Parameter;
 
             targetParam.SensorCount = sourceParam.SensorCount;
-            targetParam.SamplingStep = sourceParam.SamplingStep;
+            targetParam.SamplingStep = (float)sourceParam.SamplingStep;
             targetParam.MainBoardSoftwareVersion = sourceParam.MainBoardSoftwareVersion;
             targetParam.FrequencyDivisionFactor = sourceParam.FrequencyDivisionFactor;
             targetParam.DamageInterval = sourceParam.DamageInterval;
             targetParam.DamageThreshold = sourceParam.DamageThreshold;
             targetParam.ScrapUpperLimit = sourceParam.ScrapUpperLimit;
             targetParam.BackMagnetLength = sourceParam.BackMagnetLength;
-            targetParam.ValueCoefficient = sourceParam.ValueCoefficient;
+            targetParam.ValueCoefficient = (float)sourceParam.ValueCoefficient;
             targetParam.FrontMagnetLength = sourceParam.FrontMagnetLength;
-            targetParam.EffectiveStrokeLength = sourceParam.EffectiveStrokeLength;
+            targetParam.EffectiveStrokeLength = (float)sourceParam.EffectiveStrokeLength;
             targetParam.ZeroPositionCorrectionOffset = sourceParam.ZeroPositionCorrectionOffset;
             targetParam.SoundLightAlarmAutoResetMode = sourceParam.SoundLightAlarmAutoResetMode;
             targetParam.ZeroPositionCorrectionDuration = sourceParam.ZeroPositionCorrectionDuration;
             targetParam.SystemTime = sourceParam.SystemTime;
-            targetParam.AlarmValue = sourceParam.AlarmValue;
-            targetParam.TwistFactor = sourceParam.TwistFactor;
-            targetParam.WarningValue = sourceParam.WarningValue;
+            targetParam.AlarmValue = (float)sourceParam.AlarmValue;
+            targetParam.TwistFactor = (float)sourceParam.TwistFactor;
+            targetParam.WarningValue = (float)sourceParam.WarningValue;
             targetParam.WireRopeType = sourceParam.WireRopeType;
             targetParam.WireRopeCount = sourceParam.WireRopeCount;
-            targetParam.WireRopeLength = sourceParam.WireRopeLength;
-            targetParam.WireRopeDiameter = sourceParam.WireRopeDiameter;
+            targetParam.WireRopeLength = (float)sourceParam.WireRopeLength;
+            targetParam.WireRopeDiameter = (float)sourceParam.WireRopeDiameter;
             targetParam.EncoderDirection = sourceParam.EncoderDirection;
             targetParam.WireRopeStrandCount = sourceParam.WireRopeStrandCount;
             targetParam.WireRopeStrandWireCount = sourceParam.WireRopeStrandWireCount;
-            targetParam.FirstCalibrationPositiont = sourceParam.FirstCalibrationPositiont;
-            targetParam.SecondCalibrationPositiont = sourceParam.SecondCalibrationPositiont;
+            targetParam.FirstCalibrationPositiont = (float)sourceParam.FirstCalibrationPositiont;
+            targetParam.SecondCalibrationPositiont = (float)sourceParam.SecondCalibrationPositiont;
         }
 
         // 可选:创建新实例的扩展方法

+ 25 - 41
Models/ViewModel/EquipmentSettingViewModel.cs

@@ -28,7 +28,7 @@ namespace SWRIS.Models.ViewModel
         private RunningStatus runningStatus = RunningStatus.SpatialNormal;
         private double hoistDrumDiameter = 750;
         private double encoderResolution = 1000;
-        private double ratedHeight;
+        private double ratedHeight = 20;
 
         /// <summary>
         /// 绳号
@@ -293,7 +293,7 @@ namespace SWRIS.Models.ViewModel
             {
                 return;
             }
-            parameter.SamplingStep = (float)(Math.PI * hoistDrumDiameter * parameter.FrequencyDivisionFactor / encoderResolution);
+            parameter.SamplingStep = Math.Round(Math.PI * hoistDrumDiameter * parameter.FrequencyDivisionFactor / encoderResolution, 5);
         }
 
         /// <summary>
@@ -312,8 +312,6 @@ namespace SWRIS.Models.ViewModel
         public List<KeyAndValueDto> WireSurfaceTypes => TypeExtension.ToKeyAndDescriptionList(typeof(WireSurfaceType));
         public List<KeyAndValueDto> RiskLevels => TypeExtension.ToKeyAndDescriptionList(typeof(RiskLevel));
 
-
-
         public event PropertyChangedEventHandler PropertyChanged;
         protected internal virtual void OnPropertyChanged(string propertyName)
         {
@@ -324,31 +322,31 @@ namespace SWRIS.Models.ViewModel
     {
         private string mainBoardSoftwareVersion;
         private short sensorCount;
-        private float samplingStep;
+        private double samplingStep;
         private short frequencyDivisionFactor;
         private short damageInterval;
         private short damageThreshold;
         private short scrapUpperLimit;
         private short frontMagnetLength;
         private short backMagnetLength;
-        private float valueCoefficient;
-        private float effectiveStrokeLength;
+        private double valueCoefficient;
+        private double effectiveStrokeLength;
         private short zeroPositionCorrectionDuration;
         private short zeroPositionCorrectionOffset;
-        private float warningValue;
-        private float alarmValue;
+        private double warningValue;
+        private double alarmValue;
         private short soundLightAlarmAutoResetMode;
         private short wireRopeType;
         private short wireRopeCount;
-        private float wireRopeLength;
-        private float wireRopeDiameter;
+        private double wireRopeLength;
+        private double wireRopeDiameter;
         private short wireRopeStrandCount;
         private short wireRopeStrandWireCount;
         private EncoderDirection encoderDirection;
         private DateTime? systemTime;
-        private float twistFactor;
-        private float firstCalibrationPositiont;
-        private float secondCalibrationPositiont;
+        private double twistFactor;
+        private double firstCalibrationPositiont;
+        private double secondCalibrationPositiont;
 
 
         /// <summary>
@@ -378,7 +376,7 @@ namespace SWRIS.Models.ViewModel
         /// <summary>
         /// 采样步长 单位:mm/点   4字节浮点数
         /// </summary>
-        public float SamplingStep
+        public double SamplingStep
         {
             get => samplingStep;
             set
@@ -387,6 +385,7 @@ namespace SWRIS.Models.ViewModel
                 OnPropertyChanged(nameof(SamplingStep));
             }
         }
+
         /// <summary>
         /// 分频系数
         /// </summary>
@@ -462,7 +461,7 @@ namespace SWRIS.Models.ViewModel
         /// <summary>
         /// 量值系数  4字节浮点数
         /// </summary>
-        public float ValueCoefficient
+        public double ValueCoefficient
         {
             get => valueCoefficient;
             set
@@ -474,7 +473,7 @@ namespace SWRIS.Models.ViewModel
         /// <summary>
         /// 零位有效行程长度,单位:m  4字节浮点数
         /// </summary>
-        public float EffectiveStrokeLength
+        public double EffectiveStrokeLength
         {
             get => effectiveStrokeLength;
             set
@@ -510,7 +509,7 @@ namespace SWRIS.Models.ViewModel
         /// <summary>
         /// 预警(黄色报警)量值  4字节浮点数
         /// </summary>
-        public float WarningValue
+        public double WarningValue
         {
             get => warningValue;
             set
@@ -522,7 +521,7 @@ namespace SWRIS.Models.ViewModel
         /// <summary>
         /// 报警(红色报警)量值  4字节浮点数
         /// </summary>
-        public float AlarmValue
+        public double AlarmValue
         {
             get => alarmValue;
             set
@@ -570,36 +569,21 @@ namespace SWRIS.Models.ViewModel
         /// <summary>
         /// 钢丝绳长度,单位:m  4字节浮点数(供协议打包/持久化使用)
         /// </summary>
-        public float WireRopeLength
+        public double WireRopeLength
         {
             get => wireRopeLength;
             set
             {
                 // 统一保留 2 位小数,避免浮点运算产生冗长小数位
-                wireRopeLength = (float)Math.Round(value, 2, MidpointRounding.AwayFromZero);
-                OnPropertyChanged(nameof(WireRopeLength));
-                OnPropertyChanged(nameof(WireRopeLengthValue));
-            }
-        }
-        /// <summary>
-        /// 钢丝绳长度(double 显示值,供输入框绑定)。
-        /// float 转 double 会产生二进制噪声(如 41.2f → 41.200000762939453),
-        /// 故暴露 double 值并四舍五入到 2 位小数后再绑定。
-        /// </summary>
-        public double WireRopeLengthValue
-        {
-            get => Math.Round(wireRopeLength, 2);
-            set
-            {
-                wireRopeLength = (float)Math.Round(value, 2, MidpointRounding.AwayFromZero);
+                wireRopeLength = Math.Round(value, 2, MidpointRounding.AwayFromZero);
                 OnPropertyChanged(nameof(WireRopeLength));
-                OnPropertyChanged(nameof(WireRopeLengthValue));
             }
         }
+
         /// <summary>
         /// 钢丝绳直径,单位:mm  4字节浮点数
         /// </summary>
-        public float WireRopeDiameter
+        public double WireRopeDiameter
         {
             get => wireRopeDiameter;
             set
@@ -660,7 +644,7 @@ namespace SWRIS.Models.ViewModel
         /// 判伤捻距系数,浮点数,判伤捻距默认为7d,可通过此参数设置系数来调整(与损伤判定相关)。
         /// 默认值为1.0,设置2.0表示判伤捻距为2 x 7 = 14d
         /// </summary>
-        public float TwistFactor
+        public double TwistFactor
         {
             get => twistFactor;
             set
@@ -673,7 +657,7 @@ namespace SWRIS.Models.ViewModel
         /// <summary>
         ///  限位1校准位置
         /// </summary>
-        public float FirstCalibrationPositiont
+        public double FirstCalibrationPositiont
         {
             get => firstCalibrationPositiont;
             set
@@ -685,7 +669,7 @@ namespace SWRIS.Models.ViewModel
         /// <summary>
         /// 限位2校准位置
         /// </summary>
-        public float SecondCalibrationPositiont
+        public double SecondCalibrationPositiont
         {
             get => secondCalibrationPositiont;
             set

+ 2 - 2
Pages/ParameterDialog.xaml

@@ -177,14 +177,14 @@
                                 <TextBlock Text="长度" VerticalAlignment="Center"/>
                                 <StackPanel Orientation="Horizontal"  Margin="0,0,4,0">
                                     <pu:NumberInput Margin="15,0,6,0" Width="110" 
-                                                    Value="{Binding Parameter.WireRopeLengthValue}" Minimum="1"/>
+                                                    Value="{Binding Parameter.WireRopeLength}" Minimum="1"/>
                                     <TextBlock Text="m" Width="45" VerticalAlignment="Center"/>
                                 </StackPanel>
                             </StackPanel>
                             <StackPanel Orientation="Horizontal" Margin="0,7"  HorizontalAlignment="Right">
                                 <TextBlock Text="采样步长" VerticalAlignment="Center"/>
                                 <StackPanel Orientation="Horizontal"  Margin="0,0,4,0">
-                                    <TextBox Margin="15,0,6,0" Width="110" Text="{Binding Parameter.SamplingStep}"/>
+                                    <pu:NumberInput Margin="15,0,6,0" Width="110" Value="{Binding Parameter.SamplingStep}" Minimum="0"/>
                                     <TextBlock  Text="mm" Width="45" VerticalAlignment="Center"/>
                                 </StackPanel>
                             </StackPanel>

+ 3 - 0
README.md

@@ -9,6 +9,9 @@
 - **修改检测模式**
   - 去掉原来的停止检测按钮,优化点击事件,避免重复发送指令。
   - 时域检测时起升高度保持为0m
+- **修改检测模式**
+  - 增加卷筒直径、额定高度、编码器分辨率、供应商等参数
+  - 自动计算步长和钢丝绳长度
 ## 版本 1.2.0 - 2026-8-17
 
 ### 新增功能