Inheritance: SerialPort
コード例 #1
0
ファイル: DTR.cs プロジェクト: petalogix/ArduCAM_OSD
        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");
        }
コード例 #2
0
ファイル: OSD.cs プロジェクト: petalogix/ArduCAM_OSD
        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!");
        }
コード例 #3
0
ファイル: OSD.cs プロジェクト: Ziege-One/HottBtOSD
        //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();
        }
コード例 #4
0
ファイル: OSD.cs プロジェクト: Ziege-One/HottBtOSD
        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();
        }
コード例 #5
0
ファイル: 3DRradio.cs プロジェクト: kaldpils/ardupilotone
        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();
        }
コード例 #6
0
ファイル: temp.cs プロジェクト: 415porto/ardupilotone
        private void BUT_flashup_Click(object sender, EventArgs e)
        {
            byte[] FLASH = new byte[1];

            try
            {
                StreamReader sr = new StreamReader(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex");
                FLASH = readIntelHEXv2(sr);
                sr.Close();

            }
            catch (Exception ex) { MessageBox.Show("Failed to read firmware.hex : " + ex.Message); }
            ArduinoComms port = new ArduinoSTK();

            if (DialogResult.Yes == MessageBox.Show("is this a 1280?", "", MessageBoxButtons.YesNo))
            {
                port = new ArduinoSTK();
                port.BaudRate = 57600;
            }
            else
            {
                port = new ArduinoSTKv2();
                port.BaudRate = 115200;
            }

            port.DataBits = 8;
            port.StopBits = StopBits.One;
            port.Parity = Parity.None;
            port.DtrEnable = true;

            try
            {
                port.PortName = ArdupilotMega.MainV2.comportname;

                port.Open();

                if (port.connectAP())
                {
                    Console.WriteLine("starting");

                    port.uploadflash(FLASH, 0, FLASH.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(); }
        }
コード例 #7
0
ファイル: temp.cs プロジェクト: 415porto/ardupilotone
        private void BUT_dleeprom_Click(object sender, EventArgs e)
        {
            ArduinoComms port = new ArduinoSTK();

            if (DialogResult.Yes == MessageBox.Show("is this a 1280?", "", MessageBoxButtons.YesNo))
            {
                port = new ArduinoSTK();
                port.BaudRate = 57600;
            }
            else
            {
                port = new ArduinoSTKv2();
                port.BaudRate = 115200;
            }
            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 + @"EEPROM.bin");
                        BinaryWriter bw = new BinaryWriter(sw.BaseStream);
                        bw.Write(EEPROM, 0, 1024 * 4);
                        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(); } }
        }
コード例 #8
0
ファイル: 3DRradio.cs プロジェクト: wangbo121/ardupilot-mega
        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();
            }
        }
