串口问题
C#串口通信,当R232的2-3脚没有连接时,发送数时老是卡死。代码如下程序代码:
private void button1_Click(object sender, EventArgs e) { serialPort1.PortName = "COM1"; serialPort1.BaudRate = 9600; serialPort1.Open(); byte[] data = Encoding.Unicode.GetBytes(textBox1.Text); string str = Convert.ToBase64String(data); serialPort1.WriteLine(str); MessageBox.Show("数据发送成功!", "系统提示"); byte[] data = Convert.FromBase64String(serialPort1.ReadLine()); textBox2.Text = Encoding.Unicode.GetString(data); serialPort1.Close(); MessageBox.Show("数据接收成功!", "系统提示"); }请高手帮解决下这类问题