Browse Source

数据长度按读取位数截取

章政 6 years ago
parent
commit
c55f09f582
1 changed files with 3 additions and 2 deletions
  1. 3 2
      PLCDataReader/PublicMethod/BaseUtil.cs

+ 3 - 2
PLCDataReader/PublicMethod/BaseUtil.cs

@@ -400,7 +400,8 @@ namespace UAS_PLCDataReader.PublicMethod
                     }
                 }
             }
-            return ReturnStr.ToUpper();
+            int ValueDataSize = Convert.ToInt32("0x" + (ReturnStr.Substring(4, 2)), 16) * 2;
+            return ReturnStr.ToUpper().Substring(0, ValueDataSize + 6 + 2);//首部6位和尾部2位校验位
         }
 
         public static int[] GetDecimalData(string HexStr, int DataSize)
@@ -412,7 +413,7 @@ namespace UAS_PLCDataReader.PublicMethod
                 HexStr = HexStr.Replace(":", "");
                 if (HexStr != "")
                 {
-                    int ValueDataSize = Convert.ToInt32("0x" + (HexStr.Substring(4, 2)), 16)*2;
+                    int ValueDataSize = Convert.ToInt32("0x" + (HexStr.Substring(4, 2)), 16) * 2;
                     string RealData = HexStr.Substring(6);
                     RealData = RealData.Substring(0, ValueDataSize);
                     //每个地址位存的数据是DataSize个