C#串口通信触发不了DataReceived事件
public void SerialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e) //接收中断{
int receive_length = SerialPort1.BytesToRead;
byte[] receive_data = new byte[receive_length];
//receive_data = Convert.FromBase64String(SerialPort1.ReadLine());
//txt_receive.Text = Encoding.Unicode.GetString(receive_data);
SerialPort1.Read(receive_data, 0, receive_length);
string str = "";
for (int i = 0; i < receive_length; i++)
{
str += receive_data[i].ToString("X2") + " ";
}
this.Invoke(interfaceUpdateHandle, new string[] { str });
}
private void SerierCom_Load(object sender, EventArgs e)
{
//默认串口值
combobox_com.SelectedIndex = 0;
combobox_baudrate.SelectedIndex = 3;
combobox_verify.SelectedIndex = 1;
combobox_databit.SelectedIndex = 0;
combobox_stopbit.SelectedIndex = 0;
SerialPort1.PortName = "COM1";
SerialPort1.BaudRate = 9600;
SerialPort1.Parity =
SerialPort1.Open();
//public event HandleInterfaceUpdateDelegate SerialPort1_DataReceived;
SerialPort1.DataReceived += new SerialDataReceivedEventHandler(SerialPort1_DataReceived);//注册事件
//HandleInterfaceUpdateDelegate interfaceUpdateHandle = new HandleInterfaceUpdateDelegate(UpdateTextBox);
//Control.CheckForIllegalCrossThreadCalls = false;//屏蔽非法跨线程调用将始终引发异常
SerialPort1.ReceivedBytesThreshold = 1;
//thread1 = new Thread(new ThreadStart(UpdateTextBox));
//thread1.Start();
}