1 概要:串口通信模拟SerialPort serialPort2 = new SerialPort(COM2);serialPort2.Open();serialPort2.Write(textBox2.Text); SerialPort serialPort2 = new SerialPort(COM1);serialPort2.Open();byte[...
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. 运行结果
沃梦达教程
本文标题为:c#-串口通信-进程间-简单实验
猜你喜欢
- c#使用linq把多列的List转化为只有指定列的List 2023-02-03
- C#实现在窗体上的统计图效果 2023-05-17
- C# CultureInfo类案例详解 2023-04-28
- c# – 对Sql Server中的索引感到困惑 2023-11-12
- 对int array进行排序的实例讲解 2022-11-28
- C#实现飞行棋优化版 2023-04-15
- WPF实现在控件上显示Loading等待动画的方法详解 2023-07-18
- C# wpf使用ffmpeg命令行实现录屏的示例代码 2023-06-27
- C#中DataGridView导出Excel的两种方法 2023-03-29
- C#实现GridView导出Excel实例代码 2022-11-06