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


C# SerialPort.DiscardOutBuffer方法代码示例

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


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

示例1: Button_Click

        private void Button_Click(object sender, RoutedEventArgs e)//按钮打开事件
        {
            try
            {
                open.IsEnabled = false;
                stop.IsEnabled = true;
                control.IsEnabled = true;
                port = new SerialPort();
                port.BaudRate = 115200;
                port.PortName = COMName.Text;
                port.DataBits = 8;

                port.Open();
                port.DiscardInBuffer();
                port.DiscardOutBuffer();
                MessageBox.Show("串口打开成功", "系统提示");
            }
            catch (IOException ex)
            {
                MessageBox.Show("串口打开失败" + ex, "系统提示");
                return;
            }
            _keepReading = true;
            _readThread = new Thread(ReadPort);
            _readThread.Start();
        }
开发者ID:UEChip,项目名称:UENSimulation,代码行数:26,代码来源:Port.xaml.cs

示例2: CompanySerialIO

 public CompanySerialIO(int serialPortNumber)
 {
     _semaphore = new Semaphore(1, 1);
     _serialPort = new SerialPort("COM" + serialPortNumber);
     _serialPort.ReadTimeout = 1000;
     _serialPort.Open();
     _serialPort.DiscardInBuffer(); // Discard unsynchronized data
     _serialPort.DiscardOutBuffer(); // Discard unsynchronized data
 }
开发者ID:FernandoToigo,项目名称:Forecourt.Drivers,代码行数:9,代码来源:CompanySerialIO.cs

示例3: theLoop

        public void theLoop()
        {
            int listenPort = 11000;
            UdpClient listener = new UdpClient(listenPort);
            IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);
            SerialPort portCOM1 = new SerialPort();
            try{
                portCOM1 = new SerialPort("/dev/ttyS0", 115200, Parity.None, 8, StopBits.One);
                portCOM1.Open();
            }
            catch(Exception ee)
            {
                Console.WriteLine("Not connected to COM1");
                Console.WriteLine(ee.Message.ToString());
            }
            string received_data;
            byte[] received_byte_array;

            bool done = false;

            while(!done)
            {
                Console.WriteLine("Waiting For Data - press (q) to quit");
                received_byte_array = listener.Receive(ref groupEP);
                received_data = "";
                for(int i = 0; i < received_byte_array.Length; i++)
                {
                    received_data = received_data+received_byte_array[i]+" ";
                }
                Console.WriteLine("Recived Data From {0}: {1}", groupEP.ToString(), received_data);
                try{
                    portCOM1.Write(received_byte_array,0,received_byte_array.Length);		// write what was recived on UDP to com 1
                    Console.WriteLine("Wrote data to COM1 @ 115200 8N1");
                }
                catch(Exception ee)
                {
                    Console.WriteLine(ee.Message.ToString());
                    try{
                        portCOM1.Close();
                        portCOM1.DiscardOutBuffer();
                        portCOM1.DiscardInBuffer();

                        listener.Close();

                        listener = new UdpClient(listenPort);
                 		groupEP = new IPEndPoint(IPAddress.Any, listenPort);
                    }
                    catch(Exception eee)
                    {
                        Console.WriteLine(eee.Message.ToString());
                    }

                }

            }
        }
开发者ID:thedancomplex,项目名称:Hubo-UDP-to-Serial--UDP2Serial-,代码行数:56,代码来源:Main.cs

示例4: Open

        /* open serial port */
        public void Open(string portName, uint baudRate)
        {
            /* initialize serial port */
            sp = new SerialPort(portName, (int)baudRate, Parity.Even, 8);
            /* open serial port */
            sp.Open();

            /* discard buffers */
            sp.DiscardInBuffer();
            sp.DiscardOutBuffer();
        }
开发者ID:MightyDevices,项目名称:STBootLib,代码行数:12,代码来源:STBoot.cs

