From da107f3b89271191052d9ece45e0010bb2d7d795 Mon Sep 17 00:00:00 2001
From: 啊鑫 <t2856754968@163.com>
Date: 星期六, 26 七月 2025 15:41:40 +0800
Subject: [PATCH] 修复Oracle数据库列名映射错误和空引用异常

---
 Database/DatabaseEntities.cs |  112 ++++++++++++++++++------------------
 UniversalModbusManager.cs    |   42 +++++++++++++
 config/ModbusDataParser.cs   |   19 ++++++
 3 files changed, 114 insertions(+), 59 deletions(-)

diff --git a/Database/DatabaseEntities.cs b/Database/DatabaseEntities.cs
index 31e3957..9dee393 100644
--- a/Database/DatabaseEntities.cs
+++ b/Database/DatabaseEntities.cs
@@ -5,7 +5,7 @@
     /// <summary>
     /// Modbus涓绘暟鎹疄浣� - 瀛樺偍浠嶱LC璇诲彇鐨勬暟鎹�
     /// </summary>
-    [SugarTable("ModbusData")]
+    [SugarTable("PRODUCTION_DATA")]
     public class ModbusDataEntity
     {
         /// <summary>
@@ -17,56 +17,56 @@
         /// <summary>
         /// 鏁版嵁璇诲彇鏃堕棿
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "鏁版嵁璇诲彇鏃堕棿")]
+        [SugarColumn(ColumnName = "READ_TIME", IsNullable = true, ColumnDescription = "鏁版嵁璇诲彇鏃堕棿")]
         public DateTime? ReadTime { get; set; }
 
         /// <summary>
         /// 椤圭洰鍚嶇О锛堟潵鑷厤缃級
         /// </summary>
-        [SugarColumn(Length = 100, IsNullable = true, ColumnDescription = "椤圭洰鍚嶇О")]
+        [SugarColumn(ColumnName = "PROJECT_NAME", Length = 100, IsNullable = true, ColumnDescription = "椤圭洰鍚嶇О")]
         public string? ProjectName { get; set; } 
 
         /// <summary>
         /// PLC IP鍦板潃
         /// </summary>
-        [SugarColumn(Length = 50, IsNullable = true, ColumnDescription = "PLC IP鍦板潃")]
+        [SugarColumn(ColumnName = "PLC_IP_ADDRESS", Length = 50, IsNullable = true, ColumnDescription = "PLC IP鍦板潃")]
         public string? PlcIpAddress { get; set; } 
 
         /// <summary>
         /// 鎺у埗淇″彿鏁版嵁锛圝SON鏍煎紡锛�
         /// </summary>
-        [SugarColumn(ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "鎺у埗淇″彿鏁版嵁JSON")]
+        [SugarColumn(ColumnName = "CONTROL_SIGNALS_JSON", ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "鎺у埗淇″彿鏁版嵁JSON")]
         public string? ControlSignalsJson { get; set; }
 
         /// <summary>
         /// 浜у搧鏁版嵁锛圝SON鏍煎紡锛�
         /// </summary>
-        [SugarColumn(ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "浜у搧鏁版嵁JSON")]
+        [SugarColumn(ColumnName = "PRODUCT_DATA_JSON", ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "浜у搧鏁版嵁JSON")]
         public string? ProductDataJson { get; set; }
 
         /// <summary>
         /// 娴嬮噺鏁版嵁锛圝SON鏍煎紡锛�
         /// </summary>
-        [SugarColumn(ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "娴嬮噺鏁版嵁JSON")]
+        [SugarColumn(ColumnName = "MEASUREMENT_DATA_JSON", ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "娴嬮噺鏁版嵁JSON")]
         public string? MeasurementDataJson { get; set; }
 
         /// <summary>
         /// 鍘熷瀵勫瓨鍣ㄦ暟鎹紙JSON鏍煎紡锛岀敤浜庤皟璇曪級
         /// </summary>