コード例 #9
0
ファイル: MainV2.cs プロジェクト: 415porto/ardupilotone
        private void MenuConnect_Click(object sender, EventArgs e)
        {
            givecomport = false;

            if (comPort.BaseStream.IsOpen)
            {
                try
                {
                    if (talk != null) // cancel all pending speech
                        talk.SpeakAsyncCancelAll();

                    if (comPort.logfile != null)
                        comPort.logfile.Close();

                    comPort.BaseStream.DtrEnable = false;
                    comPort.Close();
                }
                catch { }

                this.MenuConnect.BackgroundImage = global::ArdupilotMega.Properties.Resources.connect;
            }
            else
            {
                if (CMB_serialport.Text == "TCP")
                {
                    comPort.BaseStream = new TcpSerial();
                }
                else
                    if (CMB_serialport.Text == "UDP")
                    {
                        comPort.BaseStream = new UdpSerial();
                    }
                    else
                    {
                        comPort.BaseStream = new SerialPort();
                    }
                try
                {
                    comPort.BaseStream.BaudRate = int.Parse(CMB_baudrate.Text);
                }
                catch { }
                comPort.BaseStream.DataBits = 8;
                comPort.BaseStream.StopBits = (StopBits)Enum.Parse(typeof(StopBits), "1");
                comPort.BaseStream.Parity = (Parity)Enum.Parse(typeof(Parity), "None");

                comPort.BaseStream.DtrEnable = false;

                if (config["CHK_resetapmonconnect"] == null || bool.Parse(config["CHK_resetapmonconnect"].ToString()) == true)
                    comPort.BaseStream.DtrEnable = true;

                if (DialogResult.OK != Common.MessageShowAgain("Mavlink Connect", "Make sure your APM slider switch is in Flight Mode (away from RC pins)"))
                {
                    return;
                }

                try
                {
                    if (comPort.logfile != null)
                        comPort.logfile.Close();
                    try
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"logs");
                        comPort.logfile = new BinaryWriter(File.Open(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"logs" + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd hh-mm-ss") + ".tlog", FileMode.CreateNew));
                    }
                    catch { MessageBox.Show("Failed to create log - wont log this session"); } // soft fail

                    comPort.BaseStream.PortName = CMB_serialport.Text;
                    comPort.Open(true);

                    if (comPort.param["SYSID_SW_TYPE"] != null)
                    {
                        if (float.Parse(comPort.param["SYSID_SW_TYPE"].ToString()) == 10)
                        {
                            TOOL_APMFirmware.SelectedIndex = TOOL_APMFirmware.Items.IndexOf(Firmwares.ArduCopter2);
                        }
                        else if (float.Parse(comPort.param["SYSID_SW_TYPE"].ToString()) == 0)
                        {
                            TOOL_APMFirmware.SelectedIndex = TOOL_APMFirmware.Items.IndexOf(Firmwares.ArduPlane);
                        }
                    }

                    cs.firmware = APMFirmware;

                    config[CMB_serialport.Text + "_BAUD"] = CMB_baudrate.Text;

                    if (config["loadwpsonconnect"] != null && bool.Parse(config["loadwpsonconnect"].ToString()) == true)
                    {
                        MenuFlightPlanner_Click(null, null);
                        FlightPlanner.BUT_read_Click(null, null);
                    }

                    this.MenuConnect.BackgroundImage = global::ArdupilotMega.Properties.Resources.disconnect;
                }
                catch (Exception ex)
                {
                    try
                    {
                        comPort.Close();
                    }
                    catch { }
                    try
                    {
                        string version = ArduinoDetect.DetectVersion(comPort.BaseStream.PortName);
                        ArduinoComms port = new ArduinoSTK();
                        if (version == "1280")
                        {
                            port = new ArduinoSTK();
                            port.BaudRate = 57600;
                        }
                        else if (version == "2560")
                        {
                            port = new ArduinoSTKv2();
                            port.BaudRate = 115200;
                        }
                        else { throw new Exception("Can not determine APM board type"); }
                        port.PortName = comPort.BaseStream.PortName;
                        port.DtrEnable = true;
                        port.Open();
                        if (port.connectAP())
                        {
                            byte[] buffer = port.download(20);
                            port.Close();

                            if (buffer[0] != 'A' || buffer[1] != 'P') // this is the apvar header
                            {
                                MessageBox.Show("You dont appear to have uploaded a firmware yet,\n\nPlease goto the firmware page and upload one.");
                                return;
                            }
                            else
                            {
                                Console.WriteLine("Valid eeprom contents");
                            }
                        }
                    }
                    catch { }
                    MessageBox.Show("Is your CLI switch in Flight position?\n(this is required for MAVlink comms)\n\n" + ex.ToString());
                    return;
                }
            }
        }
コード例 #10
0
ファイル: DTR.cs プロジェクト: petalogix/ArduCAM_OSD
        void ser(ArduinoSTK sp)
        {
            if (sp.connectAP())
            {
                try
                {
                    byte[] test = sp.download(1024);
                    Console.WriteLine("Download OK!!");
                } catch (Exception ex) {
                    Console.WriteLine(ex.Message);
                }
            }
            else
            {
                Console.WriteLine("Failed connect");
            }

            //System.Threading.Thread.Sleep(2000);
        }
コード例 #11
0
        private void BUT_flashdl_Click(object sender, EventArgs e)
        {
            byte[] FLASH = new byte[256 * 1024];

            ArduinoComms port = new ArduinoSTK();

            if (DialogResult.Yes == CustomMessageBox.Show("is this a 1280?", "", MessageBoxButtons.YesNo))
            {
                port          = new ArduinoSTK();
                port.BaudRate = 57600;
            }
            else
            {
                port          = new ArduinoSTKv2();
                port.BaudRate = 115200;
            }
            port.DataBits  = 8;
            port.StopBits  = StopBits.One;
            port.Parity    = Parity.None;
            port.DtrEnable = true;

            port.PortName = ArdupilotMega.MainV2.comPortName;
            try
            {
                port.Open();

                System.Threading.Thread.Sleep(100);

                if (port.connectAP())
                {
                    // waypoints
                    int   start  = 0;
                    short length = 0x100;

                    log.Info(start + " to " + FLASH.Length);

                    while (start < FLASH.Length)
                    {
                        log.Info("Doing " + length + " at " + start);
                        port.setaddress(start);
                        port.downloadflash(length).CopyTo(FLASH, start);
                        start += length;
                    }

                    StreamWriter sw = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + 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 + @"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();

                    log.Info("Downloaded");
                }
                else
                {
                    CustomMessageBox.Show("Communication Error - no connection");
                }
                port.Close();
            }
            catch (Exception ex) { CustomMessageBox.Show("Port in use? " + ex.ToString()); port.Close(); }
        }