示例5: SerialComm

 public SerialComm(string port)
 {
     serial = new SerialPort(port, 115200, Parity.None, 8, StopBits.One)
     {
         Handshake = Handshake.None, //Handshake not needed
     };
     serial.DataReceived += SerialDataReceived;
     serial.Open();
     serial.DiscardOutBuffer();
     serial.DiscardInBuffer();
 }
开发者ID:chinnyannieb,项目名称:iValuable,代码行数:11,代码来源:SerialComm.cs

示例6: ExecCommand

        public static string ExecCommand(SerialPort port, string command, int responseTimeout, string errorMessage)
        {
            port.DiscardOutBuffer();
            port.DiscardInBuffer();
            receiveNow.Reset();
            port.Write(command + "\r");

            string input = ReadResponse(port, responseTimeout);
            if ((input.Length == 0) || ((!input.EndsWith("\r\n> ")) && (!input.EndsWith("\r\nOK\r\n"))))
                throw new ApplicationException("No success message was received.");
            return input;
        }
开发者ID:mangmaytinh,项目名称:doanD2T,代码行数:12,代码来源:sms.cs

示例7: Modem

 public Modem(SerialPort port)
 {            
     serialPort = port;
     //init port
     EnsurePortOpen();
     //we will handle read timeout manually, system implementation is not consistent
     serialPort.ReadTimeout = 0;
     serialPort.WriteTimeout = SerialPort.InfiniteTimeout;
     serialPort.DiscardInBuffer();
     serialPort.DiscardOutBuffer();
     serialPort.NewLine = "\r";
     serialPort.Encoding = Encoding.ASCII;
 }
开发者ID:huguogang,项目名称:Modem.NET,代码行数:13,代码来源:Modem.cs

示例8: ClearBuffer

 public static bool ClearBuffer(SerialPort port)
 {
     try
     {
         port.DiscardOutBuffer();
         port.DiscardInBuffer();
         return true;
     }
     catch(Exception ex)
     {
         FileWorker.WriteEventFile(DateTime.Now, "ASubDriver", "ClearBuffer", ex.Message);
         return false;
     }
 }
开发者ID:EugeneGudima,项目名称:Reflecta,代码行数:14,代码来源:ASubDriver.cs

示例9: gainsmessageasync_test

        public void gainsmessageasync_test()
        {
            SerialPort port = new SerialPort("COM7", 250000, Parity.None, 8, StopBits.One);

            SerialPortInterface portInterface = new SerialPortInterface(port);

            using (FlightComputerInterface fcInt = new FlightComputerInterface(portInterface))
            {
                fcInt.Open();
                port.DiscardInBuffer();
                port.DiscardOutBuffer();

                FlightComputerTelemetryMessage gains = null;

                for (int i = 0; i < 1000; i++)
                {
                    gains = (FlightComputerTelemetryMessage) fcInt.Receive();

                    Assert.IsTrue(gains.LateralInnerLoopGain == 1.1f);
                    Assert.IsTrue(gains.LongitudeInnerLoopGain == 1.2f);
                    Assert.IsTrue(gains.PitchAngularVelocityGain == 1.3f);
                    Assert.IsTrue(gains.RollAngularVelocityGain == 1.4f);
                    Assert.IsTrue(gains.XAntiWindupGain == 1.5f);
                    Assert.IsTrue(gains.XDerivativeGain == 1.6f);
                    Assert.IsTrue(gains.XIntegralGain == 1.7f);
                    Assert.IsTrue(gains.XProportionalGain == 1.8f);
                    Assert.IsTrue(gains.YAntiWindupGain == 1.9f);
                    Assert.IsTrue(gains.YawAntiWindupGain == 1.0f);
                    Assert.IsTrue(gains.YawDerivativeGain == 1.11f);
                    Assert.IsTrue(gains.YawIntegralGain == 1.12f);
                    Assert.IsTrue(gains.YawProportionalGain == 1.13f);
                    Assert.IsTrue(gains.YDerivativeGain == 1.14f);
                    Assert.IsTrue(gains.YIntegralGain == 1.15f);
                    Assert.IsTrue(gains.YProportionalGain == 1.16f);
                    Assert.IsTrue(gains.ZAntiWindupGain == 1.17f);
                    Assert.IsTrue(gains.ZDerivativeGain == 1.18f);
                    Assert.IsTrue(gains.ZIntegralGain == 1.19f);
                    Assert.IsTrue(gains.ZProportionalGain == i);

                    Debug.WriteLine(i);

                    fcInt.Transmit(gains);
                }

                gains = (FlightComputerTelemetryMessage) fcInt.Receive();

                Assert.IsTrue(gains.ZProportionalGain == 12);

            }
        }
