我正在用GSM手机发送AT命令的短信。我想发送成百上千条消息。我读到,通过GSM移动,我们可以发送6-8短信每分钟。但当我发送消息时,就会有人去,有人不去。我正在从excel文件中获取信息,这意味着目的地号码和消息文本。你能告诉我为什么有些短信要发,有些不要。我的代码是
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);
}发布于 2009-09-07 11:56:49
我认为你的问题在于,在发送下一个命令之前,你没有等待最终的结果代码(即OK、ERROR和其他一些代码)。这样做的问题是,如果新命令没有完成,它将触发正在进行的命令的中止。引用V.250
5.6.1中止命令
..。
命令的中止是通过从DTE向DCE传输任意字符来完成的。
所以在发送AT命令时,你必须等待最后的结果代码,然后才能发送下一条命令,所以。
我可以建议将serialport.WriteLine("ATxxx" + Environment.NewLine)重构为sendCommand(serialport, "ATxxx")函数吗?然后,您可以在该函数的末尾添加等待最终结果代码。
发布于 2009-07-31 06:35:30
尝试查看未发送的消息是否有模式。因为这样可能会出现数字格式的问题或消息中的无效字符。
另外,还有一些注意事项:
https://stackoverflow.com/questions/1210934
复制相似问题