private static void Test() { try { ProductStruct product = new ProductStruct(); product.No = 1; product.UID = "PNo123456".GetFixLengthChar(14); product.Current = 0.567; product.Pass = 0; var b = StructHelper.StuctToByte(product); Console.WriteLine("Struct length:" + b.Length); Console.WriteLine("Hex: " + ByteToHexString(b, ' ')); var s = StructHelper.ByteToStuct <ProductStruct>(b); Console.WriteLine("No: " + s.No.ToString()); Console.WriteLine("UID: " + s.UID.GetString()); Console.WriteLine("Current: " + s.Current.ToString()); Console.WriteLine("Pass: " + s.Pass.ToString()); //Test1(); } catch (Exception ex) { MessageBox.Show(ex.Message); } //byte[] buffer = new byte[1024]; //Array.Copy(test, 0, buffer, 0, test.Length); //Analysis(buffer, test); }
private static void Test1() { InfoStruct Info = new InfoStruct(); Info.HardwareNum = "1.0.0".GetFixLengthChar(16); Info.HardwareVersion = "ABC1234567".GetFixLengthChar(16); Info.DeviceName = "Device Name1".GetFixLengthChar(32); Info.ModuleID = 0x10000001; Info.SlotNum = 1; Info.SoftwareDate = "2018/1/22".GetFixLengthChar(16); Info.SoftwareVersion = "V1.0.0".GetFixLengthChar(16); var b = StructHelper.StuctToByte(Info); Console.WriteLine("Struct length:" + b.Length); Console.WriteLine("Hex:" + ByteToHexString(b, ' ')); var s = StructHelper.ByteToStuct <InfoStruct>(b); Console.WriteLine("Name:" + s.DeviceName.GetString()); Console.WriteLine("HardwareVersion:" + s.HardwareVersion.GetString()); }