示例#1
0
 private void BUTtests_Click(object sender, EventArgs e)
 {
     if (comPort.IsOpen)
     {
         try
         {
             System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
             byte[] data = encoding.GetBytes("exit\rtest\r?\r\n");
             comPort.Write(data, 0, data.Length);
         }
         catch { }
     }
     TXT_terminal.Focus();
 }
示例#2
0
 private void BUTradiosetup_Click(object sender, EventArgs e)
 {
     if (comPort.IsOpen)
     {
         try
         {
             var encoding = new ASCIIEncoding();
             var data     = encoding.GetBytes("exit\rsetup\r\nradio\r");
             comPort.Write(data, 0, data.Length);
         }
         catch
         {
         }
     }
     TXT_terminal.Focus();
 }
示例#3
0
        private void startreadthread()
        {
            Console.WriteLine("Terminal_Load run " + threadrun + " " + comPort.IsOpen);

            BUT_disconnect.Enabled = true;

            var t11 = new Thread(delegate()
            {
                threadrun = true;

                Console.WriteLine("Terminal thread start run run " + threadrun + " " + comPort.IsOpen);

                try
                {
                    comPort.Write("\r");
                }
                catch
                {
                }

                // 10 sec
                waitandsleep(10000);

                Console.WriteLine("Terminal thread 1 run " + threadrun + " " + comPort.IsOpen);

                // 100 ms
                readandsleep(100);

                Console.WriteLine("Terminal thread 2 run " + threadrun + " " + comPort.IsOpen);

                try
                {
                    if (!inlogview && comPort.IsOpen)
                    {
                        comPort.Write("\n\n\n");
                    }

                    // 1 secs
                    if (!inlogview && comPort.IsOpen)
                    {
                        readandsleep(1000);
                    }

                    if (!inlogview && comPort.IsOpen)
                    {
                        comPort.Write("\r\r\r?\r");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Terminal thread 3 " + ex);
                    ChangeConnectStatus(false);
                    threadrun = false;
                    return;
                }

                Console.WriteLine("Terminal thread 3 run " + threadrun + " " + comPort.IsOpen);

                while (threadrun)
                {
                    try
                    {
                        Thread.Sleep(10);

                        if (!threadrun)
                        {
                            break;
                        }
                        if (this.Disposing)
                        {
                            break;
                        }
                        if (inlogview)
                        {
                            continue;
                        }
                        if (!comPort.IsOpen)
                        {
                            Console.WriteLine("Comport Closed");
                            ChangeConnectStatus(false);
                            break;
                        }
                        if (comPort.BytesToRead > 0)
                        {
                            comPort_DataReceived(null, null);
                        }

                        if (comPort is MAVLinkSerialPort)
                        {
                            if (lastsend.AddMilliseconds(500) > DateTime.Now)
                            {
                                // 20 hz
                                ((MAVLinkSerialPort)comPort).timeout = 50;
                            }
                            else
                            {
                                // 5 hz
                                ((MAVLinkSerialPort)comPort).timeout = 200;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Terminal thread 4 " + ex);
                    }
                }

                threadrun = false;
                try
                {
                    comPort.DtrEnable = false;
                }
                catch
                {
                }
                try
                {
                    Console.WriteLine("term thread close run " + threadrun + " " + comPort.IsOpen);
                    ChangeConnectStatus(false);
                    comPort.Close();
                }
                catch
                {
                }

                Console.WriteLine("Comport thread close run " + threadrun);
            });

            t11.IsBackground = true;
            t11.Name         = "Terminal serial thread";
            t11.Start();

            // doesnt seem to work on mac
            //comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived);

            if (IsDisposed || Disposing)
            {
                return;
            }

            TXT_terminal.AppendText("Opened com port\r\n");
            inputStartPos = TXT_terminal.SelectionStart;


            TXT_terminal.Focus();
        }
示例#4
0
        private void Terminal_Load(object sender, EventArgs e)
        {
            try
            {
                if (comPort.IsOpen)
                {
                    comPort.Close();
                }

                comPort.ReadBufferSize = 1024 * 1024;

                comPort.PortName = MainV2.comPort.BaseStream.PortName;

                comPort.Open();

                comPort.toggleDTR();

                var t11 = new Thread(delegate()
                {
                    threadrun = true;

                    var start = DateTime.Now;

                    while ((DateTime.Now - start).TotalMilliseconds < 2000)
                    {
                        try
                        {
                            if (comPort.BytesToRead > 0)
                            {
                                comPort_DataReceived(null, null);
                            }
                        }
                        catch
                        {
                            return;
                        }
                    }
                    try
                    {
                        comPort.Write("\n\n\n");
                    }
                    catch
                    {
                        return;
                    }
                    while (threadrun)
                    {
                        try
                        {
                            Thread.Sleep(10);
                            if (!comPort.IsOpen)
                            {
                                break;
                            }
                            if (comPort.BytesToRead > 0)
                            {
                                comPort_DataReceived(null, null);
                            }
                        }
                        catch
                        {
                        }
                    }

                    comPort.DtrEnable = false;

                    try
                    {
                        //if (sw != null)
                        //  sw.Close();
                    }
                    catch
                    {
                    }

                    if (threadrun == false)
                    {
                        comPort.Close();
                    }
                    Console.WriteLine("Comport thread close");
                });
                t11.IsBackground = true;
                t11.Name         = "Terminal serial thread";
                t11.Start();

                // doesnt seem to work on mac
                //comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived);

                TXT_terminal.AppendText("Opened com port\r\n");
            }
            catch (Exception)
            {
                TXT_terminal.AppendText("Cant open serial port\r\n");
                return;
            }

            TXT_terminal.Focus();
        }
示例#5
0
        private void start_Terminal(bool px4)
        {
            setcomport();

            try
            {
                if (MainV2.comPort != null && MainV2.comPort.BaseStream != null && MainV2.comPort.BaseStream.IsOpen)
                {
                    MainV2.comPort.BaseStream.Close();
                }

                if (comPort.IsOpen)
                {
                    Console.WriteLine("Terminal Start - Close Port");
                    threadrun = false;
                    //  if (DialogResult.Cancel == CustomMessageBox.Show("The port is open\n Continue?", "Continue", MessageBoxButtons.YesNo))
                    {
                        //  return;
                    }

                    comPort.Close();

                    // allow things to cleanup
                    System.Threading.Thread.Sleep(400);
                }

                comPort.ReadBufferSize = 1024 * 1024 * 4;

                comPort.PortName = MainV2.comPortName;

                // test moving baud rate line

                comPort.BaudRate = int.Parse(MainV2._connectionControl.CMB_baudrate.Text);

                if (px4)
                {
                    TXT_terminal.AppendText("Rebooting " + MainV2.comPortName + " at " + comPort.BaudRate + "\n");
                    // keep it local
                    using (MAVLinkInterface mine = new MAVLinkInterface())
                    {
                        mine.BaseStream.PortName = MainV2.comPortName;
                        mine.BaseStream.BaudRate = comPort.BaudRate;

                        mine.giveComport = true;
                        mine.BaseStream.Open();

                        // check if we are a mavlink stream
                        byte[] buffer = mine.readPacket();

                        if (buffer.Length > 0)
                        {
                            log.Info("got packet - sending reboot via mavlink");
                            TXT_terminal.AppendText("Via Mavlink\n");
                            mine.doReboot(false);
                            try
                            {
                                mine.BaseStream.Close();
                            }
                            catch { }
                        }
                        else
                        {
                            log.Info("no packet - sending reboot via console");
                            TXT_terminal.AppendText("Via Console\n");
                            try
                            {
                                mine.BaseStream.Write("reboot\r");
                                mine.BaseStream.Write("exit\rreboot\r");
                            }
                            catch { }
                            try
                            {
                                mine.BaseStream.Close();
                            }
                            catch { }
                        }
                    }

                    TXT_terminal.AppendText("Waiting for reboot\n");

                    // wait 7 seconds for px4 reboot
                    log.Info("waiting for reboot");
                    DateTime deadline = DateTime.Now.AddSeconds(9);
                    while (DateTime.Now < deadline)
                    {
                        System.Threading.Thread.Sleep(500);
                        Application.DoEvents();
                    }

                    int a = 0;
                    while (a < 5)
                    {
                        try
                        {
                            if (!comPort.IsOpen)
                            {
                                comPort.Open();
                            }
                        }
                        catch { }
                        System.Threading.Thread.Sleep(200);
                        a++;
                    }
                }
                else
                {
                    log.Info("About to open " + comPort.PortName);

                    comPort.Open();

                    log.Info("toggle dtr");

                    comPort.toggleDTR();
                }

                try
                {
                    comPort.DiscardInBuffer();
                }
                catch { }

                Console.WriteLine("Terminal_Load run " + threadrun + " " + comPort.IsOpen);

                BUT_disconnect.Enabled = true;

                System.Threading.Thread t11 = new System.Threading.Thread(delegate()
                {
                    threadrun = true;

                    Console.WriteLine("Terminal thread start run run " + threadrun + " " + comPort.IsOpen);

                    try
                    {
                        comPort.Write("\r");
                    }
                    catch { }

                    // 10 sec
                    waitandsleep(10000);

                    Console.WriteLine("Terminal thread 1 run " + threadrun + " " + comPort.IsOpen);

                    // 100 ms
                    readandsleep(100);

                    Console.WriteLine("Terminal thread 2 run " + threadrun + " " + comPort.IsOpen);

                    try
                    {
                        if (!inlogview && comPort.IsOpen)
                        {
                            comPort.Write("\n\n\n");
                        }

                        // 1 secs
                        if (!inlogview && comPort.IsOpen)
                        {
                            readandsleep(1000);
                        }

                        if (!inlogview && comPort.IsOpen)
                        {
                            comPort.Write("\r\r\r?\r");
                        }
                    }
                    catch (Exception ex) { Console.WriteLine("Terminal thread 3 " + ex.ToString()); ChangeConnectStatus(false); threadrun = false; return; }

                    Console.WriteLine("Terminal thread 3 run " + threadrun + " " + comPort.IsOpen);

                    while (threadrun)
                    {
                        try
                        {
                            System.Threading.Thread.Sleep(10);

                            if (!threadrun)
                            {
                                break;
                            }
                            if (this.Disposing)
                            {
                                break;
                            }
                            if (inlogview)
                            {
                                continue;
                            }
                            if (!comPort.IsOpen)
                            {
                                Console.WriteLine("Comport Closed");
                                ChangeConnectStatus(false);
                                break;
                            }
                            if (comPort.BytesToRead > 0)
                            {
                                comPort_DataReceived((object)null, (SerialDataReceivedEventArgs)null);
                            }
                        }
                        catch (Exception ex) { Console.WriteLine("Terminal thread 4 " + ex.ToString()); }
                    }

                    threadrun = false;
                    try
                    {
                        comPort.DtrEnable = false;
                    }
                    catch { }
                    try
                    {
                        Console.WriteLine("term thread close run " + threadrun + " " + comPort.IsOpen);
                        ChangeConnectStatus(false);
                        comPort.Close();
                    }
                    catch { }

                    Console.WriteLine("Comport thread close run " + threadrun);
                });
                t11.IsBackground = true;
                t11.Name         = "Terminal serial thread";
                t11.Start();

                // doesnt seem to work on mac
                //comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived);

                if (this.IsDisposed || this.Disposing)
                {
                    return;
                }

                TXT_terminal.AppendText("Opened com port\r\n");
                inputStartPos = TXT_terminal.SelectionStart;
            }
            catch (Exception ex) { log.Error(ex); TXT_terminal.AppendText("Cant open serial port\r\n"); return; }

            TXT_terminal.Focus();
        }
示例#6
0
        private void Terminal_Load(object sender, EventArgs e)
        {
            try
            {
                MainV2.givecomport = true;

                if (comPort.IsOpen)
                {
                    comPort.Close();
                }

                comPort.ReadBufferSize = 1024 * 1024;

                comPort.PortName = MainV2.comportname;

                comPort.Open();

                comPort.toggleDTR();

                System.Threading.Thread t11 = new System.Threading.Thread(delegate()
                {
                    threadrun = true;

                    DateTime start = DateTime.Now;

                    while ((DateTime.Now - start).TotalMilliseconds < 2000)
                    {
                        try
                        {
                            if (comPort.BytesToRead > 0)
                            {
                                comPort_DataReceived((object)null, (SerialDataReceivedEventArgs)null);
                            }
                        }
                        catch { return; }
                    }

                    comPort.Write("\n\n\n");

                    while (threadrun)
                    {
                        try
                        {
                            System.Threading.Thread.Sleep(10);
                            if (inlogview)
                            {
                                continue;
                            }
                            if (!comPort.IsOpen)
                            {
                                break;
                            }
                            if (comPort.BytesToRead > 0)
                            {
                                comPort_DataReceived((object)null, (SerialDataReceivedEventArgs)null);
                            }
                        }
                        catch { }
                    }

                    comPort.DtrEnable = false;

                    if (threadrun == false)
                    {
                        comPort.Close();
                    }
                    Console.WriteLine("Comport thread close");
                });
                t11.IsBackground = true;
                t11.Name         = "Terminal serial thread";
                t11.Start();
                MainV2.threads.Add(t11);

                // doesnt seem to work on mac
                //comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived);

                TXT_terminal.AppendText("Opened com port\r\n");
                inputStartPos = TXT_terminal.SelectionStart;
            }
            catch (Exception) { TXT_terminal.AppendText("Cant open serial port\r\n"); return; }

            TXT_terminal.Focus();
        }
示例#7
0
        private void Terminal_Load(object sender, EventArgs e)
        {
            try
            {
                MainV2.comPort.giveComport = true;

                comPort = MainV2.comPort.BaseStream;

                if (comPort.IsOpen)
                {
                    comPort.Close();
                }

                comPort.ReadBufferSize = 1024 * 1024;

                comPort.PortName = MainV2.comPortName;

                comPort.BaudRate = int.Parse(MainV2._connectionControl.CMB_baudrate.Text);

                comPort.Open();

                comPort.toggleDTR();

                MainV2.comPort.doReboot();

                comPort.DiscardInBuffer();

                Console.WriteLine("Terminal_Load");

                System.Threading.Thread t11 = new System.Threading.Thread(delegate()
                {
                    threadrun = true;

                    Console.WriteLine("Terminal thread start");

                    // 10 sec
                    waitandsleep(10000);

                    Console.WriteLine("Terminal thread 1");

                    // 100 ms
                    readandsleep(100);

                    Console.WriteLine("Terminal thread 2");

                    try
                    {
                        if (!inlogview)
                        {
                            comPort.Write("\n\n\n");
                        }

                        // 1 secs
                        if (!inlogview)
                        {
                            readandsleep(1000);
                        }

                        if (!inlogview)
                        {
                            comPort.Write("\r\r\r?\r");
                        }
                    }
                    catch (Exception ex) { Console.WriteLine("Terminal thread 3 " + ex.ToString()); threadrun = false; return; }

                    Console.WriteLine("Terminal thread 3");

                    while (threadrun)
                    {
                        try
                        {
                            System.Threading.Thread.Sleep(10);
                            if (inlogview)
                            {
                                continue;
                            }
                            if (!comPort.IsOpen)
                            {
                                break;
                            }
                            if (comPort.BytesToRead > 0)
                            {
                                comPort_DataReceived((object)null, (SerialDataReceivedEventArgs)null);
                            }
                        }
                        catch (Exception ex) { Console.WriteLine("Terminal thread 4 " + ex.ToString()); }
                    }

                    threadrun = false;
                    try
                    {
                        comPort.DtrEnable = false;
                    }
                    catch { }
                    try
                    {
                        Console.WriteLine("term thread close");
                        comPort.Close();
                    }
                    catch { }

                    Console.WriteLine("Comport thread close");
                });
                t11.IsBackground = true;
                t11.Name         = "Terminal serial thread";
                t11.Start();

                // doesnt seem to work on mac
                //comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived);

                TXT_terminal.AppendText("Opened com port\r\n");
                inputStartPos = TXT_terminal.SelectionStart;
            }
            catch (Exception) { TXT_terminal.AppendText("Cant open serial port\r\n"); return; }

            TXT_terminal.Focus();
        }