private void btnProgram_Click(object sender, RoutedEventArgs e) { var eep = new eeprom.eep_config(); SyncConfigToUI(ref current_cfg); eeprom.GenerateEEPROMConfig(current_cfg, out eep); }
/* read config from first connected device */ /* returns null on failure */ public config Read() { var loader = new HidDeviceLoader(); var device = loader.GetDevices(0x1234, 0x9876).First(); HidStream stream; if (!device.TryOpen(out stream)) return null; if (!CheckBootloader(stream)) return null; // read EEPROM var result = ExecuteHIDCommand(stream, (int)BootloaderCommands.READ_EEPROM, 0); if (result == null) return null; if (result.Length != (4 + 32)) // header + one EEPROM page { Console.WriteLine("Incorrect size response from bootloader."); return null; } // marshall the bytes from result into a new eep_config object var eep = new eeprom.eep_config(); int size = Marshal.SizeOf(eep); IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.Copy(result, 4, ptr, size); eep = (eeprom.eep_config)Marshal.PtrToStructure(ptr, typeof(eeprom.eep_config)); Marshal.FreeHGlobal(ptr); // test EEPROM config and convert to config string error_message; var cfg = eeprom.DecodeEEPROMConfig(eep, out error_message); if (cfg == null) { Console.WriteLine(error_message); return null; } return cfg; }