做的一个C#串口发送和接收的小软件

把串口的2、3短接
 
 把串口的2、3短接
 
 

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                serialPort1.PortName = comboBox1.Text.ToString();
                serialPort1.Open();
            }
            catch
            {
                return;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string s=textBox2.Text.ToString();
            try
            {
                this.serialPort1.Write(s);
            }
            catch
            {
                return;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                //int ss = this.serialPort1.BytesToRead;
                serialPort1.Dispose();
                this.serialPort1.Close();
            }
            catch
            {
               
                return;
            }
        }

        private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            int i = 0;
            i = this.serialPort1.BytesToRead;
            CheckForIllegalCrossThreadCalls = false;
            this.textBox1.Text += this.serialPort1.ReadExisting();
        }
    }




原程序https://files.cnblogs.com/slcfhr/chuankou.rar
把2、3针短接
posted @ 2008-05-21 23:25  邵利超  阅读(4930)  评论(2编辑  收藏  举报