关于SerialPort串口编程的问题
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
namespace online
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//向COM2接收数据
private void btnStart_Click(object sender, EventArgs e)
{
try
{
SerialPort spIncept = new SerialPort("COM2");
spIncept.Open();
string message = spIncept.ReadLine();
spIncept.Close();
MessageBox.Show(message);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
private void btnSend_Click(object sender, EventArgs e)
{
try
{
SerialPort spSend = new SerialPort("COM1");
spSend.Open();
spSend.Write("Fuck You!");
spSend.Close();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}
我用的是C# Winform程序写的,上面这段代码运行到//向COM2接收数据时候就会假死哪个大哥帮我看看啊,如果还有其他的错误请帮我指明一下,谢谢各位大大了!!!