Hcsy 6 years ago
parent
commit
f09b1819f7

+ 37 - 0
PLCDataReader/ClassFile/LogManager.cs

@@ -58,5 +58,42 @@ namespace ClassFile
             }
             catch (Exception) { }
         }
+
+
+
+        /// <summary>
+        /// 获取LRC
+        /// </summary>
+        /// <param name="SQL"></param>
+        public static string getLRC(string SENDMESSAGE)
+        {
+            string message = SENDMESSAGE.Trim();
+            if (message.Length % 2 != 0)
+            {
+                message = message + "0";
+            }
+
+            int LRC = 0x0;
+            for (int i = 0; i < message.Length; i = i + 2)
+            {
+                int inside = int.Parse(message.Substring(i, 1).ToString() + message.Substring(i + 1, 1).ToString(), System.Globalization.NumberStyles.HexNumber);
+                LRC += inside;
+            }
+            string _LRC = string.Format("{0:X2}", LRC);
+            string LRCre = "";
+            for (int i = 0; i < _LRC.Length; i++)
+            {
+                int index;
+                if (i != _LRC.Length - 1)
+                {
+                    index = 0xF - int.Parse(_LRC.Substring(i, 1).ToString(), System.Globalization.NumberStyles.HexNumber);
+                }
+                else
+                    index = 0xF - int.Parse(_LRC.Substring(i, 1).ToString(), System.Globalization.NumberStyles.HexNumber) + 1;
+                LRCre += string.Format("{0:X}", index);
+            }
+
+            return LRCre;
+        }
     }
 }

+ 0 - 27
PLCDataReader/ClassFile/ModeBusTCPServer.cs

@@ -147,33 +147,6 @@ namespace ClassFile
                                     }
                                     item.Send(Encoding.UTF8.GetBytes(strH));
                                     break;
-                                case "LRC":
-                                    string message = SENDMESSAGE.Text.Trim();
-                                    if (message.Length % 2 != 0) {
-                                        message = message + "0";
-                                    }
-
-                                    int LRC = 0x0;
-                                    for (int i = 0; i < message.Length; i=i+2)
-                                    {
-                                        int inside =int.Parse(message.Substring(i,1).ToString()+ message.Substring(i+1,1).ToString(), System.Globalization.NumberStyles.HexNumber);
-                                        LRC += inside;
-                                    }
-                                    string _LRC = string.Format("{0:X2}", LRC);
-                                    string LRCre = "";
-                                    for (int i = 0; i < _LRC.Length; i++)
-                                    {
-                                        int index;
-                                        if (i != _LRC.Length - 1)
-                                        {
-                                             index = 0xF - int.Parse(_LRC.Substring(i, 1).ToString(), System.Globalization.NumberStyles.HexNumber);
-                                        }else
-                                             index = 0xF - int.Parse(_LRC.Substring(i, 1).ToString(), System.Globalization.NumberStyles.HexNumber)+1;
-                                        LRCre += string.Format("{0:X}", index);
-                                    }
-
-                                    item.Send(Encoding.UTF8.GetBytes(LRCre.ToString()));
-                                    break;
                             }                        
                         }
                     }

+ 1 - 2
PLCDataReader/MainWindow.Designer.cs

@@ -141,8 +141,7 @@
             this.Encoding.Items.AddRange(new object[] {
             "UTF-8",
             "ASCII",
-            "Hexadecimal",
-            "LRC"});
+            "Hexadecimal"});
             this.Encoding.Location = new System.Drawing.Point(533, 89);
             this.Encoding.Name = "Encoding";
             this.Encoding.Size = new System.Drawing.Size(157, 20);