790
社区成员
发帖
与我相关
我的任务
分享
public string SendAT(string ATCom)
{
string str = string.Empty;
//忽略接收缓冲区内容,准备发送
this.sp.DiscardInBuffer();
//注销事件关联,为发送做准备
this.sp.DataReceived -= this.sp_DataReceived;
try
{
this.sp.Write(ATCom + "\r");
}
catch (Exception ex)
{
this.sp.DataReceived += this.sp_DataReceived;
throw ex;
}
try
{
string temp = string.Empty;
while ((temp.Trim() != "OK") && (temp.Trim() != "ERROR"))
{
temp = this.sp.ReadLine();
str += temp;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
this.sp.DataReceived += this.sp_DataReceived;
}
return str;
}