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 = 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(); } }
private void button3_Click(object sender, EventArgs e) { sp = new ArduinoSTK(); sp.BaudRate = 57600; sp.PortName = textBox1.Text; sp.DtrEnable = true; sp.RtsEnable = true; sp.Open(); Console.WriteLine("Open dtr rts"); ser(sp); sp.Close(); Console.WriteLine("Close"); }
private void WriteCharsetVersion(string version) { byte[] tempEeprom = new byte[3]; tempEeprom[0] = (byte)version[0]; tempEeprom[1] = (byte)version[1]; tempEeprom[2] = (byte)version[2]; //Set Com port ArduinoSTK sp; try { if (comPort.IsOpen) comPort.Close(); sp = new ArduinoSTK(); sp.PortName = CMB_ComPort.Text; sp.BaudRate = 57600; sp.DataBits = 8; sp.StopBits = StopBits.One; sp.Parity = Parity.None; sp.DtrEnable = false; sp.RtsEnable = false; //added sp.Open(); } catch { MessageBox.Show("Error opening com port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (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(tempEeprom, (short)0, (short)tempEeprom.Length, (short)CS_VERSION1_ADDR); if (!spupload_flag) { if (sp.keepalive()) Console.WriteLine("keepalive successful (iter " + i + ")"); else Console.WriteLine("keepalive fail (iter " + i + ")"); } else break; } if (spupload_flag) 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(); }
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; } } } // Writing single values to their correct EEPROM locations eeprom[128] = (byte)numLEFT.Value; eeprom[129] = (byte)numRIGHT.Value; eeprom[130] = (byte)numFRONT.Value; eeprom[131] = (byte)numREAR.Value; eeprom[152] = (byte)Convert.ToByte(BAlarm_Percentage.Text); if (CB_FrSky.Checked) { eeprom[140] = 1; } else { eeprom[140] = 0; } if (CB_Factory_Reset.Checked) { eeprom[141] = 1; CB_Factory_Reset.Checked = false; } 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, 180, 0)) { MessageBox.Show("Upload settings..\n 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_copy1280_Click(object sender, EventArgs e) { ArduinoSTK port = new ArduinoSTK(); port.BaudRate = 57600; port.DataBits = 8; port.StopBits = StopBits.One; port.Parity = Parity.None; port.DtrEnable = true; try { port.PortName = ArdupilotMega.MainV2.comPortName; log.Info("Open Port"); port.Open(); log.Info("Connect AP"); if (port.connectAP()) { log.Info("Download AP"); byte[] EEPROM = new byte[1024 * 4]; for (int a = 0; a < 4 * 1024; a += 0x100) { port.setaddress(a); port.download(0x100).CopyTo(EEPROM, a); } log.Info("Verify State"); if (port.keepalive()) { StreamWriter sw = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"EEPROM1280.bin"); BinaryWriter bw = new BinaryWriter(sw.BaseStream); bw.Write(EEPROM, 0, EEPROM.Length); bw.Close(); log.Info("Download AP"); byte[] FLASH = new byte[1024 * 128]; for (int a = 0; a < FLASH.Length; a += 0x100) { port.setaddress(a); port.downloadflash(0x100).CopyTo(FLASH, a); } sw = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"FLASH1280.bin"); bw = new BinaryWriter(sw.BaseStream); bw.Write(FLASH, 0, FLASH.Length); bw.Close(); } else { CustomMessageBox.Show("Communication Error - Bad data"); } } else { CustomMessageBox.Show("Communication Error - no connection"); } port.Close(); } catch (Exception ex) { CustomMessageBox.Show("Port Error? " + ex.ToString()); if (port != null && port.IsOpen) { port.Close(); } } }
//Write data to MinimOSD EPPROM private void BUT_ResetOSD_EEPROM() { toolStripProgressBar1.Style = ProgressBarStyle.Continuous; this.toolStripStatusLabel1.Text = ""; //First Panel List<TreeNode> AllNodes = new List<TreeNode>(); foreach (TreeNode tn in LIST_items.Nodes) { foreach (TreeNode tn2 in tn.Nodes) { AllNodes.Add(tn2); } AllNodes.Add(tn); } foreach (TreeNode tn in AllNodes) { string str = tn.Text; foreach (var tuple in this.panelItems_default) { if ((tuple != null) && ((tuple.Item1 == str)) && tuple.Item5 != -1) { if (str == "Center") eeprom[tuple.Item5] = 0; else if (str == "Tune") eeprom[tuple.Item5] = 0; else if (str == "Channel Raw") eeprom[tuple.Item5] = 0; else eeprom[tuple.Item5] = 1; eeprom[tuple.Item6] = (byte)tuple.Item3; // x eeprom[tuple.Item7] = (byte)tuple.Item4; // y } } } //Second Panel AllNodes = new List<TreeNode>(); foreach (TreeNode tn in LIST_items2.Nodes) { foreach (TreeNode tn2 in tn.Nodes) { AllNodes.Add(tn2); } AllNodes.Add(tn); } foreach (TreeNode tn in AllNodes) { string str = tn.Text; foreach (var tuple in this.panelItems2_default) { if ((tuple != null) && ((tuple.Item1 == str)) && tuple.Item5 != -1) { if (str == "Center") eeprom[tuple.Item5] = 0; else if (str == "Tune") eeprom[tuple.Item5] = 0; else if (str == "Channel Raw") eeprom[tuple.Item5] = 0; else eeprom[tuple.Item5] = 1; eeprom[tuple.Item6 + OffsetBITpanel] = (byte)tuple.Item3; // x eeprom[tuple.Item7 + OffsetBITpanel] = (byte)tuple.Item4; // y } } } //Setup configuration panel eeprom[measure_ADDR] = pan.converts; eeprom[overspeed_ADDR] = pan.overspeed; eeprom[stall_ADDR] = pan.stall; eeprom[battv_ADDR] = pan.battv; eeprom[OSD_RSSI_HIGH_ADDR] = pan.rssical; eeprom[OSD_RSSI_LOW_ADDR] = pan.rssipersent; eeprom[OSD_RSSI_RAW_ADDR] = pan.rssiraw_on; eeprom[OSD_Toggle_ADDR] = pan.ch_toggle; eeprom[switch_mode_ADDR] = pan.switch_mode; eeprom[PAL_NTSC_ADDR] = pan.pal_ntsc; eeprom[OSD_BATT_WARN_ADDR] = pan.batt_warn_level; eeprom[OSD_BATT_SHOW_PERCENT_ADDR] = Convert.ToByte(pan.osd_battery_show_percentage); eeprom[OSD_RSSI_WARN_ADDR] = pan.rssi_warn_level; eeprom[OSD_BRIGHTNESS_ADDR] = pan.osd_brightness; eeprom[CHK_VERSION] = VER; for (int i = 0; i < OSD_CALL_SIGN_TOTAL; i++) { eeprom[OSD_CALL_SIGN_ADDR + i] = Convert.ToByte('a'); Console.WriteLine("Call Sign ", i, " is ", eeprom[OSD_CALL_SIGN_ADDR + i]); } ArduinoSTK sp; try { if (comPort.IsOpen) comPort.Close(); sp = new ArduinoSTK(); sp.PortName = CMB_ComPort.Text; sp.BaudRate = 57600; sp.DataBits = 8; sp.StopBits = StopBits.One; sp.Parity = Parity.None; sp.DtrEnable = false; sp.RtsEnable = false; //added sp.Open(); } catch { MessageBox.Show("Error opening com port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (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, 0,CHK_VERSION + 1, 0); if (!spupload_flag) { if (sp.keepalive()) Console.WriteLine("keepalive successful (iter " + i + ")"); else Console.WriteLine("keepalive fail (iter " + i + ")"); } else break; } if (spupload_flag) 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(); }
private void updateFirmwareToolStripMenuItem_Click(object sender, EventArgs e) { toolStripProgressBar1.Style = ProgressBarStyle.Continuous; this.toolStripStatusLabel1.Text = ""; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "*.hex|*.hex"; ofd.ShowDialog(); if (ofd.FileName != "") { byte[] FLASH; bool spuploadflash_flag = false; try { toolStripStatusLabel1.Text = "Reading Hex File"; statusStrip1.Refresh(); FLASH = readIntelHEXv2(new StreamReader(ofd.FileName)); } catch { MessageBox.Show("Bad Hex File"); return; } //bool fail = false; ArduinoSTK sp; try { if (comPort.IsOpen) comPort.Close(); sp = new ArduinoSTK(); sp.PortName = CMB_ComPort.Text; sp.BaudRate = 57600; sp.DataBits = 8; sp.StopBits = StopBits.One; sp.Parity = Parity.None; sp.DtrEnable = false; sp.RtsEnable = false; //added sp.Open(); } catch { MessageBox.Show("Error opening com port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } toolStripStatusLabel1.Text = "Connecting to Board"; if (sp.connectAP()) { sp.Progress += new ArduinoSTK.ProgressEventHandler(sp_Progress); try { for (int i = 0; i < 3; i++) //try to upload 3 times { //try to upload n times if it fail spuploadflash_flag = sp.uploadflash(FLASH, 0, FLASH.Length, 0); if (!spuploadflash_flag) { if (sp.keepalive()) Console.WriteLine("keepalive successful (iter " + i + ")"); else Console.WriteLine("keepalive fail (iter " + i + ")"); //toolStripStatusLabel1.Text = "Lost sync. Reconnecting..."; } else break; } //if (!sp.uploadflash(FLASH, 0, FLASH.Length, 0)) //{ // if (sp.IsOpen) // sp.Close(); // MessageBox.Show("Upload failed. Lost sync. Try using Arduino to upload instead", // "Error", // MessageBoxButtons.OK, // MessageBoxIcon.Warning); //} } catch (Exception ex) { //fail = true; MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Failed to talk to bootloader"); } sp.Close(); if (spuploadflash_flag) { toolStripStatusLabel1.Text = "Done"; MessageBox.Show("Done!"); } else { MessageBox.Show("Upload failed. Lost sync. Try using Arduino to upload instead", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); toolStripStatusLabel1.Text = "Failed"; } } //Check EEPROM version this.BUT_ReadOSD_Click(EventArgs.Empty, EventArgs.Empty); }
private void BUT_ReadOSD_Click(object sender, EventArgs e) { toolStripProgressBar1.Style = ProgressBarStyle.Continuous; this.toolStripStatusLabel1.Text = ""; bool fail = false; 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 { eeprom = sp.download(1024); } catch (Exception ex) { fail = true; MessageBox.Show(ex.Message); } } else { MessageBox.Show("Failed to talk to bootloader"); fail = true; } sp.Close(); if (!fail) { for (int a = 0; a < panelItems.Length; a++) { if (panelItems[a] != null) { if (panelItems[a].Item5 >= 0) LIST_items.SetItemCheckState(a, eeprom[panelItems[a].Item5] == 0 ? CheckState.Unchecked : CheckState.Checked); if (panelItems[a].Item7 >= 0 || panelItems[a].Item6 >= 0) panelItems[a] = new Tuple<string, Func<int, int, int>, int, int, int, int, int>(panelItems[a].Item1, panelItems[a].Item2, eeprom[panelItems[a].Item6], eeprom[panelItems[a].Item7], panelItems[a].Item5, panelItems[a].Item6, panelItems[a].Item7); } } } osdDraw(); if (!fail) MessageBox.Show("Done!"); }
private void BUT_upload_Click(object sender, EventArgs e) { ArduinoSTK comPort = new ArduinoSTK(); uploader.Uploader uploader = new uploader.Uploader(); try { comPort.PortName = MainV2.comPort.BaseStream.PortName; comPort.BaudRate = 115200; comPort.Open(); } catch { CustomMessageBox.Show("Invalid ComPort or in use"); return; } bool bootloadermode = false; // attempt bootloader mode try { uploader_ProgressEvent(0); uploader_LogEvent("Trying Bootloader Mode"); uploader.port = comPort; uploader.connect_and_sync(); uploader.ProgressEvent += new ProgressEventHandler(uploader_ProgressEvent); uploader.LogEvent += new LogEventHandler(uploader_LogEvent); uploader_LogEvent("In Bootloader Mode"); bootloadermode = true; } catch { // cleanup bootloader mode fail, and try firmware mode comPort.Close(); comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate; comPort.Open(); uploader.ProgressEvent += new ProgressEventHandler(uploader_ProgressEvent); uploader.LogEvent += new LogEventHandler(uploader_LogEvent); uploader_LogEvent("Trying Firmware Mode"); bootloadermode = false; } // check for either already bootloadermode, or if we can do a ATI to ID the firmware if (bootloadermode || doConnect(comPort)) { uploader.IHex iHex = new uploader.IHex(); iHex.LogEvent += new LogEventHandler(iHex_LogEvent); iHex.ProgressEvent += new ProgressEventHandler(iHex_ProgressEvent); // put into bootloader mode/udpate mode if (!bootloadermode) { try { comPort.Write("AT&UPDATE\r\n"); string left = comPort.ReadExisting(); log.Info(left); Sleep(700); comPort.BaudRate = 115200; } catch { } } global::uploader.Uploader.Code device = global::uploader.Uploader.Code.FAILED; global::uploader.Uploader.Code freq = global::uploader.Uploader.Code.FAILED; // get the device type and frequency in the bootloader uploader.getDevice(ref device, ref freq); // get firmware for this device if (getFirmware(device)) { // load the hex try { iHex.load(firmwarefile); } catch { CustomMessageBox.Show("Bad Firmware File"); goto exit; } // upload the hex and verify try { uploader.upload(comPort, iHex); } catch (Exception ex) { CustomMessageBox.Show("Upload Failed " + ex.Message); } } else { CustomMessageBox.Show("Failed to download new firmware"); } } else { CustomMessageBox.Show("Failed to identify Radio"); } exit: if (comPort.IsOpen) { comPort.Close(); } }
private void GetFwFromOSD() { ArduinoSTK sp; byte[] FLASH = new byte[32 * 1024]; //byte[] FLASH = new byte[30382]; try { if (comPort.IsOpen) comPort.Close(); sp = new ArduinoSTK(); sp.PortName = CMB_ComPort.Text; sp.BaudRate = 57600; sp.DataBits = 8; sp.StopBits = StopBits.One; sp.Parity = Parity.None; sp.DtrEnable = false; sp.RtsEnable = false; //added sp.Open(); } catch { MessageBox.Show("Error opening com port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (sp.connectAP()) { try { int start = 0; short length = 0x100; while (start < FLASH.Length) { sp.setaddress(start); sp.downloadflash(length).CopyTo(FLASH, start); start += length; } StreamWriter sw = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + "FW" + Path.DirectorySeparatorChar + @"flash.bin", false); BinaryWriter bw = new BinaryWriter(sw.BaseStream); bw.Write(FLASH, 0, FLASH.Length); bw.Close(); sw = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + "FW" + Path.DirectorySeparatorChar + @"flash.hex", false); for (int i = 0; i < FLASH.Length; i += 16) { string add = string.Format("{0:X4}", i); if (i % (0x1000 << 4) == 0) { if (i != 0) sw.WriteLine(":02000002{0:X4}{1:X2}", ((i >> 4) & 0xf000), 0x100 - (2 + 2 + (((i >> 4) & 0xf000) >> 8) & 0xff)); } if (add.Length == 5) { add = add.Substring(1); } sw.Write(":{0:X2}{1}00", 16, add); byte ck = (byte)(16 + (i & 0xff) + ((i >> 8) & 0xff)); for (int a = 0; a < 16; a++) { ck += FLASH[i + a]; sw.Write("{0:X2}", FLASH[i + a]); } sw.WriteLine("{0:X2}", (byte)(0x100 - ck)); } sw.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } sp.Close(); }
private void BUT_upload_Click(object sender, EventArgs e) { ArduinoSTK comPort = new ArduinoSTK(); uploader.Uploader uploader = new uploader.Uploader(); try { comPort.PortName = MainV2.comPort.BaseStream.PortName; comPort.BaudRate = 115200; comPort.Open(); } catch { CustomMessageBox.Show("Invalid ComPort or in use"); return; } bool bootloadermode = false; uploader.ProgressEvent += new ProgressEventHandler(uploader_ProgressEvent); uploader.LogEvent += new LogEventHandler(uploader_LogEvent); try { uploader_ProgressEvent(0); uploader_LogEvent("Trying Bootloader Mode"); uploader.port = comPort; uploader.connect_and_sync(); uploader_LogEvent("In Bootloader Mode"); bootloadermode = true; } catch { comPort.Close(); comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate; comPort.Open(); uploader_LogEvent("Trying Firmware Mode"); bootloadermode = false; } if (bootloadermode || doConnect(comPort)) { if (getFirmware()) { uploader.IHex iHex = new uploader.IHex(); iHex.LogEvent += new LogEventHandler(iHex_LogEvent); iHex.ProgressEvent += new ProgressEventHandler(iHex_ProgressEvent); try { iHex.load(firmwarefile); } catch { CustomMessageBox.Show("Bad Firmware File"); goto exit; } if (!bootloadermode) { try { comPort.Write("AT&UPDATE\r\n"); string left = comPort.ReadExisting(); Console.WriteLine(left); Sleep(700); comPort.BaudRate = 115200; } catch { } } try { uploader.upload(comPort, iHex); } catch (Exception ex) { CustomMessageBox.Show("Upload Failed " + ex.Message); } } else { CustomMessageBox.Show("Failed to download new firmware"); } } else { CustomMessageBox.Show("Failed to identify Radio"); } exit: if (comPort.IsOpen) { comPort.Close(); } }
private void BUT_ReadIOB_Click(object sender, EventArgs e) { toolStripProgressBar1.Style = ProgressBarStyle.Continuous; this.toolStripStatusLabel1.Text = ""; bool fail = false; 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 { eeprom = sp.download(1024); } catch (Exception ex) { fail = true; MessageBox.Show(ex.Message); } } else { MessageBox.Show("Failed to talk to bootloader"); fail = true; } sp.Close(); int startmbind = 64; if (!fail) { for (int pos = 0; pos < 16 ;pos++) { patterns[pos] = (ushort)((ushort)(eeprom[pos*2] << 8) + eeprom[pos*2 + 1]); Control[] ctls = this.Controls.Find("pattern" + (pos+1), true); if (ctls.Length > 0) { ((Pattern)ctls[0]).Value = patterns[pos]; ((Pattern)ctls[0]).FlightMode = (ushort)(eeprom[startmbind + pos * 2]); } } } printeeprom(); if (!fail) MessageBox.Show("Done!"); }
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_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(); }
private void BUT_ReadOSD_Click(object sender, EventArgs e) { toolStripProgressBar1.Style = ProgressBarStyle.Continuous; this.toolStripStatusLabel1.Text = ""; bool fail = false; 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 { for (int i = 0; i < 5; i++) { //try to download two times if it fail eeprom = sp.download(1024); if (!sp.down_flag) { if (sp.keepalive()) Console.WriteLine("keepalive successful (iter " + i + ")"); else Console.WriteLine("keepalive fail (iter " + i + ")"); } else break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Failed to talk to bootloader"); fail = true; } sp.Close(); //Verify EEPROM version if (eeprom[CHK_VERSION] != VER) { // no match MessageBox.Show("The EEPROM mapping is outdated! An automatic update will start.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); BUT_ResetOSD_EEPROM(); //write defaults MessageBox.Show("EEPROM mapping updated!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!fail) { for (int a = 0; a < panelItems.Length; a++) { if (panelItems[a] != null) { if (panelItems[a].Item5 >= 0) { TreeNode[] tnArray = LIST_items.Nodes.Find(panelItems[a].Item1, true); if (tnArray.Length > 0) tnArray[0].Checked = (eeprom[panelItems[a].Item5] == 1); //LIST_items.SetItemCheckState(a, eeprom[panelItems[a].Item5] == 0 ? CheckState.Unchecked : CheckState.Checked); } if (panelItems[a].Item7 >= 0 || panelItems[a].Item6 >= 0) panelItems[a] = new Tuple<string, Func<int, int, int>, int, int, int, int, int>(panelItems[a].Item1, panelItems[a].Item2, eeprom[panelItems[a].Item6], eeprom[panelItems[a].Item7], panelItems[a].Item5, panelItems[a].Item6, panelItems[a].Item7); } } //Second panel for (int a = 0; a < panelItems2.Length; a++) { if (panelItems2[a] != null) { if (panelItems2[a].Item5 >= 0) { TreeNode[] tnArray = LIST_items2.Nodes.Find(panelItems2[a].Item1, true); if (tnArray.Length > 0) tnArray[0].Checked = (eeprom[panelItems2[a].Item5 + OffsetBITpanel] == 1); //LIST_items2.SetItemCheckState(a, eeprom[panelItems[a].Item5] == 0 ? CheckState.Unchecked : CheckState.Checked); } if (panelItems2[a].Item7 >= 0 || panelItems2[a].Item6 >= 0) panelItems2[a] = new Tuple<string, Func<int, int, int>, int, int, int, int, int>(panelItems2[a].Item1, panelItems2[a].Item2, eeprom[panelItems2[a].Item6 + OffsetBITpanel], eeprom[panelItems2[a].Item7 + OffsetBITpanel], panelItems2[a].Item5, panelItems2[a].Item6, panelItems2[a].Item7); } } } //Setup configuration panel pan.model_type = eeprom[MODEL_TYPE_ADD]; pan.fw_version1 = eeprom[FW_VERSION1_ADDR]; pan.fw_version2 = eeprom[FW_VERSION2_ADDR]; pan.fw_version3 = eeprom[FW_VERSION3_ADDR]; pan.cs_version1 = eeprom[CS_VERSION1_ADDR]; pan.cs_version2 = eeprom[CS_VERSION1_ADDR + 1]; pan.cs_version3 = eeprom[CS_VERSION1_ADDR + 2]; if((pan.fw_version1 == '0') && (pan.fw_version2 == '0') && (pan.fw_version3 == '0')) { lblFWModelType.Text = "Model Type found in OSD: Unknown or custom"; } else { lblFWModelType.Text = "Model Type found in OSD: " + (ModelType)pan.model_type + " " + pan.fw_version1 + "." + pan.fw_version2 + "." + pan.fw_version3; } if ((pan.cs_version1 == '0') && (pan.cs_version2 == '0') && (pan.cs_version3 == '0')) { lblLatestCharsetUploaded.Text = "Last charset uploaded to OSD: Unknown or custom "; } else { lblLatestCharsetUploaded.Text = "Last charset uploaded to OSD: Charset " + (pan.cs_version1 - '0').ToString() + "." + (pan.cs_version2 - '0').ToString() + "." + (pan.cs_version3 - '0').ToString(); } pan.sign_air_speed = eeprom[SIGN_AS_ON_ADDR]; pan.sign_ground_speed = eeprom[SIGN_GS_ON_ADDR]; pan.sign_home_altitude = eeprom[SIGN_HA_ON_ADDR]; pan.sign_msl_altitude = eeprom[SIGN_MSL_ON_ADDR]; cbxAirSpeedSign.Checked = (pan.sign_air_speed != 0); cbxGroundSpeedSign.Checked = (pan.sign_ground_speed != 0); cbxHomeAltitudeSign.Checked = (pan.sign_home_altitude != 0); cbxMslAltitudeSign.Checked = (pan.sign_msl_altitude != 0); cbxModelType.SelectedItem = (ModelType)pan.model_type; pan.converts = eeprom[measure_ADDR]; //Modify units if (pan.converts == 0) { UNITS_combo.SelectedIndex = 0; //metric STALL_label.Text = cbxModelType.SelectedItem.ToString() == "Copter" ? "Max VS (m/min) / 10" : "Stall Speed (km/h)"; OVERSPEED_label.Text = "Overspeed (km/h)"; } else if (pan.converts == 1) { UNITS_combo.SelectedIndex = 1; //imperial STALL_label.Text = cbxModelType.SelectedItem.ToString() == "Copter" ? "Max VS (ft/min) / 10" : "Stall Speed (mph)"; OVERSPEED_label.Text = "Overspeed (mph)"; } else //garbage value in EEPROM - default to metric { pan.converts = 0; //correct value UNITS_combo.SelectedIndex = 0; //metric STALL_label.Text = cbxModelType.SelectedItem.ToString() == "Copter" ? "Max VS (m/min) / 10" : "Stall Speed (km/h)"; OVERSPEED_label.Text = "Overspeed (km/h)"; } pan.overspeed = eeprom[overspeed_ADDR]; OVERSPEED_numeric.Value = pan.overspeed; pan.stall = eeprom[stall_ADDR]; STALL_numeric.Value = pan.stall; pan.battv = eeprom[battv_ADDR]; MINVOLT_numeric.Value = Convert.ToDecimal(pan.battv) / Convert.ToDecimal(10.0); pan.rssical = eeprom[OSD_RSSI_HIGH_ADDR]; //RSSI_numeric_max.Value = pan.rssical; pan.rssipersent = eeprom[OSD_RSSI_LOW_ADDR]; //RSSI_numeric_min.Value = pan.rssipersent; pan.rssiraw_on = eeprom[OSD_RSSI_RAW_ADDR]; updatingRSSI = true; RSSI_numeric_min.Minimum = 0; RSSI_numeric_min.Maximum = 2000; RSSI_numeric_max.Minimum = 0; RSSI_numeric_max.Maximum = 2000; RSSI_numeric_min.Value = 0; RSSI_numeric_max.Value = 0; RSSI_RAW.Checked = Convert.ToBoolean(pan.rssiraw_on % 2); if ((int)(pan.rssiraw_on / 2) == 0) { RSSI_numeric_min.Value = pan.rssipersent; RSSI_numeric_max.Value = pan.rssical; RSSI_numeric_min.Minimum = 0; RSSI_numeric_min.Maximum = 255; RSSI_numeric_max.Minimum = 0; RSSI_numeric_max.Maximum = 255; } else { RSSI_numeric_min.Value = pan.rssipersent * 10; RSSI_numeric_max.Value = pan.rssical * 10; RSSI_numeric_min.Minimum = 900; RSSI_numeric_min.Maximum = 2000; RSSI_numeric_max.Minimum = 900; RSSI_numeric_max.Maximum = 2000; } cbxRSSIChannel.SelectedIndex = (int)(pan.rssiraw_on / 2); updatingRSSI = false; pan.ch_toggle = eeprom[OSD_Toggle_ADDR]; if (pan.ch_toggle >= toggle_offset && pan.ch_toggle < 9) ONOFF_combo.SelectedIndex = pan.ch_toggle - toggle_offset; else ONOFF_combo.SelectedIndex = 0; //reject garbage from EEPROM pan.auto_screen_switch = eeprom[AUTO_SCREEN_SWITCH_ADD]; cbxWarningsAutoPanelSwitch.SelectedItem = (PanelsAutoSwitch)pan.auto_screen_switch; pan.switch_mode = eeprom[switch_mode_ADDR]; TOGGLE_BEH.Checked = Convert.ToBoolean(pan.switch_mode); pan.pal_ntsc = eeprom[PAL_NTSC_ADDR]; CHK_pal.Checked = Convert.ToBoolean(pan.pal_ntsc); pan.batt_warn_level = eeprom[OSD_BATT_WARN_ADDR]; BATT_WARNnumeric.Value = pan.batt_warn_level; pan.osd_battery_show_percentage = eeprom[OSD_BATT_SHOW_PERCENT_ADDR]; rbtBatteryPercent.Checked = Convert.ToBoolean(pan.osd_battery_show_percentage); rbtBatterymAh.Checked = !rbtBatteryPercent.Checked; pan.rssi_warn_level = eeprom[OSD_RSSI_WARN_ADDR]; RSSI_WARNnumeric.Value = pan.rssi_warn_level; pan.osd_brightness = eeprom[OSD_BRIGHTNESS_ADDR]; BRIGHTNESScomboBox.SelectedIndex = pan.osd_brightness; char[] str_call = new char[OSD_CALL_SIGN_TOTAL]; for (int i = 0; i < OSD_CALL_SIGN_TOTAL; i++) { str_call[i] = Convert.ToChar(eeprom[OSD_CALL_SIGN_ADDR + i]); Console.WriteLine("Call Sign read ", i, " is ", eeprom[OSD_CALL_SIGN_ADDR + i]); } pan.callsign_str = new string(str_call); CALLSIGNmaskedText.Text = pan.callsign_str; this.pALToolStripMenuItem_CheckStateChanged(EventArgs.Empty, EventArgs.Empty); this.nTSCToolStripMenuItem_CheckStateChanged(EventArgs.Empty, EventArgs.Empty); this.CHK_pal_CheckedChanged(EventArgs.Empty, EventArgs.Empty); osdDraw1(); osdDraw2(); //if (!fail) // MessageBox.Show("Done!"); if (sp.down_flag) { fwWasRead = true; MessageBox.Show("Done downloading data!"); } else MessageBox.Show("Failed to download data!"); sp.down_flag = false; }
//Write data to MinimOSD EPPROM private void BUT_WriteOSD_Click(object sender, EventArgs e) { toolStripProgressBar1.Style = ProgressBarStyle.Continuous; this.toolStripStatusLabel1.Text = ""; TabPage current = PANEL_tabs.SelectedTab; if (current.Text == "Panel 1") { //First Panel List<TreeNode> AllNodes = new List<TreeNode>(); foreach (TreeNode tn in LIST_items.Nodes) { foreach (TreeNode tn2 in tn.Nodes) { AllNodes.Add(tn2); } AllNodes.Add(tn); } foreach (TreeNode tn in AllNodes) { string str = tn.Text; foreach (var tuple in this.panelItems) { if ((tuple != null) && ((tuple.Item1 == str)) && tuple.Item5 != -1) { TreeNode[] trArray = LIST_items.Nodes.Find(str, true); eeprom[tuple.Item5] = (byte)(trArray[0].Checked ? 1 : 0); eeprom[tuple.Item6] = (byte)tuple.Item3; // x eeprom[tuple.Item7] = (byte)tuple.Item4; // y //Console.WriteLine(str); } } } } else if (current.Text == "Panel 2") { //Second Panel List<TreeNode> AllNodes = new List<TreeNode>(); foreach (TreeNode tn in LIST_items2.Nodes) { foreach (TreeNode tn2 in tn.Nodes) { AllNodes.Add(tn2); } AllNodes.Add(tn); } foreach (TreeNode tn in AllNodes) { string str = tn.Text; foreach (var tuple in this.panelItems2) { if ((tuple != null) && ((tuple.Item1 == str)) && tuple.Item5 != -1) { TreeNode[] trArray = LIST_items2.Nodes.Find(str, true); eeprom[tuple.Item5 + OffsetBITpanel] = (byte)(trArray[0].Checked ? 1 : 0); eeprom[tuple.Item6 + OffsetBITpanel] = (byte)tuple.Item3; // x eeprom[tuple.Item7 + OffsetBITpanel] = (byte)tuple.Item4; // y //Console.WriteLine(str); } } } } else if (current.Text == "Config") { //Setup configuration panel //It only checks if configuration screen model type matches fw model type if model type already have been read from eeprom //(either by pushing the "Read From OSD" or by uploading the fw) if (fwWasRead) { ModelType fwModelType = (ModelType)eeprom[MODEL_TYPE_ADD]; if (fwModelType != (ModelType)cbxModelType.SelectedItem) { if (MessageBox.Show("OSD firmware is of type " + fwModelType.ToString() + " and you have selected " + cbxModelType.SelectedText + " model type." + Environment.NewLine + "Are you sure you want to upload this configuration?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != System.Windows.Forms.DialogResult.Yes) return; } } eeprom[SIGN_AS_ON_ADDR] = pan.sign_air_speed; eeprom[SIGN_GS_ON_ADDR] = pan.sign_ground_speed; eeprom[SIGN_HA_ON_ADDR] = pan.sign_home_altitude; eeprom[SIGN_MSL_ON_ADDR] = pan.sign_msl_altitude; eeprom[measure_ADDR] = pan.converts; eeprom[overspeed_ADDR] = pan.overspeed; eeprom[stall_ADDR] = pan.stall; eeprom[battv_ADDR] = pan.battv; eeprom[OSD_RSSI_HIGH_ADDR] = pan.rssical; eeprom[OSD_RSSI_LOW_ADDR] = pan.rssipersent; eeprom[OSD_RSSI_RAW_ADDR] = pan.rssiraw_on; eeprom[AUTO_SCREEN_SWITCH_ADD] = pan.auto_screen_switch; eeprom[OSD_Toggle_ADDR] = pan.ch_toggle; eeprom[switch_mode_ADDR] = pan.switch_mode; eeprom[PAL_NTSC_ADDR] = pan.pal_ntsc; eeprom[OSD_BATT_WARN_ADDR] = pan.batt_warn_level; eeprom[OSD_BATT_SHOW_PERCENT_ADDR] = Convert.ToByte(pan.osd_battery_show_percentage); eeprom[OSD_RSSI_WARN_ADDR] = pan.rssi_warn_level; eeprom[OSD_BRIGHTNESS_ADDR] = pan.osd_brightness; //for (int i = 0; i < OSD_CALL_SIGN_TOTAL; i++) for (int i = 0; i < pan.callsign_str.Length; i++) { eeprom[OSD_CALL_SIGN_ADDR + i] = Convert.ToByte(pan.callsign_str[i]); Console.WriteLine("Call Sign ", i, " is ", eeprom[OSD_CALL_SIGN_ADDR + i]); } if (pan.callsign_str.Length < OSD_CALL_SIGN_TOTAL) for (int i = pan.callsign_str.Length; i < OSD_CALL_SIGN_TOTAL; i++) eeprom[OSD_CALL_SIGN_ADDR + i] = Convert.ToByte('\0'); } ArduinoSTK sp; try { if (comPort.IsOpen) comPort.Close(); sp = new ArduinoSTK(); sp.PortName = CMB_ComPort.Text; sp.BaudRate = 57600; sp.DataBits = 8; sp.StopBits = StopBits.One; sp.Parity = Parity.None; sp.DtrEnable = false; sp.RtsEnable = false; //added sp.Open(); } catch { MessageBox.Show("Error opening com port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (sp.connectAP()) { try { bool spupload_flag = false; //nav_up = sp.upload(eeprom, 0, OffsetBITpanel * npanel, 0); //conf_up = sp.upload(eeprom, measure_ADDR, (OSD_RSSI_LOW_ADDR - measure_ADDR), measure_ADDR); if (current.Text == "Panel 1") { for (int i = 0; i < 10; i++) { //try to upload two times if it fail spupload_flag = sp.upload(eeprom, (short)0, (short)OffsetBITpanel, (short)0); if (!spupload_flag) { if (sp.keepalive()) Console.WriteLine("keepalive successful (iter " + i + ")"); else Console.WriteLine("keepalive fail (iter " + i + ")"); } else break; } if (spupload_flag) MessageBox.Show("Done writing Panel 1 data!"); else MessageBox.Show("Failed to upload new Panel 1 data"); } else if (current.Text == "Panel 2") { for (int i = 0; i < 10; i++) { //try to upload two times if it fail spupload_flag = sp.upload(eeprom, (short)OffsetBITpanel, (short)(OffsetBITpanel), (short)OffsetBITpanel); if (!spupload_flag) { if (sp.keepalive()) Console.WriteLine("keepalive successful (iter " + i + ")"); else Console.WriteLine("keepalive fail (iter " + i + ")"); } else break; } if (spupload_flag) MessageBox.Show("Done writing Panel 2 data!"); else MessageBox.Show("Failed to upload new Panel 2 data"); } else if (current.Text == "Config") { for (int i = 0; i < 10; i++) { //try to upload two times if it fail spupload_flag = sp.upload(eeprom, (short)SIGN_MSL_ON_ADDR, (short)((OSD_CALL_SIGN_ADDR + OSD_CALL_SIGN_TOTAL) - SIGN_MSL_ON_ADDR + 1), (short)SIGN_MSL_ON_ADDR); if (!spupload_flag) { if (sp.keepalive()) Console.WriteLine("keepalive successful (iter " + i + ")"); else Console.WriteLine("keepalive fail (iter " + i + ")"); } else break; } if (spupload_flag) 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(); }
private ModelType GetModelType() { ModelType modelType = ModelType.Unknown; byte[] tempEeprom = null; bool fail = false; 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 ModelType.Unknown; } if (sp.connectAP()) { try { for (int i = 0; i < 5; i++) { //try to download two times if it fail tempEeprom = sp.download(1024); if (!sp.down_flag) { if (sp.keepalive()) Console.WriteLine("keepalive successful (iter " + i + ")"); else Console.WriteLine("keepalive fail (iter " + i + ")"); } else break; } modelType = (ModelType)tempEeprom[MODEL_TYPE_ADD]; } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Failed to talk to bootloader"); } sp.Close(); //Setup configuration panel return modelType; }
private void updateFirmwareToolStripMenuItem_Click(object sender, EventArgs e) { toolStripProgressBar1.Style = ProgressBarStyle.Continuous; this.toolStripStatusLabel1.Text = ""; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "*.hex|*.hex"; ofd.ShowDialog(); if (ofd.FileName != "") { byte[] FLASH; try { toolStripStatusLabel1.Text = "Reading Hex File"; statusStrip1.Refresh(); FLASH = readIntelHEXv2(new StreamReader(ofd.FileName)); } catch { MessageBox.Show("Bad Hex File"); return; } bool fail = false; 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; } toolStripStatusLabel1.Text = "Connecting to Board"; if (sp.connectAP()) { sp.Progress += new ArduinoSTK.ProgressEventHandler(sp_Progress); try { if (!sp.uploadflash(FLASH, 0, FLASH.Length, 0)) { if (sp.IsOpen) sp.Close(); MessageBox.Show("Upload failed. Lost sync. Try using Arduino to upload instead", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { fail = true; MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Failed to talk to bootloader"); } sp.Close(); if (!fail) { toolStripStatusLabel1.Text = "Done"; MessageBox.Show("Done!"); } else { toolStripStatusLabel1.Text = "Failed"; } } }
private bool UploadFirmware(string fileName) { if (string.IsNullOrEmpty(fileName)) return false; byte[] FLASH; bool spuploadflash_flag = false; try { toolStripStatusLabel1.Text = "Reading Hex File"; statusStrip1.Refresh(); FLASH = readIntelHEXv2(new StreamReader(fileName)); } catch { MessageBox.Show("Bad Hex File"); return false; } //bool fail = false; ArduinoSTK sp; try { if (comPort.IsOpen) comPort.Close(); sp = new ArduinoSTK(); sp.PortName = CMB_ComPort.Text; sp.BaudRate = 57600; sp.DataBits = 8; sp.StopBits = StopBits.One; sp.Parity = Parity.None; sp.DtrEnable = false; sp.RtsEnable = false; //added sp.Open(); } catch { MessageBox.Show("Error opening com port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } toolStripStatusLabel1.Text = "Connecting to Board"; if (sp.connectAP()) { sp.Progress += new ArduinoSTK.ProgressEventHandler(sp_Progress); try { for (int i = 0; i < 3; i++) //try to upload 3 times { //try to upload n times if it fail spuploadflash_flag = sp.uploadflash(FLASH, 0, FLASH.Length, 0); if (!spuploadflash_flag) { if (sp.keepalive()) Console.WriteLine("keepalive successful (iter " + i + ")"); else Console.WriteLine("keepalive fail (iter " + i + ")"); //toolStripStatusLabel1.Text = "Lost sync. Reconnecting..."; } else break; } //if (!sp.uploadflash(FLASH, 0, FLASH.Length, 0)) //{ // if (sp.IsOpen) // sp.Close(); // MessageBox.Show("Upload failed. Lost sync. Try using Arduino to upload instead", // "Error", // MessageBoxButtons.OK, // MessageBoxIcon.Warning); //} } catch (Exception ex) { //fail = true; MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Failed to talk to bootloader"); } sp.Close(); if (spuploadflash_flag) { toolStripStatusLabel1.Text = "Done"; MessageBox.Show("Done!"); } else { MessageBox.Show("Upload failed. Lost sync. Try using Arduino to upload instead", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); toolStripStatusLabel1.Text = "Failed"; } return true; }
private void BUT_WriteOSD_Click(object sender, EventArgs e) { toolStripProgressBar1.Style = ProgressBarStyle.Continuous; this.toolStripStatusLabel1.Text = ""; foreach (string str in this.LIST_items.Items) { foreach (var tuple in this.panelItems) { if ((tuple != null) && ((tuple.Item1 == str)) && tuple.Item5 != -1) { eeprom[tuple.Item5] = (byte)(this.LIST_items.CheckedItems.Contains(str) ? 1 : 0); eeprom[tuple.Item6] = (byte)tuple.Item3; // x eeprom[tuple.Item7] = (byte)tuple.Item4; // y Console.WriteLine(str); } } } 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, 200, 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_copy1280_Click(object sender, EventArgs e) { ArduinoSTK port = new ArduinoSTK(); port.BaudRate = 57600; port.DataBits = 8; port.StopBits = StopBits.One; port.Parity = Parity.None; port.DtrEnable = true; try { port.PortName = ArdupilotMega.MainV2.comportname; Console.WriteLine("Open Port"); port.Open(); Console.WriteLine("Connect AP"); if (port.connectAP()) { Console.WriteLine("Download AP"); byte[] EEPROM = new byte[1024 * 4]; for (int a = 0; a < 4 * 1024; a += 0x100) { port.setaddress(a); port.download(0x100).CopyTo(EEPROM, a); } Console.WriteLine("Verify State"); if (port.keepalive()) { StreamWriter sw = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"EEPROM1280.bin"); BinaryWriter bw = new BinaryWriter(sw.BaseStream); bw.Write(EEPROM, 0, EEPROM.Length); bw.Close(); Console.WriteLine("Download AP"); byte[] FLASH = new byte[1024 * 128]; for (int a = 0; a < FLASH.Length; a += 0x100) { port.setaddress(a); port.downloadflash(0x100).CopyTo(FLASH, a); } sw = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"FLASH1280.bin"); bw = new BinaryWriter(sw.BaseStream); bw.Write(FLASH, 0, FLASH.Length); bw.Close(); } else { MessageBox.Show("Communication Error - Bad data"); } } else { MessageBox.Show("Communication Error - no connection"); } port.Close(); } catch (Exception ex) { MessageBox.Show("Port Error? " + ex.ToString()); if (port != null && port.IsOpen) { port.Close(); } } }
private void BUT_ReadOSD_Click(object sender, EventArgs e) { toolStripProgressBar1.Style = ProgressBarStyle.Continuous; this.toolStripStatusLabel1.Text = ""; bool fail = false; 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 { for (int i = 0; i < 5; i++) { //try to download two times if it fail eeprom = sp.download(1024); if (!sp.down_flag) { if (sp.keepalive()) Console.WriteLine("keepalive successful (iter " + i + ")"); else Console.WriteLine("keepalive fail (iter " + i + ")"); } else break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Failed to talk to bootloader"); fail = true; } sp.Close(); //Verify EEPROM version if (eeprom[CHK_VERSION] != VER) { // no match MessageBox.Show("The EEPROM mapping is outdated! An automatic update will start.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); BUT_ResetOSD_EEPROM(); //write defaults MessageBox.Show("EEPROM mapping updated!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!fail) { for (int a = 0; a < panelItems.Length; a++) { if (panelItems[a] != null) { if (panelItems[a].Item5 >= 0) { TreeNode[] tnArray = LIST_items.Nodes.Find(panelItems[a].Item1, true); if (tnArray.Length > 0) tnArray[0].Checked = (eeprom[panelItems[a].Item5] == 1); //LIST_items.SetItemCheckState(a, eeprom[panelItems[a].Item5] == 0 ? CheckState.Unchecked : CheckState.Checked); } if (panelItems[a].Item7 >= 0 || panelItems[a].Item6 >= 0) panelItems[a] = new Tuple<string, Func<int, int, int>, int, int, int, int, int>(panelItems[a].Item1, panelItems[a].Item2, eeprom[panelItems[a].Item6], eeprom[panelItems[a].Item7], panelItems[a].Item5, panelItems[a].Item6, panelItems[a].Item7); } } //Second panel for (int a = 0; a < panelItems2.Length; a++) { if (panelItems2[a] != null) { if (panelItems2[a].Item5 >= 0) { TreeNode[] tnArray = LIST_items2.Nodes.Find(panelItems2[a].Item1, true); if (tnArray.Length > 0) tnArray[0].Checked = (eeprom[panelItems2[a].Item5 + OffsetBITpanel] == 1); //LIST_items2.SetItemCheckState(a, eeprom[panelItems[a].Item5] == 0 ? CheckState.Unchecked : CheckState.Checked); } if (panelItems2[a].Item7 >= 0 || panelItems2[a].Item6 >= 0) panelItems2[a] = new Tuple<string, Func<int, int, int>, int, int, int, int, int>(panelItems2[a].Item1, panelItems2[a].Item2, eeprom[panelItems2[a].Item6 + OffsetBITpanel], eeprom[panelItems2[a].Item7 + OffsetBITpanel], panelItems2[a].Item5, panelItems2[a].Item6, panelItems2[a].Item7); } } } //Setup configuration panel pan.converts = eeprom[measure_ADDR]; //Modify units if (pan.converts == 0) { UNITS_combo.SelectedIndex = 0; //metric STALL_label.Text = "Stall Speed (km/h)"; OVERSPEED_label.Text = "Overspeed (km/h)"; } else if (pan.converts == 1) { UNITS_combo.SelectedIndex = 1; //imperial STALL_label.Text = "Stall Speed (mph)"; OVERSPEED_label.Text = "Overspeed (mph)"; } else //garbage value in EEPROM - default to metric { pan.converts = 0; //correct value UNITS_combo.SelectedIndex = 0; //metric STALL_label.Text = "Stall Speed (km/h)"; OVERSPEED_label.Text = "Overspeed (km/h)"; } pan.overspeed = eeprom[overspeed_ADDR]; OVERSPEED_numeric.Value = pan.overspeed; pan.stall = eeprom[stall_ADDR]; STALL_numeric.Value = pan.stall; pan.battv = eeprom[battv_ADDR]; MINVOLT_numeric.Value = Convert.ToDecimal(pan.battv) / Convert.ToDecimal(10.0); pan.rssical = eeprom[OSD_RSSI_HIGH_ADDR]; RSSI_numeric_max.Value = pan.rssical; pan.rssipersent = eeprom[OSD_RSSI_LOW_ADDR]; RSSI_numeric_min.Value = pan.rssipersent; pan.rssiraw_on = eeprom[OSD_RSSI_RAW_ADDR]; RSSI_RAW.Checked = Convert.ToBoolean(pan.rssiraw_on); pan.ch_toggle = eeprom[OSD_Toggle_ADDR]; if (pan.ch_toggle >= toggle_offset && pan.ch_toggle < 9) ONOFF_combo.SelectedIndex = pan.ch_toggle - toggle_offset; else ONOFF_combo.SelectedIndex = 0; //reject garbage from EEPROM pan.switch_mode = eeprom[switch_mode_ADDR]; TOGGLE_BEH.Checked = Convert.ToBoolean(pan.switch_mode); pan.pal_ntsc = eeprom[PAL_NTSC_ADDR]; CHK_pal.Checked = Convert.ToBoolean(pan.pal_ntsc); pan.batt_warn_level = eeprom[OSD_BATT_WARN_ADDR]; BATT_WARNnumeric.Value = pan.batt_warn_level; pan.osd_battery_show_percentage = eeprom[OSD_BATT_SHOW_PERCENT_ADDR]; rbtBatteryPercent.Checked = Convert.ToBoolean(pan.osd_battery_show_percentage); rbtBatterymAh.Checked = !rbtBatteryPercent.Checked; pan.rssi_warn_level = eeprom[OSD_RSSI_WARN_ADDR]; RSSI_WARNnumeric.Value = pan.rssi_warn_level; pan.osd_brightness = eeprom[OSD_BRIGHTNESS_ADDR]; BRIGHTNESScomboBox.SelectedIndex = pan.osd_brightness; char[] str_call = new char[OSD_CALL_SIGN_TOTAL]; for (int i = 0; i < OSD_CALL_SIGN_TOTAL; i++){ str_call[i] = Convert.ToChar(eeprom[OSD_CALL_SIGN_ADDR + i]); Console.WriteLine("Call Sign read ", i, " is ", eeprom[OSD_CALL_SIGN_ADDR + i]); } pan.callsign_str = new string(str_call); CALLSIGNmaskedText.Text = pan.callsign_str; this.pALToolStripMenuItem_CheckStateChanged(EventArgs.Empty, EventArgs.Empty); this.nTSCToolStripMenuItem_CheckStateChanged(EventArgs.Empty, EventArgs.Empty); this.CHK_pal_CheckedChanged(EventArgs.Empty, EventArgs.Empty); osdDraw1(); osdDraw2(); //if (!fail) // MessageBox.Show("Done!"); if (sp.down_flag) MessageBox.Show("Done downloading data!"); else MessageBox.Show("Failed to download data!"); sp.down_flag = false; }
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()) { Console.WriteLine("starting"); port.uploadflash(FLASH, 0, FLASH.Length, 0); port.upload(EEPROM, 0, (short)EEPROM.Length, 0); Console.WriteLine("Uploaded"); } else { MessageBox.Show("Communication Error - no connection"); } port.Close(); } catch (Exception ex) { MessageBox.Show("Check port settings or Port in use? " + ex.ToString()); port.Close(); } }
//Write data to MinimOSD EPPROM private void BUT_WriteOSD_Click(object sender, EventArgs e) { toolStripProgressBar1.Style = ProgressBarStyle.Continuous; this.toolStripStatusLabel1.Text = ""; TabPage current = PANEL_tabs.SelectedTab; if (current.Text == "Panel 1") { //First Panel List<TreeNode> AllNodes = new List<TreeNode>(); foreach (TreeNode tn in LIST_items.Nodes) { foreach (TreeNode tn2 in tn.Nodes) { AllNodes.Add(tn2); } AllNodes.Add(tn); } foreach (TreeNode tn in AllNodes) { string str = tn.Text; foreach (var tuple in this.panelItems) { if ((tuple != null) && ((tuple.Item1 == str)) && tuple.Item5 != -1) { TreeNode[] trArray = LIST_items.Nodes.Find(str, true); eeprom[tuple.Item5] = (byte)(trArray[0].Checked ? 1 : 0); eeprom[tuple.Item6] = (byte)tuple.Item3; // x eeprom[tuple.Item7] = (byte)tuple.Item4; // y //Console.WriteLine(str); } } } } else if (current.Text == "Panel 2") { //Second Panel List<TreeNode> AllNodes = new List<TreeNode>(); foreach (TreeNode tn in LIST_items2.Nodes) { foreach (TreeNode tn2 in tn.Nodes) { AllNodes.Add(tn2); } AllNodes.Add(tn); } foreach (TreeNode tn in AllNodes) { string str = tn.Text; foreach (var tuple in this.panelItems2) { if ((tuple != null) && ((tuple.Item1 == str)) && tuple.Item5 != -1) { TreeNode[] trArray = LIST_items2.Nodes.Find(str, true); eeprom[tuple.Item5 + OffsetBITpanel] = (byte)(trArray[0].Checked ? 1 : 0); eeprom[tuple.Item6 + OffsetBITpanel] = (byte)tuple.Item3; // x eeprom[tuple.Item7 + OffsetBITpanel] = (byte)tuple.Item4; // y //Console.WriteLine(str); } } } } else if (current.Text == "Config") { //Setup configuration panel eeprom[measure_ADDR] = pan.converts; eeprom[overspeed_ADDR] = pan.overspeed; eeprom[stall_ADDR] = pan.stall; eeprom[battv_ADDR] = pan.battv; eeprom[OSD_RSSI_HIGH_ADDR] = pan.rssical; eeprom[OSD_RSSI_LOW_ADDR] = pan.rssipersent; eeprom[OSD_RSSI_RAW_ADDR] = pan.rssiraw_on; eeprom[OSD_Toggle_ADDR] = pan.ch_toggle; eeprom[switch_mode_ADDR] = pan.switch_mode; eeprom[PAL_NTSC_ADDR] = pan.pal_ntsc; eeprom[OSD_BATT_WARN_ADDR] = pan.batt_warn_level; eeprom[OSD_BATT_SHOW_PERCENT_ADDR] = Convert.ToByte(pan.osd_battery_show_percentage); eeprom[OSD_RSSI_WARN_ADDR] = pan.rssi_warn_level; eeprom[OSD_BRIGHTNESS_ADDR] = pan.osd_brightness; //for (int i = 0; i < OSD_CALL_SIGN_TOTAL; i++) for (int i = 0; i < pan.callsign_str.Length; i++) { eeprom[OSD_CALL_SIGN_ADDR + i] = Convert.ToByte(pan.callsign_str[i]); Console.WriteLine("Call Sign ", i, " is ", eeprom[OSD_CALL_SIGN_ADDR + i]); } if (pan.callsign_str.Length < OSD_CALL_SIGN_TOTAL) for (int i = pan.callsign_str.Length; i < OSD_CALL_SIGN_TOTAL; i++) eeprom[OSD_CALL_SIGN_ADDR + i] = Convert.ToByte('\0'); } ArduinoSTK sp; try { if (comPort.IsOpen) comPort.Close(); sp = new ArduinoSTK(); sp.PortName = CMB_ComPort.Text; sp.BaudRate = 57600; sp.DataBits = 8; sp.StopBits = StopBits.One; sp.Parity = Parity.None; sp.DtrEnable = false; sp.RtsEnable = false; //added sp.Open(); } catch { MessageBox.Show("Error opening com port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (sp.connectAP()) { try { bool spupload_flag = false; //nav_up = sp.upload(eeprom, 0, OffsetBITpanel * npanel, 0); //conf_up = sp.upload(eeprom, measure_ADDR, (OSD_RSSI_LOW_ADDR - measure_ADDR), measure_ADDR); if (current.Text == "Panel 1") { for(int i = 0; i < 10; i++) { //try to upload two times if it fail spupload_flag = sp.upload(eeprom, (short)0, (short)OffsetBITpanel, (short)0); if (!spupload_flag) { if (sp.keepalive()) Console.WriteLine("keepalive successful (iter "+ i + ")"); else Console.WriteLine("keepalive fail (iter " + i + ")"); } else break; } if (spupload_flag) MessageBox.Show("Done writing Panel 1 data!"); else MessageBox.Show("Failed to upload new Panel 1 data"); } else if (current.Text == "Panel 2") { for (int i = 0; i < 10; i++) { //try to upload two times if it fail spupload_flag = sp.upload(eeprom, (short)OffsetBITpanel, (short)(OffsetBITpanel), (short)OffsetBITpanel); if (!spupload_flag) { if (sp.keepalive()) Console.WriteLine("keepalive successful (iter " + i + ")"); else Console.WriteLine("keepalive fail (iter " + i + ")"); } else break; } if (spupload_flag) MessageBox.Show("Done writing Panel 2 data!"); else MessageBox.Show("Failed to upload new Panel 2 data"); } else if (current.Text == "Config") { for (int i = 0; i < 10; i++) { //try to upload two times if it fail spupload_flag = sp.upload(eeprom, (short)OSD_BATT_SHOW_PERCENT_ADDR, (short)((OSD_CALL_SIGN_ADDR + OSD_CALL_SIGN_TOTAL) - OSD_BATT_SHOW_PERCENT_ADDR + 1), (short)OSD_BATT_SHOW_PERCENT_ADDR); if (!spupload_flag) { if (sp.keepalive()) Console.WriteLine("keepalive successful (iter " + i + ")"); else Console.WriteLine("keepalive fail (iter " + i + ")"); } else break; } if (spupload_flag) 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(); }
private void BUT_upload_Click(object sender, EventArgs e) { ArduinoSTK comPort = new ArduinoSTK(); uploader.Uploader uploader = new uploader.Uploader(); try { comPort.PortName = MainV2.comPort.BaseStream.PortName; comPort.BaudRate = 115200; comPort.Open(); } catch { CustomMessageBox.Show("Invalid ComPort or in use"); return; } bool bootloadermode = false; uploader.ProgressEvent += new ProgressEventHandler(uploader_ProgressEvent); uploader.LogEvent += new LogEventHandler(uploader_LogEvent); try { uploader_ProgressEvent(0); uploader_LogEvent("Trying Bootloader Mode"); uploader.port = comPort; uploader.connect_and_sync(); uploader_LogEvent("In Bootloader Mode"); bootloadermode = true; } catch { comPort.Close(); comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate; comPort.Open(); uploader_LogEvent("Trying Firmware Mode"); bootloadermode = false; } if (bootloadermode || doConnect(comPort)) { if (getFirmware()) { uploader.IHex iHex = new uploader.IHex(); iHex.LogEvent += new LogEventHandler(iHex_LogEvent); iHex.ProgressEvent += new ProgressEventHandler(iHex_ProgressEvent); try { iHex.load(firmwarefile); } catch { CustomMessageBox.Show("Bad Firmware File"); goto exit; } if (!bootloadermode) { try { comPort.Write("AT&UPDATE\r\n"); string left = comPort.ReadExisting(); Console.WriteLine(left); Sleep(700); comPort.BaudRate = 115200; } catch { } } try { uploader.upload(comPort, iHex); } catch (Exception ex) { CustomMessageBox.Show("Upload Failed " + ex.Message); } } else { CustomMessageBox.Show("Failed to download new firmware"); } } else { CustomMessageBox.Show("Failed to identify Radio"); } exit: if (comPort.IsOpen) comPort.Close(); }
private void ReadCharsetVersion() { byte[] tempEeprom = new byte[1024]; bool fail = false; 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 { for (int i = 0; i < 5; i++) { //try to download two times if it fail tempEeprom = sp.download(1024); if (!sp.down_flag) { if (sp.keepalive()) Console.WriteLine("keepalive successful (iter " + i + ")"); else Console.WriteLine("keepalive fail (iter " + i + ")"); } else break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Failed to talk to bootloader"); fail = true; } sp.Close(); if (!fail) { lblLatestCharsetUploaded.Text = "Last charset uploaded to OSD: " + tempEeprom[CS_VERSION1_ADDR].ToString() + "." + tempEeprom[CS_VERSION1_ADDR + 1].ToString() + "." + tempEeprom[CS_VERSION1_ADDR + 2].ToString(); } }
private void BUT_ReadIOB_Click(object sender, EventArgs e) { toolStripProgressBar1.Style = ProgressBarStyle.Continuous; this.toolStripStatusLabel1.Text = ""; bool fail = false; 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 { eeprom = sp.download(1024); } catch (Exception ex) { fail = true; MessageBox.Show(ex.Message); } } else { MessageBox.Show("Failed to talk to bootloader"); fail = true; } sp.Close(); // txtLEFT.Text = eeprom[128]; int startmbind = 64; // Reading EEPROM values and put them to their right locations. if (!fail) { for (int pos = 0; pos < 16 ;pos++) { patterns[pos] = (ushort)((ushort)(eeprom[pos*2] << 8) + eeprom[pos*2 + 1]); Control[] ctls = this.Controls.Find("pattern" + (pos+1), true); if (ctls.Length > 0) { ((Pattern)ctls[0]).Value = patterns[pos]; ((Pattern)ctls[0]).FlightMode = (ushort)(eeprom[startmbind + pos * 2]); } } // Single values numLEFT.Value = eeprom[128]; numRIGHT.Value = eeprom[129]; numFRONT.Value = eeprom[130]; numREAR.Value = eeprom[131]; BAlarm_Percentage.Text = Convert.ToString(eeprom[152]); if (eeprom[140] == 1) CB_FrSky.Checked = true; if(eeprom[1000] >= 10) { BUT_WriteIOB.Enabled = true; LBL_NOTIFY.Visible = false; hasRead = true; } } printeeprom(); if (!fail) MessageBox.Show("Download settings...\n Done!"); if (eeprom[1012] < 5) { BUT_WriteIOB.Enabled = false; MessageBox.Show( "Please update firmware on\n" + "your jD-IOBoard. Version\n" + "needs to be at least v0.5\n\n" + "Click \"Download Firmware\" button\n" + "on General tab!!" , "Outdated Firmware", MessageBoxButtons.OK, MessageBoxIcon.Information); } }