开发者ID:helicopter,项目名称:UAVHelicopter,代码行数:50,代码来源:FlightComputerInterfaceTest.cs

示例10: Link

		public Link (int BUFSIZE)
		{
			// Create a new SerialPort object with default settings.
			serialPort = new SerialPort("/dev/ttyS1",115200,Parity.None,8,StopBits.One);

			if(!serialPort.IsOpen)
				serialPort.Open();

			buffer = new byte[(BUFSIZE*2)];

			serialPort.ReadTimeout = 500;
			serialPort.DiscardInBuffer ();
			serialPort.DiscardOutBuffer ();
		}
开发者ID:SimonKaeseler,项目名称:SimonKaeseler,代码行数:14,代码来源:Link.cs

示例11: identify

        private bool identify(ref Dictionary<string, Arduino> _ArduinoMap, string _potentialArduino) {
            if (!_ArduinoMap.ContainsKey(_potentialArduino)) {
                SerialPort temp;
                try {
                    temp = new SerialPort(_potentialArduino);
                    temp.Open();
                    string toWrite = Arduino_Codes.IDENTITY_QUERY;
                    temp.DiscardOutBuffer();
                    temp.DiscardInBuffer();
                    Thread.Sleep(100);
                    temp.WriteLine(toWrite);
                    Thread.Sleep(200);
                    temp.WriteLine(toWrite);
                    Thread.Sleep(200);
                    string ID = temp.ReadExisting();
                    if (ID.Contains(Arduino_Codes.ARM_IDENTITY_RESPONSE))
                    {
                        _ArduinoMap.Add(Arduino_Codes.ARM_IDENTITY, new Arduino(temp, Arduino_Codes.ARM_IDENTITY));
                        return true;
                    }
                    else if (ID.Contains(Arduino_Codes.HAND_IDENTITY_RESPONSE))
                    {
                        _ArduinoMap.Add(Arduino_Codes.HAND_IDENTITY, new Arduino(temp, Arduino_Codes.HAND_IDENTITY));
                        return true;
                    }
                    else if (ID.Contains(Arduino_Codes.DRIVEFRONT_IDENTITY_RESPONSE))
                    {
                        _ArduinoMap.Add(Arduino_Codes.DRIVEFRONT_IDENTITY, new Arduino(temp, Arduino_Codes.DRIVEFRONT_IDENTITY));
                        return true;
                    }
                    else if (ID.Contains(Arduino_Codes.DRIVEBACK_IDENTITY_RESPONSE))
                    {
                        _ArduinoMap.Add(Arduino_Codes.DRIVEBACK_IDENTITY, new Arduino(temp, Arduino_Codes.DRIVEBACK_IDENTITY));
                        return true;
                    }
                    else if (ID.Contains(Arduino_Codes.PT_IDENTITY_RESPONSE))
                    {
                        _ArduinoMap.Add(Arduino_Codes.PT_IDENTITY, new Arduino(temp, Arduino_Codes.PT_IDENTITY));
                        return true;
                    }

                    temp.Dispose(); //Gets rid of safe handle issue! Or at least appears to!
                }
                catch {
                    return false;
                }
            }
            return false;
        }
开发者ID:hintofherring,项目名称:RoboUtes-2014,代码行数:49,代码来源:ArduinoManager.cs

