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


C# ICommsSerial.ReadByte方法代码示例

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


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

示例1: Serial_ReadLine

        string Serial_ReadLine(ICommsSerial comPort)
        {
            StringBuilder sb = new StringBuilder();
            DateTime Deadline = DateTime.Now.AddMilliseconds(comPort.ReadTimeout);

            while (DateTime.Now < Deadline)
            {
                if (comPort.BytesToRead > 0)
                {
                    byte data = (byte)comPort.ReadByte();
                    sb.Append((char)data);
                    if (data == '\n')
                        break;
                }
            }

            return sb.ToString();
        }
开发者ID:LeoTosti,项目名称:x-drone,代码行数:18,代码来源:3DRradio.cs

示例2: Upload

        public static void Upload(string firmwarebin, ICommsSerial comPort)
        {
            var fs = new FileStream(firmwarebin, FileMode.Open);
            var len = (int)fs.Length;
            len = (len % 128) == 0 ? len / 128 : (len / 128) + 1;
            var startlen = len;

            int a = 1;
            while (len > 0)
            {
                if (LogEvent != null)
                    LogEvent("Uploading block " + a + "/" + startlen);

                XModem.SendBlock(fs, comPort, a);
                // responce ACK
                var ack = comPort.ReadByte();
                while (ack == 'C')
                    ack = comPort.ReadByte();

                if (ack==ACK)
                {
                    len--;
                    a++;

                    if (ProgressEvent != null)
                        ProgressEvent(len / startlen);
                }
                else if (ack==NAK)
                {
                    CustomMessageBox.Show("Corrupted packet. Please power cycle and try again.\r\n", "Warning",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    len = 0;
                }
            }

            // boot
            comPort.Write("b");
        }
开发者ID:AndersonRayner,项目名称:MissionPlanner,代码行数:38,代码来源:XModem.cs

示例3: upload_xmodem

        bool upload_xmodem(ICommsSerial comPort)
        {
            // try xmodem mode
            // xmodem - short cts to ground
            try
            {
                uploader_LogEvent("Trying XModem Mode");
                //comPort.BaudRate = 57600;
                comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
                comPort.ReadTimeout = 1000;

                Thread.Sleep(2000);
                var tempd = comPort.ReadExisting();
                Console.WriteLine(tempd);
                comPort.Write("U");
                Thread.Sleep(1000);
                var resp1 = Serial_ReadLine(comPort); // echo
                var resp2 = Serial_ReadLine(comPort); // echo 2
                var tempd2 = comPort.ReadExisting(); // posibly bootloader info / use to sync
                // identify
                comPort.Write("i");
                // responce is rfd900....
                var resp3 = Serial_ReadLine(comPort); //echo
                var resp4 = Serial_ReadLine(comPort); // newline
                var resp5 = Serial_ReadLine(comPort); // bootloader info
                uploader_LogEvent(resp5);
                if (resp5.Contains("RFD900"))
                {
                    // start upload
                    comPort.Write("u");
                    var resp6 = Serial_ReadLine(comPort); // echo
                    var resp7 = Serial_ReadLine(comPort); // Ready
                    if (resp7.Contains("Ready"))
                    {
                        comPort.ReadTimeout = 3500;
                        // responce is C
                        var isC = comPort.ReadByte();
                        var temp = comPort.ReadExisting();
                        if (isC == 'C')
                        {
                            XModem.LogEvent += uploader_LogEvent;
                            XModem.ProgressEvent += uploader_ProgressEvent;
                            // start file send
                            XModem.Upload(@"SiK900x.bin",
                                comPort);
                            XModem.LogEvent -= uploader_LogEvent;
                            XModem.ProgressEvent -= uploader_ProgressEvent;
                            return true;
                        }
                    }
                }
            }
            catch (Exception ex2)
            {
                log.Error(ex2);
            }

            return false;
        }
开发者ID:nitbot,项目名称:MissionPlanner,代码行数:59,代码来源:Sikradio.cs

示例4: Sleep

 void Sleep(int ms, ICommsSerial comPortT)
 {
     DateTime start = DateTime.Now;
     Console.WriteLine("sleep in");
     while (start.AddMilliseconds(ms) > DateTime.Now)
     {
         while (comPortT.BytesToRead > 0)
         {
             Console.Write((char)comPortT.ReadByte());
         }
         System.Threading.Thread.Sleep(1);
     }
     Console.WriteLine("sleep out");
 }
开发者ID:jdillg,项目名称:ardupilotone,代码行数:14,代码来源:Setup.cs


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