-        [SugarColumn(ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "鍘熷瀵勫瓨鍣ㄦ暟鎹甁SON")]
+        [SugarColumn(ColumnName = "RAW_REGISTERS_JSON", ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "鍘熷瀵勫瓨鍣ㄦ暟鎹甁SON")]
         public string? RawRegistersJson { get; set; }
 
         /// <summary>
         /// 鏁版嵁鍒涘缓鏃堕棿
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "璁板綍鍒涘缓鏃堕棿")]
+        [SugarColumn(ColumnName = "CREATED_AT", IsNullable = true, ColumnDescription = "璁板綍鍒涘缓鏃堕棿")]
         public DateTime? CreatedAt { get; set; } = DateTime.Now;
     }
 
     /// <summary>
     /// 閫氫俊鏃ュ織瀹炰綋 - 璁板綍閫氫俊鐘舵�佸拰缁熻淇℃伅
     /// </summary>
-    [SugarTable("CommunicationLog")]
+    [SugarTable("COMMUNICATION_LOG")]
     public class CommunicationLogEntity
     {
         /// <summary>
@@ -78,56 +78,56 @@
         /// <summary>
         /// 鏃ュ織鏃堕棿
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "鏃ュ織鏃堕棿")]
+        [SugarColumn(ColumnName = "LOG_TIME", IsNullable = true, ColumnDescription = "鏃ュ織鏃堕棿")]
         public DateTime? LogTime { get; set; }
 
         /// <summary>
         /// 椤圭洰鍚嶇О
         /// </summary>
-        [SugarColumn(Length = 100, IsNullable = true, ColumnDescription = "椤圭洰鍚嶇О")]
+        [SugarColumn(ColumnName = "PROJECT_NAME", Length = 100, IsNullable = true, ColumnDescription = "椤圭洰鍚嶇О")]
         public string? ProjectName { get; set; }
 
         /// <summary>
         /// PLC IP鍦板潃
         /// </summary>
-        [SugarColumn(Length = 50, IsNullable = true, ColumnDescription = "PLC IP鍦板潃")]
+        [SugarColumn(ColumnName = "PLC_IP_ADDRESS", Length = 50, IsNullable = true, ColumnDescription = "PLC IP鍦板潃")]
         public string? PlcIpAddress { get; set; } 
 
         /// <summary>
         /// 浜嬩欢绫诲瀷锛圕onnected, Disconnected, DataReceived, Error绛夛級
         /// </summary>
-        [SugarColumn(Length = 50, IsNullable = true, ColumnDescription = "浜嬩欢绫诲瀷")]
+        [SugarColumn(ColumnName = "EVENT_TYPE", Length = 50, IsNullable = true, ColumnDescription = "浜嬩欢绫诲瀷")]
         public string? EventType { get; set; }
 
         /// <summary>
         /// 浜嬩欢鎻忚堪
         /// </summary>
-        [SugarColumn(Length = 500, IsNullable = true, ColumnDescription = "浜嬩欢鎻忚堪")]
+        [SugarColumn(ColumnName = "EVENT_DESCRIPTION", Length = 500, IsNullable = true, ColumnDescription = "浜嬩欢鎻忚堪")]
         public string? EventDescription { get; set; }
 
         /// <summary>
         /// 鏄惁鎴愬姛
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "鏄惁鎴愬姛")]
+        [SugarColumn(ColumnName = "IS_SUCCESS", IsNullable = true, ColumnDescription = "鏄惁鎴愬姛")]
         public bool? IsSuccess { get; set; }
 
         /// <summary>
         /// 鑰楁椂锛堟绉掞級
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "鎿嶄綔鑰楁椂姣")]
+        [SugarColumn(ColumnName = "DURATION_MS", IsNullable = true, ColumnDescription = "鎿嶄綔鑰楁椂姣")]
         public int? DurationMs { get; set; }
 
         /// <summary>
         /// 闄勫姞鏁版嵁锛圝SON鏍煎紡锛�
         /// </summary>
-        [SugarColumn(ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "闄勫姞鏁版嵁JSON")]
+        [SugarColumn(ColumnName = "ADDITIONAL_DATA_JSON", ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "闄勫姞鏁版嵁JSON")]
         public string? AdditionalDataJson { get; set; }
     }
 
     /// <summary>
     /// 閿欒鏃ュ織瀹炰綋 - 璁板綍閫氫俊鍜屽鐞嗛敊璇�
     /// </summary>
-    [SugarTable("ErrorLog")]
+    [SugarTable("ERROR_LOG")]
     public class ErrorLogEntity
     {
         /// <summary>
@@ -139,61 +139,61 @@
         /// <summary>
         /// 閿欒鍙戠敓鏃堕棿
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "閿欒鍙戠敓鏃堕棿")]
+        [SugarColumn(ColumnName = "ERROR_TIME", IsNullable = true, ColumnDescription = "閿欒鍙戠敓鏃堕棿")]
         public DateTime? ErrorTime { get; set; }
 
         /// <summary>
         /// 椤圭洰鍚嶇О
         /// </summary>
