public partial class Form1 : Form
{
SerialPort serialport1 = new SerialPort();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
serialport1.PortName = "COM5";
serialport1.BaudRate = 9600;
serialport1.Open();
byte[] data = Encoding.Unicode.GetBytes(textBox1.Text);
string str = Convert.ToBase64String(data);
serialport1.WriteLine(str);
MessageBox.Show("数据发送成功!", "系统提示");
}
private void button2_Click(object sender, EventArgs e)
{
byte[] data = Convert.FromBase64String(serialport1.ReadLine());
textBox2.Text = Encoding.Unicode.GetString(data);
serialport1.Close();
MessageBox.Show("数据接收成功!", "系统提示");
}
为什么button1发送之后,点击button2没有接受到数据,程序直接就死那了,,求解~
慕沐林林
萧十郎
慕森卡
撒科打诨
汪汪一只猫
狐的传说
GCT1015
宝慕林4294392