日期:2014-05-17 浏览次数:20897 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace 串口收发
{
public partial class Form1 : Form
{
public string receiveing = string.Empty;
public string transmission = string.Empty;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
transmission = txtTransmission.Text;
serialPort1.WriteLine(transmission);
MessageBox.Show("数据发送成功!", "系统提示");
}
private void serialPort2_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
receiveing = serialPort2.ReadLine();
}
private void button2_Click(object sender, EventArgs e)
{
txtReceive.Text = receiveing;
MessageBox.Show("数据接收成功!", "系统提示");
}
private void Form1_Load(object sender, EventArgs e)
{
serialPort1.Open();
serialPort2.Open();
}
}
}