-        [SugarColumn(Length = 100, IsNullable = true, ColumnDescription = "椤圭洰鍚嶇О")]
+        [SugarColumn(ColumnName = "PROJECT_NAME", Length = 100, IsNullable = true, ColumnDescription = "椤圭洰鍚嶇О")]
         public string? ProjectName { get; set; } 
         /// <summary>
         /// PLC IP鍦板潃
         /// </summary>
-        [SugarColumn(Length = 50, IsNullable = true, ColumnDescription = "PLC IP鍦板潃")]
+        [SugarColumn(ColumnName = "PLC_IP_ADDRESS", Length = 50, IsNullable = true, ColumnDescription = "PLC IP鍦板潃")]
         public string? PlcIpAddress { get; set; }
 
         /// <summary>
         /// 閿欒绫诲瀷
         /// </summary>
-        [SugarColumn(Length = 100, IsNullable = true, ColumnDescription = "閿欒绫诲瀷")]
+        [SugarColumn(ColumnName = "ERROR_TYPE", Length = 100, IsNullable = true, ColumnDescription = "閿欒绫诲瀷")]
         public string? ErrorType { get; set; }
 
         /// <summary>
         /// 閿欒娑堟伅
         /// </summary>
-        [SugarColumn(Length = 1000, IsNullable = true, ColumnDescription = "閿欒娑堟伅")]
+        [SugarColumn(ColumnName = "ERROR_MESSAGE", Length = 1000, IsNullable = true, ColumnDescription = "閿欒娑堟伅")]
         public string? ErrorMessage { get; set; }
 
         /// <summary>
         /// 寮傚父鍫嗘爤淇℃伅
         /// </summary>
-        [SugarColumn(ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "寮傚父鍫嗘爤淇℃伅")]
+        [SugarColumn(ColumnName = "STACK_TRACE", ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "寮傚父鍫嗘爤淇℃伅")]
         public string? StackTrace { get; set; }
 
         /// <summary>
         /// 閿欒涓ラ噸绾у埆锛圕ritical, High, Medium, Low锛�
         /// </summary>
-        [SugarColumn(Length = 20, IsNullable = true, ColumnDescription = "閿欒涓ラ噸绾у埆")]
+        [SugarColumn(ColumnName = "SEVERITY", Length = 20, IsNullable = true, ColumnDescription = "閿欒涓ラ噸绾у埆")]
         public string? Severity { get; set; } = "Medium";
 
         /// <summary>
         /// 閲嶈瘯娆℃暟
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "閲嶈瘯娆℃暟")]
+        [SugarColumn(ColumnName = "RETRY_COUNT", IsNullable = true, ColumnDescription = "閲嶈瘯娆℃暟")]
         public int? RetryCount { get; set; } = 0;
 
         /// <summary>
         /// 鏄惁宸茶В鍐�
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "鏄惁宸茶В鍐�")]
+        [SugarColumn(ColumnName = "IS_RESOLVED", IsNullable = true, ColumnDescription = "鏄惁宸茶В鍐�")]
         public bool? IsResolved { get; set; } = false;
     }
 
     /// <summary>
     /// 缁熻鏁版嵁瀹炰綋 - 璁板綍閫氫俊缁熻淇℃伅
     /// </summary>
-    [SugarTable("Statistics")]
+    [SugarTable("STATISTICS")]
     public class StatisticsEntity
     {
         /// <summary>
@@ -205,91 +205,91 @@
         /// <summary>
         /// 缁熻鏃堕棿
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "缁熻鏃堕棿")]
+        [SugarColumn(ColumnName = "STATISTICS_TIME", IsNullable = true, ColumnDescription = "缁熻鏃堕棿")]
         public DateTime? StatisticsTime { get; set; }
 
         /// <summary>
         /// 椤圭洰鍚嶇О
         /// </summary>
-        [SugarColumn(Length = 100, IsNullable = true, ColumnDescription = "椤圭洰鍚嶇О")]
+        [SugarColumn(ColumnName = "PROJECT_NAME", Length = 100, IsNullable = true, ColumnDescription = "椤圭洰鍚嶇О")]
         public string? ProjectName { get; set; } 
 
         /// <summary>
         /// PLC IP鍦板潃
         /// </summary>
