当前位置: 首页>>代码示例>>C#>>正文


C# ICommsSerial.Close方法代码示例

本文整理汇总了C#中ICommsSerial.Close方法的典型用法代码示例。如果您正苦于以下问题:C# ICommsSerial.Close方法的具体用法?C# ICommsSerial.Close怎么用?C# ICommsSerial.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICommsSerial的用法示例。


在下文中一共展示了ICommsSerial.Close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Terminal_Load

        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();

                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; }
//.........这里部分代码省略.........
开发者ID:hzeera,项目名称:MissionPlanner,代码行数:101,代码来源:Terminal.cs

示例2: start_Terminal

        private void start_Terminal(bool px4)
        {
            try
            {
                MainV2.comPort.giveComport = true;

                comPort = MainV2.comPort.BaseStream;

                if (comPort.IsOpen)
                {
                    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(200);
                }

                comPort.ReadBufferSize = 1024 * 1024;

                comPort.PortName = MainV2.comPortName;

                // test moving baud rate line

                log.Info("About to open " + comPort.PortName);

                comPort.Open();

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

                if (px4)
                {
                    TXT_terminal.AppendText("Rebooting");

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

                    if (buffer.Length > 0)
                    {
                        log.Info("got packet - sending reboot via mavlink");
                        MainV2.comPort.giveComport = true;
                        MainV2.comPort.doReboot(false);
                        try
                        {
                            comPort.Close();
                        }
                        catch { }

                    }
                    else
                    {
                        log.Info("no packet - sending reboot via console");
                        MainV2.comPort.giveComport = true;
                        MainV2.comPort.BaseStream.Write("exit\rreboot\r");
                        try
                        {
                            comPort.Close();
                        }
                        catch { }

                    }

                    MainV2.comPort.giveComport = true;

                    TXT_terminal.AppendText("Waiting for reboot");

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

                    int a = 0;
                   // while (a < 5)
                    {
                        try
                        {
                            comPort.Open();
                        }
                        catch { }
                        System.Threading.Thread.Sleep(200);
                        a++;
                    }

                }
                else
                {
                    comPort.toggleDTR();
                }

                try
                {
                    comPort.DiscardInBuffer();
//.........这里部分代码省略.........
开发者ID:neolu,项目名称:MissionPlanner,代码行数:101,代码来源:Terminal.cs

示例3: upload

		/// <summary>
		/// Upload the specified image_data.
		/// </summary>
		/// <param name='image_data'>
		/// Image_data to be uploaded.
		/// </param>
		public void upload (ICommsSerial on_port, IHex image_data, bool use_mavlink = false)
		{
			progress (0);
			
			port = on_port;
			
			try {
                connect_and_sync();
				upload_and_verify (image_data);
				cmdReboot ();
			} catch {
				if (port.IsOpen)
					port.Close ();
				throw;
			}
		}
开发者ID:mileslee1987,项目名称:MissionPlanner,代码行数:22,代码来源:Uploader.cs

示例4: CloseStream

 private void CloseStream(ICommsSerial basestream)
 {
     try
     {
         if (basestream.IsOpen)
             basestream.Close();
     }
     catch { }
 }
开发者ID:lmhonorio,项目名称:TrimaresRouter,代码行数:9,代码来源:MsgRouter.cs


注:本文中的ICommsSerial.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。