我正在通過AT命令與GSM手機發送短信。我想發送數千條消息。我通過GSM移動閱讀我們可以每分鐘發送6-8個短信。但是當我發送消息時,有人會去,而不是有人。我從excel文件獲取信息意味着目標號碼和消息文本。你能告訴我爲什麼有些短信正在進行,有些則沒有。我的代碼是短信通過AT命令與GSM手機給出錯誤
SmsFields smsObj = null;
List<SmsFields> smsColl = null;
SerialPort serialport = null;
StringBuilder strbuild = new StringBuilder();
try
{
//Validate the form
if (!Validation()) return;
serialport = new SerialPort();
////Sets the properties of serial port object
serialport.PortName = cboPort.SelectedItem.ToString();
serialport.BaudRate = 9600;
serialport.Parity = Parity.None;
serialport.DataBits = 8;
serialport.StopBits = StopBits.One;
serialport.Handshake = Handshake.RequestToSend;
serialport.DtrEnable = true;
serialport.RtsEnable = true;
//Open the port to send sms
serialport.Open();
//Check if port is opened or not
if (!serialport.IsOpen)
{
MessageBox.Show("Serial port is not opened. Please try with other port");
return;
}
//Create smsFields class's object and fill the data in the generic collection
smsObj = SmsFields.Instance;
smsColl = smsObj.FillData(txtFilePath.Text);
if (smsColl == null)
{
MessageBox.Show("No data found in the excel table");
return;
}
//Gets the single record from SmsFields class and sends the message
foreach (SmsFields sms in smsColl)
{
//checks phone status
serialport.WriteLine("AT" + Environment.NewLine);
//Configures message as SMS (0 for PDU format) and (1 for text format)
serialport.WriteLine("AT+CMGF=1" + Environment.NewLine);
//Sets message center number
serialport.WriteLine("AT+CSCA=\"" + txtServiceNo.Text + "\"" + Environment.NewLine);
//Sets destination number
serialport.WriteLine("AT+CMGS=\"" + sms.DestinationNo + "\"" + Environment.NewLine);
//Specifies message and sends Ctrl+z
serialport.WriteLine(sms.Message + (char)26);
//Displays buffer containing output messages
System.Threading.Thread.Sleep(4000);
}
感謝您的回覆,但正如我寫的那樣,有些短信正在發送,有些顯示發送錯誤。那麼背後的原因是什麼?因爲我發送了大量的短信。我收到了每個命令的回覆。 serialport.ReadExisting(); 你能告訴我,爲什麼有些短信會回覆'OK',有些不會回覆'錯誤'? – Deepak 2009-07-31 06:45:28