示例12: Program

 public Program(string port)
 {
     serial = new SerialPort(port, 9600, Parity.None, 8, StopBits.One)
     {
         Handshake = Handshake.RequestToSend,
         NewLine = "\r",
     };
     serial.DataReceived +=(o,e)=>
     {
         var num = serial.BytesToRead;
         if (num == 0)
             return;
         var data = new byte[num];
         serial.Read(data, 0, num);
         foreach (var b in data)
         {
             switch (phase)
             {
                 case 0:
                     if (b == 0x0A)
                         phase = 1;
                     else
                         message.Append((char) b);
                     break;
                 case 1:
                     phase = (b == 0x30) ? 2 : 0;
                     break;
                 case 2:
                     phase = (b == 0x30) ? 3 : 0;
                     break;
                 case 3:
                     if (b == 0x0D)
                     {
                         if (message.Length > 0 && verbose)
                             Console.WriteLine(message);
                         lastMessage = message.ToString();
                         message.Clear();
                         syncEvent.Set();
                     }
                     phase = 0;
                     break;
             }
         }
     };
     serial.Open();
     //serial.RtsEnable = true;
     serial.DiscardOutBuffer();
     serial.DiscardInBuffer();
 }
开发者ID:dihic,项目名称:LairdBLETool,代码行数:49,代码来源:Program.cs

示例13: GetTemperature

 public XmlElement GetTemperature(string port, string baudRate)
 {
     try
     {
         _serialPort = new SerialPort(port);
         _serialPort.BaudRate = Convert.ToInt32(baudRate);
         _serialPort.Parity = Parity.None;
         _serialPort.StopBits = StopBits.One;
         _serialPort.DataBits = 8;
         _serialPort.Handshake = Handshake.None;
         _serialPort.RtsEnable = true;
         _serialPort.ReadTimeout = 1000;
         if (_serialPort.IsOpen)
         {
             _serialPort.Close();
             _serialPort.Open();
         }
         else
         {
             _serialPort.Open();
         }
         Thread.Sleep(1000);
         count = _serialPort.BytesToRead;
         if (count < 1)
         {
             throw new Exception("No Data to Read..."+count);
         }
         else
         {
             while (count > 0)
             {
                 int byteData = _serialPort.ReadByte();
                 data = data + Convert.ToChar(byteData);
                 count--;
             }
         }
         _serialPort.DiscardOutBuffer();
         _serialPort.Close();
         _result = GetXML(data.Trim());
     }
     catch (Exception ex)
     {
         if (_serialPort.IsOpen)
             _serialPort.Close();
         _result = GetExceptionXML(ex.ToString());
     }
     return _result;
 }
开发者ID:stellant,项目名称:LaserpointFinal,代码行数:48,代码来源:Temperature.svc.cs

示例14: OpenPort

 //打开端口
 public bool OpenPort(SerialPort port)
 {
     bool bflag = false;
     try
     {
         port.Open();
         port.DiscardInBuffer();
         port.DiscardOutBuffer();
         bflag = true;
     }
     catch (IOException ex)
     {
         bflag = false;
     }
     return bflag;
 }
开发者ID:UEChip,项目名称:UENSimulation,代码行数:17,代码来源:COMManage.cs

示例15: COMmngr

 public COMmngr()
 {
     //dataReceiveCBs += new DataReceivedCBDeleage(CC2540.DataReceivedCB);
     com = new SerialPort();
     com.BaudRate = 115200;
     com.PortName = Properties.Settings.Default.COMport;
     com.Parity = Parity.None;
     com.Handshake = Handshake.RequestToSend;
     com.StopBits = StopBits.One;
     com.DataBits = 8;
     com.ReadTimeout = 5000;
     com.WriteTimeout = 5000;
     com.DataReceived += new SerialDataReceivedEventHandler(COMDataReceivedCB);
     com.Open();
     com.DiscardInBuffer();
     com.DiscardOutBuffer();
 }
开发者ID:mihazet,项目名称:smartag,代码行数:17,代码来源:COMmngr.cs


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