使用GSM移动的AT命令发送短信给出了错误

我用GSM手机通过AT命令发送短信。 我想发送成千上万的消息。 我读过GSM手机,我们每分钟可以发送6-8个短信。 但是当我发送消息时,有人会去而有人不会。 我从excel文件获取信息意味着目的地号码和消息文本。 你能告诉我为什么有些短信正在进行而有些则没有。 我的代码是

SmsFields smsObj = null; List 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); } 

我认为你的问题是你在发送下一个命令之前没有等待最终结果代码(即OK,ERROR和其他一些代码)。 问题在于,如果未完成,新命令将触发正在进行的命令的中止。 引用V.250 :

5.6.1中止命令

通过从DTE到任何角色的DCE的传输来完成命令的中止。

所以总是在发送AT命令时,你必须在发送下一个命令之前等待最终的结果代码。

我建议将serialport.WriteLine("ATxxx" + Environment.NewLine)重构为sendCommand(serialport, "ATxxx")函数吗? 然后,您可以在该函数结束时添加等待最终结果代码。

尝试查看是否存在未发送的消息模式。 因为这样可能会出现数字格式或消息中无效字符的问题。

还有一些说明:

  1. 您没有进行任何错误检查。 我会确保在调用每个命令后得到了预期的回复。

  2. 您正在使用Environment.NewLine完成每一行。 我假设这是一个随底层操作系统而变化的属性。 然而,AT标准非常清楚用于终止命令行的确切字符。

  3. 手机是真正的混蛋。 仅仅因为你遵循规范或文档并不意味着他们这样做。 假设每个手机型号的行为与其他手机型号不同。 见第1点。