在VB中要想清空接收缓冲区使用InBufferCount=0即可,在C#2005里面应该怎么做呢?
还有我如何设置去接收文本或二进制。谁有好的接收代码或资料可以参考的吗?

解决方案 »

  1.   

    VS2005中C#对串口的操作(非常简单的一个小例子)
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.IO.Ports;namespace chuankou
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                //SerialPort sp = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                SerialPort sp = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
                sp.Open();
                if (textBox1.Text == "")
                {
                    MessageBox.Show("请检查输入!");
                }
                else
                {
                    sp.WriteLine(textBox1.Text);
                    textBox2.Text = sp.ReadLine();
                    sp.Close();
                }
            }        private void button2_Click(object sender, EventArgs e)
            {
                this.Close();
            }
        }
    }
      

  2.   

    Serialport.DiscardInBuffer();
    Serialport.DiscardOutBuffer();
    可以清空的。