upload() публичный Метод

Upload data at preset address
public upload ( byte data, short startfrom, short length, short startaddress ) : bool
data byte array to read from
startfrom short start array index
length short length to send
startaddress short sets eeprom start programing address
Результат bool
Пример #1
0
        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(); }
        }
Пример #2
0
        //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();
        }
Пример #3
0
        //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();
        }
Пример #4
0
        //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();
        }
Пример #5
0
        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();
        }
Пример #6
0
        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();
        }
Пример #7
0
        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(); }
        }
Пример #8
0
        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();
        }
Пример #9
0
        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();
        }
Пример #10
0
        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();
        }