-        [SugarColumn(Length = 50, IsNullable = true, ColumnDescription = "PLC IP鍦板潃")]
+        [SugarColumn(ColumnName = "PLC_IP_ADDRESS", Length = 50, IsNullable = true, ColumnDescription = "PLC IP鍦板潃")]
         public string? PlcIpAddress { get; set; }
 
         /// <summary>
         /// 杩炴帴灏濊瘯鎬绘暟
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "杩炴帴灏濊瘯鎬绘暟")]
+        [SugarColumn(ColumnName = "TOTAL_CONNECTION_ATTEMPTS", IsNullable = true, ColumnDescription = "杩炴帴灏濊瘯鎬绘暟")]
         public int? TotalConnectionAttempts { get; set; }
 
         /// <summary>
         /// 杩炴帴鎴愬姛鎬绘暟
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "杩炴帴鎴愬姛鎬绘暟")]
+        [SugarColumn(ColumnName = "SUCCESSFUL_CONNECTIONS", IsNullable = true, ColumnDescription = "杩炴帴鎴愬姛鎬绘暟")]
         public int? SuccessfulConnections { get; set; }
 
         /// <summary>
         /// 鏁版嵁璇诲彇鎬绘暟
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "鏁版嵁璇诲彇鎬绘暟")]
+        [SugarColumn(ColumnName = "TOTAL_DATA_READS", IsNullable = true, ColumnDescription = "鏁版嵁璇诲彇鎬绘暟")]
         public int? TotalDataReads { get; set; }
 
         /// <summary>
         /// 鏁版嵁璇诲彇鎴愬姛鎬绘暟
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "鏁版嵁璇诲彇鎴愬姛鎬绘暟")]
+        [SugarColumn(ColumnName = "SUCCESSFUL_DATA_READS", IsNullable = true, ColumnDescription = "鏁版嵁璇诲彇鎴愬姛鎬绘暟")]
         public int? SuccessfulDataReads { get; set; }
 
         /// <summary>
         /// 閿欒鎬绘暟
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "閿欒鎬绘暟")]
+        [SugarColumn(ColumnName = "TOTAL_ERRORS", IsNullable = true, ColumnDescription = "閿欒鎬绘暟")]
         public int? TotalErrors { get; set; }
 
         /// <summary>
         /// 骞冲潎鍝嶅簲鏃堕棿锛堟绉掞級
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "骞冲潎鍝嶅簲鏃堕棿姣")]
+        [SugarColumn(ColumnName = "AVERAGE_RESPONSE_TIME_MS", IsNullable = true, ColumnDescription = "骞冲潎鍝嶅簲鏃堕棿姣")]
         public double? AverageResponseTimeMs { get; set; }
 
         /// <summary>
         /// 鏈�澶у搷搴旀椂闂达紙姣锛�
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "鏈�澶у搷搴旀椂闂存绉�")]
+        [SugarColumn(ColumnName = "MAX_RESPONSE_TIME_MS", IsNullable = true, ColumnDescription = "鏈�澶у搷搴旀椂闂存绉�")]
         public int? MaxResponseTimeMs { get; set; }
 
         /// <summary>
         /// 鏈�灏忓搷搴旀椂闂达紙姣锛�
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "鏈�灏忓搷搴旀椂闂存绉�")]
+        [SugarColumn(ColumnName = "MIN_RESPONSE_TIME_MS", IsNullable = true, ColumnDescription = "鏈�灏忓搷搴旀椂闂存绉�")]
         public int? MinResponseTimeMs { get; set; }
 
         /// <summary>
         /// 杩炴帴鎴愬姛鐜�
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "杩炴帴鎴愬姛鐜�")]
+        [SugarColumn(ColumnName = "CONNECTION_SUCCESS_RATE", IsNullable = true, ColumnDescription = "杩炴帴鎴愬姛鐜�")]
         public double? ConnectionSuccessRate { get; set; }
 
         /// <summary>
         /// 鏁版嵁璇诲彇鎴愬姛鐜�
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "鏁版嵁璇诲彇鎴愬姛鐜�")]
+        [SugarColumn(ColumnName = "DATA_READ_SUCCESS_RATE", IsNullable = true, ColumnDescription = "鏁版嵁璇诲彇鎴愬姛鐜�")]
         public double? DataReadSuccessRate { get; set; }
 
         /// <summary>
         /// 缁熻鏃堕棿鑼冨洿寮�濮�
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "缁熻鏃堕棿鑼冨洿寮�濮�")]
+        [SugarColumn(ColumnName = "PERIOD_START", IsNullable = true, ColumnDescription = "缁熻鏃堕棿鑼冨洿寮�濮�")]
         public DateTime? PeriodStart { get; set; }
 
         /// <summary>
         /// 缁熻鏃堕棿鑼冨洿缁撴潫
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDescription = "缁熻鏃堕棿鑼冨洿缁撴潫")]
+        [SugarColumn(ColumnName = "PERIOD_END", IsNullable = true, ColumnDescription = "缁熻鏃堕棿鑼冨洿缁撴潫")]
         public DateTime? PeriodEnd { get; set; }
     }
 
