|
@@ -1,4 +1,5 @@
|
|
|
-using System;
|
|
|
+using SXLibrary;
|
|
|
+using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
@@ -21,18 +22,27 @@ namespace MOKA_Factory_Tools
|
|
|
|
|
|
public static byte[] HexToByte(string msg)
|
|
|
{
|
|
|
- msg = msg.Replace(" ", "");//移除空格
|
|
|
+ try
|
|
|
+ {
|
|
|
+ msg = msg.Replace(" ", "");//移除空格
|
|
|
+
|
|
|
+ //create a byte array the length of the
|
|
|
+ //divided by 2 (Hex is 2 characters in length)
|
|
|
+ byte[] comBuffer = new byte[msg.Length / 2];
|
|
|
+ for (int i = 0; i < msg.Length; i += 2)
|
|
|
+ {
|
|
|
+ //convert each set of 2 characters to a byte and add to the array
|
|
|
+ comBuffer[i / 2] = (byte)Convert.ToByte(msg.Substring(i, 2), 16);
|
|
|
+ }
|
|
|
|
|
|
- //create a byte array the length of the
|
|
|
- //divided by 2 (Hex is 2 characters in length)
|
|
|
- byte[] comBuffer = new byte[msg.Length / 2];
|
|
|
- for (int i = 0; i < msg.Length; i += 2)
|
|
|
+ return comBuffer;
|
|
|
+ }
|
|
|
+ catch(Exception e)
|
|
|
{
|
|
|
- //convert each set of 2 characters to a byte and add to the array
|
|
|
- comBuffer[i / 2] = (byte)Convert.ToByte(msg.Substring(i, 2), 16);
|
|
|
+ Log.WriteErrorLog(string.Format("HexToByte Error: {0} -> {1}", msg, e.Message));
|
|
|
}
|
|
|
|
|
|
- return comBuffer;
|
|
|
+ return new byte[] { };
|
|
|
}
|
|
|
|
|
|
public static bool BytesCompare_Base64(byte[] b1, byte[] b2)
|