コード例 #12
0
        private void BUT_wipeeeprom_Click(object sender, EventArgs e)
        {
            byte[] EEPROM = new byte[4 * 1024];

            for (int i = 0; i < EEPROM.Length; i++)
            {
                EEPROM[i] = 0xff;
            }

            ArduinoComms port = new ArduinoSTK();

            if (DialogResult.Yes == CustomMessageBox.Show("is this a 1280?", "", MessageBoxButtons.YesNo))
            {
                port          = new ArduinoSTK();
                port.BaudRate = 57600;
            }
            else
            {
                port          = new ArduinoSTKv2();
                port.BaudRate = 115200;
            }
            port.DataBits  = 8;
            port.StopBits  = StopBits.One;
            port.Parity    = Parity.None;
            port.DtrEnable = true;

            port.PortName = ArdupilotMega.MainV2.comPortName;
            try
            {
                port.Open();

                if (port.connectAP())
                {
                    // waypoints
                    int start = 0;
                    int end   = 1024 * 4;

                    log.Info(start + " to " + end);
                    port.upload(EEPROM, (short)start, (short)(end - start), (short)start);

                    if (port.keepalive())
                    {
                        // Config

                        if (port.keepalive())
                        {
                            System.Threading.Thread.Sleep(2000);
                            //MessageBox.Show("Upload Completed");
                        }
                        else
                        {
                            CustomMessageBox.Show("Communication Error - WPs wrote but no config");
                        }
                    }
                    else
                    {
                        CustomMessageBox.Show("Communication Error - Bad data");
                    }
                }
                else
                {
                    CustomMessageBox.Show("Communication Error - no connection");
                }
                port.Close();
            }
            catch (Exception ex) { CustomMessageBox.Show("Port in use? " + ex.ToString()); port.Close(); }
        }
コード例 #13
0
        } // Swap

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter           = "EEPROM.bin|*.bin";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.InitialDirectory = Path.GetDirectoryName(Application.ExecutablePath);

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    StreamReader sr     = new StreamReader(openFileDialog1.FileName);
                    BinaryReader br     = new BinaryReader(sr.BaseStream);
                    byte[]       EEPROM = br.ReadBytes(1024 * 4);
                    br.Close();
                    sr.Close();

                    ArduinoComms port = new ArduinoSTK();

                    if (DialogResult.Yes == CustomMessageBox.Show("is this a 1280?", "", MessageBoxButtons.YesNo))
                    {
                        port          = new ArduinoSTK();
                        port.BaudRate = 57600;
                    }
                    else
                    {
                        port          = new ArduinoSTKv2();
                        port.BaudRate = 115200;
                    }

                    port.DataBits  = 8;
                    port.StopBits  = StopBits.One;
                    port.Parity    = Parity.None;
                    port.DtrEnable = true;

                    port.PortName = ArdupilotMega.MainV2.comPortName;
                    try
                    {
                        port.Open();

                        if (port.connectAP())
                        {
                            // waypoints
                            int start = 0;
                            int end   = 1024 * 4;

                            log.Info(start + " to " + end);
                            port.upload(EEPROM, (short)start, (short)(end - start), (short)start);

                            if (port.keepalive())
                            {
                                // Config

                                if (port.keepalive())
                                {
                                    System.Threading.Thread.Sleep(2000);
                                    //MessageBox.Show("Upload Completed");
                                }
                                else
                                {
                                    CustomMessageBox.Show("Communication Error - WPs wrote but no config");
                                }
                            }
                            else
                            {
                                CustomMessageBox.Show("Communication Error - Bad data");
                            }
                        }
                        else
                        {
                            CustomMessageBox.Show("Communication Error - no connection");
                        }
                        port.Close();
                    }
                    catch (Exception ex) { CustomMessageBox.Show("Port in use? " + ex.ToString()); port.Close(); }
                }
                catch (Exception) { CustomMessageBox.Show("Error reading file"); }
            }
        }
コード例 #14
0
ファイル: OSD.cs プロジェクト: jhaenchen/minimosd-extra
        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);
        }
コード例 #15
0
ファイル: MainForm.cs プロジェクト: Dmitrydsc/arducodes
        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();
        }