@@ -298,14 +298,14 @@
     /// </summary>
     public static class EventTypes
     {
-        public const string? Connected = "Connected";
-        public const string? Disconnected = "Disconnected";
-        public const string? DataReceived = "DataReceived";
-        public const string? ConnectionError = "ConnectionError";
-        public const string? DataReadError = "DataReadError";
-        public const string? ConfigurationLoaded = "ConfigurationLoaded";
-        public const string? SystemStarted = "SystemStarted";
-        public const string? SystemStopped = "SystemStopped";
+        public const string Connected = "Connected";
+        public const string Disconnected = "Disconnected";
+        public const string DataReceived = "DataReceived";
+        public const string ConnectionError = "ConnectionError";
+        public const string DataReadError = "DataReadError";
+        public const string ConfigurationLoaded = "ConfigurationLoaded";
+        public const string SystemStarted = "SystemStarted";
+        public const string SystemStopped = "SystemStopped";
     }
 
     /// <summary>
@@ -313,9 +313,9 @@
     /// </summary>
     public static class ErrorSeverity
     {
-        public const string? Critical = "Critical";  // 绯荤粺鏃犳硶缁х画杩愯
-        public const string? High = "High";          // 鍔熻兘鍙楀埌涓ラ噸褰卞搷
-        public const string? Medium = "Medium";      // 鍔熻兘鍙楀埌褰卞搷浣嗗彲缁х画
-        public const string? Low = "Low";            // 杞诲井闂锛屼笉褰卞搷涓昏鍔熻兘
+        public const string Critical = "Critical";  // 绯荤粺鏃犳硶缁х画杩愯
+        public const string High = "High";          // 鍔熻兘鍙楀埌涓ラ噸褰卞搷
+        public const string Medium = "Medium";      // 鍔熻兘鍙楀埌褰卞搷浣嗗彲缁х画
+        public const string Low = "Low";            // 杞诲井闂锛屼笉褰卞搷涓昏鍔熻兘
     }
 }
