高手来看一下,代码问题
为什么下面的代码,一步一步运行发短信不会有问题
但全部一起运行就会出错
public string SendMessage(string centerNumber,string number,string message)
{
string str;
string temp;
PDUdecoding pdu = new PDUdecoding();
//短信中心号编码
string s = pdu.smsDecodedCenterNumber(centerNumber);
//接受手机号编码
string s1 = pdu.smsDecodedNumber(number);
//整个短信编码
string s2 = pdu.smsDecodedsms(centerNumber, number,message);
int leng = (s2.Length - s.Length)/2;
str = "AT+CMGF=0 " + '\r ';
comm.Output = str;
System.Threading.Thread.Sleep(1000);
temp = string.Format( "AT+CMGS={0} ",leng);
str = temp + '\r ';
comm.Output = str;
System.Threading.Thread.Sleep(1000);
str = s2+ '\u001a ';
comm.Output = str;
System.Threading.Thread.Sleep(1000);
return " ";
}
//打开串口
在 InitComPort();