我想注册事件,以便在有电话的时候随时调用它如何实现
private void SpecialCallerID()
{
serialPort = new SerialPort(ComPort);
serialPort.BaudRate = 9600;
serialPort.Parity = Parity.None;
serialPort.StopBits = StopBits.One;
serialPort.DataBits = 8;
serialPort.Handshake = Handshake.None;
serialPort.ReadTimeout = 100;
serialPort.DtrEnable = true; // Data-terminal-ready
serialPort.Open();
//serialPort.RtsEnable = true; // Request-to-send
serialPort.DataReceived += new SerialDataReceivedEventHandler(this.serialPortNEW_DataReceived);
// mySerialPort.Close();
}
private void serialPortNEW_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) {
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
string[] strFirstStep = Regex.Split(indata, "\r\nNMBR =");
string[] strLastStep = Regex.Split(strFirstStep[1], "\r\n");
string FinalValue = strLastStep[0];
custNUmber = int.Parse(FinalValue);
}