\ No newline at end of file
diff --git a/UniversalModbusManager.cs b/UniversalModbusManager.cs
index 716ab0e..53d4fbe 100644
--- a/UniversalModbusManager.cs
+++ b/UniversalModbusManager.cs
@@ -501,7 +501,23 @@
         /// <param name="groupName">缁勫悕绉帮紙鐢ㄤ簬鏃ュ織锛�</param>
         private async Task ReadFieldGroup(DynamicModbusData dynamicData, Dictionary<string, DataField> fieldGroup, string groupName)
         {
-            if (_modbusClient == null) return;
+            if (_modbusClient == null)
+            {
+                LogWarning($"Modbus瀹㈡埛绔负null锛屾棤娉曡鍙� {groupName}");
+                return;
+            }
+
+            if (!_isConnected)
+            {
+                LogWarning($"Modbus鏈繛鎺ワ紝鏃犳硶璇诲彇 {groupName}");
+                return;
+            }
+
+            if (fieldGroup == null || fieldGroup.Count == 0)
+            {
+                LogDebug($"{groupName} 娌℃湁閰嶇疆瀛楁锛岃烦杩囪鍙�");
+                return;
+            }
 
             foreach (var kvp in fieldGroup)
             {
@@ -510,14 +526,28 @@
 
                 try
                 {
+                    // 妫�鏌odbus瀹㈡埛绔姸鎬�
+                    if (_modbusClient == null || !_modbusClient.Connected)
+                    {
+                        LogWarning($"Modbus瀹㈡埛绔湭杩炴帴锛岃烦杩囧瓧娈� '{fieldName}'");
+                        continue;
+                    }
+
                     // 璇诲彇鍘熷瀵勫瓨鍣ㄦ暟鎹�
                     var registers = await Task.Run(() => 
                         _modbusClient.ReadHoldingRegisters(fieldConfig.Address, fieldConfig.Length));
 
+                    // 妫�鏌ヨ鍙栫粨鏋滄槸鍚︿负null
+                    if (registers == null)
+                    {
+                        LogWarning($"瀛楁 '{fieldName}' 璇诲彇缁撴灉涓簄ull锛屽湴鍧�: {fieldConfig.Address}, 闀垮害: {fieldConfig.Length}");
+                        continue;
+                    }
+
                     // 楠岃瘉鏁版嵁闀垮害
                     if (!ModbusDataParser.ValidateRegisterLength(registers, fieldConfig))
                     {
-                        LogWarning($"瀛楁 '{fieldName}' 鐨勬暟鎹暱搴︿笉瓒筹細鏈熸湜{fieldConfig.Length}锛屽疄闄厈registers.Length}");
+                        LogWarning($"瀛楁 '{fieldName}' 鐨勬暟鎹暱搴︿笉瓒筹細鏈熸湜{fieldConfig.Length}锛屽疄闄厈registers?.Length ?? 0}");
                         continue;
                     }
 
@@ -532,6 +562,14 @@
                 catch (Exception ex)
                 {
                     LogError($"璇诲彇瀛楁 '{fieldName}' 澶辫触: {ex.Message}");
+                    
+                    // 璁板綍璇︾粏閿欒淇℃伅
+                    await _databaseManager?.LogErrorAsync(
+                        "FieldReadError", 
+                        $"璇诲彇瀛楁 '{fieldName}' 澶辫触: {ex.Message}", 
+                        ex, 
+                        ErrorSeverity.Medium)!;
+                    
                     // 缁х画璇诲彇鍏朵粬瀛楁
                 }
             }
diff --git a/config/ModbusDataParser.cs b/config/ModbusDataParser.cs
index 59ff578..4665c15 100644
--- a/config/ModbusDataParser.cs
+++ b/config/ModbusDataParser.cs
@@ -18,9 +18,22 @@
         /// <returns>瑙f瀽鍚庣殑鏁版嵁瀵硅薄</returns>
         public static object? ParseFieldData(int[] registers, DataField fieldConfig)
         {
+            if (fieldConfig == null)
+            {
+                Console.WriteLine("[PARSER-ERROR] 瀛楁閰嶇疆涓簄ull");
+                return null;
+            }
+
             if (registers == null || registers.Length == 0)
             {
+                Console.WriteLine($"[PARSER-ERROR] 瀛楁 '{fieldConfig.DisplayName}' 鐨勫瘎瀛樺櫒鏁版嵁涓虹┖");
                 return GetDefaultValue(fieldConfig.DataType);
+            }
+
+            if (string.IsNullOrEmpty(fieldConfig.DataType))
+            {
+                Console.WriteLine($"[PARSER-ERROR] 瀛楁 '{fieldConfig.DisplayName}' 鐨勬暟鎹被鍨嬫湭瀹氫箟");
+                return null;
             }
 
             try
@@ -39,6 +52,7 @@
             catch (Exception ex)
             {
                 Console.WriteLine($"[PARSER-ERROR] 瑙f瀽瀛楁 '{fieldConfig.DisplayName}' 鏃跺彂鐢熼敊璇�: {ex.Message}");
+                Console.WriteLine($"[PARSER-ERROR] 鍫嗘爤璺熻釜: {ex.StackTrace}");
                 return GetDefaultValue(fieldConfig.DataType);
             }
         }
@@ -272,8 +286,11 @@
         /// </summary>
         /// <param name="dataType">鏁版嵁绫诲瀷瀛楃涓�</param>
         /// <returns>榛樿鍊煎璞�</returns>
-        private static object? GetDefaultValue(string dataType)
+        private static object? GetDefaultValue(string? dataType)
         {
+            if (string.IsNullOrEmpty(dataType))
+                return null;
+
             return dataType.ToLower() switch
             {
                 "byte" => (byte)0,

--
Gitblit v1.9.3