/// <summary> /// 从串口收到数据 串口事件 /// 程序未完成需要的可自己添加 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void sp_DataReceived(object sender, EventArgs e) { string temp = ""; try { temp = _com.ReadLine(); } catch (Exception ex) { //throw new Exception("sp_DataReceived ReadLine Exception:" + ex.ToString() ); //这个异常暂时不处理,如果Modem不能正常通讯,应在此断开连接重连; ModemStatusMsg = "sp_DataReceived ReadLine Exception:" + ex.ToString(); temp = ""; } if (temp.Length > 8) { if (temp.Substring(0, 6) == "+CMTI:") { newMsgIndexQueue.Enqueue(Convert.ToInt32(temp.Split(',')[1])); //存储新信息序号 OnSmsRecieved(e); //触发事件 } } }
/// <summary> /// 从串口收到数据 串口事件 /// 程序未完成需要的可自己添加 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void sp_DataReceived(object sender, EventArgs e) { string temp = ""; try { temp = _com.ReadLine(); } catch (Exception ex) { //打印日志 string errTxt = string.Format(" sp_DataReceived ReadLine Exception:{0}\r\n{1}\r\n{2}", "暂不处理", ex.Message, ex.StackTrace); LogHelpers.Error(errTxt); //throw new Exception("sp_DataReceived ReadLine Exception:" + ex.ToString() ); //这个异常暂时不处理,如果Modem不能正常通讯,应在此断开连接重连; ModemStatusMsg = "sp_DataReceived ReadLine Exception:" + ex.ToString(); temp = ""; } if (temp.Length > 8) { if (temp.Substring(0, 6) == "+CMTI:") { newMsgIndexQueue.Enqueue(Convert.ToInt32(temp.Split(',')[1])); //存储新信息序号 OnSmsRecieved(e); //触发事件 } } }
/// <summary> /// 从串口收到数据 串口事件 /// 程序未完成需要的可自己添加 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void sp_DataReceived(object sender, EventArgs e) { //Console.WriteLine("!!!!!!!!!!!!!!!!!sp_DataReceived锁死"); //isSendMessageEvent.WaitOne(); string temp = _com.ReadLine(); if (temp.Length > 8) { if (temp.Substring(0, 6) == "+CMTI:") { newMsgIndexQueue.Enqueue(Convert.ToInt32(temp.Split(',')[1])); //存储新信息序号 OnSmsRecieved(e); //触发事件 } } //isSendMessageEvent.Set(); //Console.WriteLine("!!!!!!!!!!!!!!!!!sp_DataReceived释放"); }