コード例 #16
0
ファイル: OSD.cs プロジェクト: jhaenchen/minimosd-extra
        //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();
        }
コード例 #17
0
ファイル: MainForm.cs プロジェクト: Dmitrydsc/arducodes
        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();
        }
コード例 #18
0
ファイル: temp.cs プロジェクト: 415porto/ardupilotone
        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(); }
        }
コード例 #19
0
ファイル: MainForm.cs プロジェクト: Dmitrydsc/arducodes
        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!");
        }
コード例 #20
0
ファイル: temp.cs プロジェクト: 415porto/ardupilotone
        private void BUT_flashdl_Click(object sender, EventArgs e)
        {
            byte[] FLASH = new byte[256 * 1024];

            ArduinoComms port = new ArduinoSTK();

            if (DialogResult.Yes == MessageBox.Show("is this a 1280?", "", MessageBoxButtons.YesNo))
            {
                port = new ArduinoSTK();
                port.BaudRate = 57600;
            }
            else
            {
                port = new ArduinoSTKv2();
                port.BaudRate = 115200;
            }
            port.DataBits = 8;
            port.StopBits = StopBits.One;
            port.Parity = Parity.None;
            port.DtrEnable = true;

            port.PortName = ArdupilotMega.MainV2.comportname;
            try
            {
                port.Open();

                System.Threading.Thread.Sleep(100);

                if (port.connectAP())
                {
                    // waypoints
                    int start = 0;
                    short length = 0x100;

                    Console.WriteLine(start + " to " + FLASH.Length);

                    while (start < FLASH.Length)
                    {
                        Console.WriteLine("Doing " + length + " at " + start);
                        port.setaddress(start);
                        port.downloadflash(length).CopyTo(FLASH, start);
                        start += length;
                    }

                    StreamWriter sw = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + 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 + @"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();

                    Console.WriteLine("Downloaded");
                }
                else
                {
                    MessageBox.Show("Communication Error - no connection");
                }
                port.Close();
            }
            catch (Exception ex) { MessageBox.Show("Port in use? " + ex.ToString()); port.Close(); }
        }
コード例 #21
0
ファイル: temp.cs プロジェクト: kaldpils/ardupilotone
        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(); } }
        }
コード例 #22
0
ファイル: temp.cs プロジェクト: 415porto/ardupilotone
        private void BUT_wipeeeprom_Click(object sender, EventArgs e)
        {
            byte[] EEPROM = new byte[4*1024];

            for (int i = 0; i < EEPROM.Length;i++)
            {
                EEPROM[i] = 0xff;
            }

            ArduinoComms port = new ArduinoSTK();

            if (DialogResult.Yes == MessageBox.Show("is this a 1280?", "", MessageBoxButtons.YesNo))
            {
                port = new ArduinoSTK();
                port.BaudRate = 57600;
            }
            else
            {
                port = new ArduinoSTKv2();
                port.BaudRate = 115200;
            }
            port.DataBits = 8;
            port.StopBits = StopBits.One;
            port.Parity = Parity.None;
            port.DtrEnable = true;

            port.PortName = ArdupilotMega.MainV2.comportname;
            try
            {
                port.Open();

                if (port.connectAP())
                {
                    // waypoints
                    int start = 0;
                    int end = 1024*4;

                        Console.WriteLine(start + " to " + end);
                        port.upload(EEPROM, (short)start, (short)(end - start), (short)start);

                        if (port.keepalive())
                        {
                            // Config

                            if (port.keepalive())
                            {
                                System.Threading.Thread.Sleep(2000);
                                //MessageBox.Show("Upload Completed");
                            }
                            else
                            {
                                MessageBox.Show("Communication Error - WPs wrote but no config");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Communication Error - Bad data");
                        }
                }
                else
                {
                    MessageBox.Show("Communication Error - no connection");
                }
                port.Close();
            }
            catch (Exception ex) { MessageBox.Show("Port in use? " + ex.ToString()); port.Close(); }
        }
コード例 #23
0
ファイル: OSD.cs プロジェクト: kosmikkosmik/MinimOSD-Extra
        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();
        }
コード例 #24
0
ファイル: OSD.cs プロジェクト: Ziege-One/HottBtOSD
        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();
            }
        }
コード例 #25
0
ファイル: OSD.cs プロジェクト: kosmikkosmik/MinimOSD-Extra
        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;
        }
コード例 #26
0
ファイル: OSD.cs プロジェクト: Ziege-One/HottBtOSD
        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;
        }
コード例 #27
0
ファイル: OSD.cs プロジェクト: kosmikkosmik/MinimOSD-Extra
        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;
        }
