private void BUT_copyto1280_Click(object sender, EventArgs e) { IArduinoComms port = new ArduinoSTK(); port.BaudRate = 57600; port.DataBits = 8; port.StopBits = StopBits.One; port.Parity = Parity.None; port.DtrEnable = true; StreamReader sr = new StreamReader(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"EEPROM1280.bin"); BinaryReader br = new BinaryReader(sr.BaseStream); byte[] EEPROM = br.ReadBytes(1024 * 4); br.Close(); sr.Close(); sr = new StreamReader(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"FLASH1280.bin"); br = new BinaryReader(sr.BaseStream); byte[] FLASH = br.ReadBytes(1024 * 128); br.Close(); sr.Close(); try { port.PortName = MissionPlanner.MainV2.comPortName; port.Open(); if (port.connectAP()) { log.Info("starting"); port.uploadflash(FLASH, 0, FLASH.Length, 0); port.upload(EEPROM, 0, (short)EEPROM.Length, 0); log.Info("Uploaded"); } else { CustomMessageBox.Show("Communication Error - no connection"); } port.Close(); } catch (Exception ex) { CustomMessageBox.Show("Check port settings or Port in use? " + ex.ToString()); port.Close(); } }
public int writeEEPROM(int start, int length) { ArduinoSTK sp = osd.OpenArduino(); int err = 0; if (sp != null && sp.connectAP()) { try { bool spupload_flag = false; for (int i = 0; i < 10; i++) //try to upload two times if it fail { spupload_flag = sp.upload(eeprom.data, (short)start, (short)length, (short)start); if (!spupload_flag) { if (sp.keepalive()) { Console.WriteLine("keepalive successful (iter " + i + ")"); } else { Console.WriteLine("keepalive fail (iter " + i + ")"); } } else { break; } if (!spupload_flag) { err = 1; } } } catch (Exception ex) { MessageBox.Show(ex.Message); err = -1; } } else { MessageBox.Show("Failed to talk to bootloader"); err = -1; } sp.Close(); return(err); }
private void resetBoardSettingsToolStripMenuItem_Click(object sender, EventArgs e) { ArduinoSTK sp; try { if (comPort.IsOpen) { comPort.Close(); } sp = new ArduinoSTK(); sp.PortName = CMB_ComPort.Text; sp.BaudRate = 57600; sp.DtrEnable = true; sp.Open(); } catch { MessageBox.Show("Error opening com port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } eeprom = new byte[eeprom.Length]; if (sp.connectAP()) { try { if (sp.upload(eeprom, 0, 1024, 0)) { MessageBox.Show("Done!"); } else { MessageBox.Show("Failed to upload new settings"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Failed to talk to bootloader"); } sp.Close(); }
private void BUT_copyto1280_Click(object sender, EventArgs e) { ArduinoComms port = new ArduinoSTK(); port.BaudRate = 57600; port.DataBits = 8; port.StopBits = StopBits.One; port.Parity = Parity.None; port.DtrEnable = true; StreamReader sr = new StreamReader(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"EEPROM1280.bin"); BinaryReader br = new BinaryReader(sr.BaseStream); byte[] EEPROM = br.ReadBytes(1024 * 4); br.Close(); sr.Close(); sr = new StreamReader(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"FLASH1280.bin"); br = new BinaryReader(sr.BaseStream); byte[] FLASH = br.ReadBytes(1024 * 128); br.Close(); sr.Close(); try { port.PortName = ArdupilotMega.MainV2.comPortName; port.Open(); if (port.connectAP()) { log.Info("starting"); port.uploadflash(FLASH, 0, FLASH.Length, 0); port.upload(EEPROM, 0, (short)EEPROM.Length, 0); log.Info("Uploaded"); } else { CustomMessageBox.Show("Communication Error - no connection"); } port.Close(); } catch (Exception ex) { CustomMessageBox.Show("Check port settings or Port in use? " + ex.ToString()); port.Close(); } }
public bool WriteCharsetVersion(string version, bool showMsg = true) { // byte[] tempEeprom = new byte[3]; // tempEeprom[0] = (byte)version[0]; // tempEeprom[1] = (byte)version[1]; // tempEeprom[2] = (byte)version[2]; EEPROM tempEeprom = new EEPROM(); ArduinoSTK sp = osd.OpenArduino(); if (sp != null && sp.connectAP()) { // Сначала считать try { for (int i = 0; i < 5; i++) //try to download two times if it fail { byte[] data = sp.download(EEPROM_SIZE); if (sp.down_flag) { tempEeprom.data = data; break; } else { if (sp.keepalive()) { Console.WriteLine("keepalive successful (iter " + i + ")"); } else { Console.WriteLine("keepalive fail (iter " + i + ")"); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } tempEeprom.CS_version = version; try { bool spupload_flag = false; for (int i = 0; i < 10; i++) //try to upload two times if it fail // spupload_flag = sp.upload(tempEeprom, (short)0, (short)tempEeprom.Length, (short)CS_VERSION1_ADDR); { spupload_flag = sp.upload(tempEeprom.data, (short)Settings_offset, (short)Settings_size, (short)Settings_offset); if (!spupload_flag) { if (sp.keepalive()) { Console.WriteLine("keepalive successful (iter " + i + ")"); } else { Console.WriteLine("keepalive fail (iter " + i + ")"); } } else { break; } } if (spupload_flag) { if (showMsg) { MessageBox.Show("Done writing configuration data!"); } } else { MessageBox.Show("Failed to upload new configuration data"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Failed to talk to bootloader"); } sp.Close(); return(true); }
private void BUT_WriteIOB_Click(object sender, EventArgs e) { toolStripProgressBar1.Style = ProgressBarStyle.Continuous; this.toolStripStatusLabel1.Text = ""; foreach (Control ctl in tabPage2.Controls) { if (ctl.GetType() == typeof(Pattern)) { Pattern pat = ctl as Pattern; int no = 0; if (int.TryParse(pat.Name.Substring(pat.Name.Length - 2), out no)) { eeprom[(no - 1) * 2] = (byte)(pat.Value >> 8); eeprom[(no - 1) * 2 + 1] = (byte)(pat.Value & 0xff); eeprom[64 + (no - 1) * 2] = (byte)pat.FlightMode; eeprom[64 + (no - 1) * 2 + 1] = (byte)pat.FlightMode; } else if (int.TryParse(pat.Name.Substring(pat.Name.Length - 1), out no)) { eeprom[(no - 1) * 2] = (byte)(pat.Value >> 8); eeprom[(no - 1) * 2 + 1] = (byte)(pat.Value & 0xff); eeprom[64 + (no - 1) * 2] = (byte)pat.FlightMode; eeprom[64 + (no - 1) * 2 + 1] = (byte)pat.FlightMode; } } } printeeprom(); ArduinoSTK sp; try { if (comPort.IsOpen) { comPort.Close(); } sp = new ArduinoSTK(); sp.PortName = CMB_ComPort.Text; sp.BaudRate = 57600; sp.DtrEnable = true; sp.Open(); } catch { MessageBox.Show("Error opening com port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (sp.connectAP()) { try { if (sp.upload(eeprom, 0, 126, 0)) { MessageBox.Show("Done!"); } else { MessageBox.Show("Failed to upload new settings"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Failed to talk to bootloader"); } sp.Close(); }