ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

c#-串口通信-进程间-简单实验

2021-02-23 17:00:01  阅读:18  来源: 互联网

标签:bf c# 通信 SerialPort serialPort2 串口 new byte Open


1 概要:串口通信模拟

SerialPort serialPort2 = new SerialPort("COM2");

serialPort2.Open();

serialPort2.Write(textBox2.Text);

 

SerialPort serialPort2 = new SerialPort("COM1");

serialPort2.Open();

byte[] bf = new byte[1000];
            serialPort2.Read(bf, 0, 1000);

2.代码

2.1.发生端

 SerialPort serialPort2 = new SerialPort("COM2");
        public Form1()
        {
            InitializeComponent();
            serialPort2.Open();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            serialPort2.Write(textBox2.Text);
            textBox1.AppendText(textBox2.Text+"\r\n");
        }

2.2 接收端

 

SerialPort serialPort2 = new SerialPort("COM1");
        public Form1()
        {
            InitializeComponent();
            serialPort2.Open();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            byte[] bf = new byte[1000];
            serialPort2.Read(bf, 0, 1000);
            string str2 = Encoding.ASCII.GetString(bf);
            textBox1.AppendText(str2 + "\r\n");
        }

3. 运行结果 

标签:bf,c#,通信,SerialPort,serialPort2,串口,new,byte,Open
来源: https://blog.csdn.net/xie__jin__cheng/article/details/113995638

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有