private void EepromSave_Click(object sender, EventArgs e) { Edgecutter2Calibration P = new Edgecutter2Calibration(); P.CalibNormal = levelNormal; P.CalibCurved = levelPhased; //#define VERSIONBYTE 0x10 WriteEepromByte(0x20, 0x10); System.Threading.Thread.Sleep(400); var B = getBytes(P); for (int i = 0; i < B.Length; i++) { WriteEepromByte((ushort)(0x20 + i + 1), B[i]); System.Threading.Thread.Sleep(100); WriteEepromByte((ushort)(0x20 + i + 1), B[i]); System.Threading.Thread.Sleep(100); } for (int i = 0; i < B.Length; i++) { byte b = B[i]; Console.WriteLine("writing {0:X}:{1:X}", i, b); } }
byte[] getBytes(Edgecutter2Calibration wob) { int size = Marshal.SizeOf(wob); byte[] arr = new byte[size]; IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(wob, ptr, true); Marshal.Copy(ptr, arr, 0, size); Marshal.FreeHGlobal(ptr); return(arr); }