コード例 #28
0
ファイル: OSD.cs プロジェクト: petalogix/ArduCAM_OSD
        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";
                }
            }
        }
コード例 #29
0
ファイル: OSD.cs プロジェクト: svpcom/minimosd-extra
		public ArduinoSTK OpenArduino () {
			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 = true;
//				sp.RtsEnable = false; //added

				sp.Open();
				return sp;
            }
            catch { 
				MessageBox.Show("Error opening com port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return null; 
			}
			
		}
コード例 #30
0
ファイル: OSD.cs プロジェクト: petalogix/ArduCAM_OSD
        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();
        }
コード例 #31
0
        public static int decodeApVar(string comport, string version)
        {
            ArduinoComms port = new ArduinoSTK();
            if (version == "1280")
            {
                port = new ArduinoSTK();
                port.BaudRate = 57600;
            }
            else if (version == "2560" || version == "2560-2")
            {
                port = new ArduinoSTKv2();
                port.BaudRate = 115200;
            }
            else { return -1; }
            port.PortName = comport;
            port.DtrEnable = true;
            port.Open();
            port.connectAP();
            byte[] buffer = port.download(1024 * 4);
            port.Close();

            if (buffer[0] != 'A' || buffer[1] != 'P') // this is the apvar header
            {
                return -1;
            }
            else
            {
                if (buffer[0] == 'A' && buffer[1] == 'P' && buffer[2] == 2)
                { // apvar header and version
                    int pos = 4;
                    byte key = 0;
                    while (pos < (1024 * 4))
                    {
                        int size = buffer[pos] & 63;
                        pos++;
                        key = buffer[pos];
                        pos++;

                        Console.Write("{0:X4}: key {1} size {2}\n ", pos - 2, key, size + 1);

                        if (key == 0xff)
                        {
                            Console.WriteLine("end sentinal at {0}", pos - 2);
                            break;
                        }

                        if (key == 0)
                        {
                            //Array.Reverse(buffer, pos, 2);
                            return BitConverter.ToUInt16(buffer, pos);
                        }

                        for (int i = 0; i <= size; i++)
                        {
                            Console.Write(" {0:X2}", buffer[pos]);
                            pos++;
                        }
                        Console.WriteLine();
                    }
                }
            }
            return -1;
        }
コード例 #32
0
ファイル: OSD.cs プロジェクト: jhaenchen/minimosd-extra
        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;
        }
コード例 #33
0
ファイル: temp.cs プロジェクト: 415porto/ardupilotone
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "EEPROM.bin|*.bin";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.InitialDirectory = Path.GetDirectoryName(Application.ExecutablePath);

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    StreamReader sr = new StreamReader(openFileDialog1.FileName);
                    BinaryReader br = new BinaryReader(sr.BaseStream);
                    byte[] EEPROM = br.ReadBytes(1024 * 4);
                    br.Close();
                    sr.Close();

                    ArduinoComms port = new ArduinoSTK();

                    if (DialogResult.Yes == MessageBox.Show("is this a 1280?", "", MessageBoxButtons.YesNo))
                    {
                        port = new ArduinoSTK();
                        port.BaudRate = 57600;
                    }
                    else
                    {
                        port = new ArduinoSTKv2();
                        port.BaudRate = 115200;
                    }

            port.DataBits = 8;
            port.StopBits = StopBits.One;
            port.Parity = Parity.None;
            port.DtrEnable = true;

            port.PortName = ArdupilotMega.MainV2.comportname;
            try
            {
                port.Open();

                if (port.connectAP())
                {
                    // waypoints
                    int start = 0;
                    int end = 1024*4;

                        Console.WriteLine(start + " to " + end);
                        port.upload(EEPROM, (short)start, (short)(end - start), (short)start);

                        if (port.keepalive())
                        {
                            // Config

                            if (port.keepalive())
                            {
                                System.Threading.Thread.Sleep(2000);
                                //MessageBox.Show("Upload Completed");
                            }
                            else
                            {
                                MessageBox.Show("Communication Error - WPs wrote but no config");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Communication Error - Bad data");
                        }
                }
                else
                {
                    MessageBox.Show("Communication Error - no connection");
                }
                port.Close();
            }
            catch (Exception ex) { MessageBox.Show("Port in use? " + ex.ToString()); port.Close(); }
                }
                catch (Exception) { MessageBox.Show("Error reading file"); }
            }
        }
コード例 #34
0
ファイル: OSD.cs プロジェクト: jhaenchen/minimosd-extra
        //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();
        }
コード例 #35
0
        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();
                                   }
            }
        }