GSM mobile通过AT命令发送SMS报错 [英] SMS by AT commands with GSM mobile is giving error

查看:141
本文介绍了GSM mobile通过AT命令发送SMS报错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am sending SMS by AT commands with GSM mobile phone. I wanna send bulk of message like thousands. I read that by GSM mobile we can send 6-8 sms per minute. But when I send messages then someone are going and someone not. I am getting information from excel file means destination number and message text. Can you tell me why some sms are going and some not. My code is

        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);
   }

推荐答案

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

I think your problem is that you are not waiting for the final result code (i.e. OK, ERROR and a few others) before sending the next command. The problem with that is that the new command will trigger an abort of the ongoing command if it is not finished. To quote V.250:

5.6.1中止命令

5.6.1 Aborting commands

...

正在中止 命令是由 从DTE到DCE的传输 任何字符.

Aborting of commands is accomplished by the transmission from the DTE to the DCE of any character.

总是发送AT命令时,您必须等待最终结果代码,然后发送下一条命令.

So ALWAYS when sending AT commands, you MUST wait for the final result code before sending the next command.

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

Might I suggest refactoring serialport.WriteLine("ATxxx" + Environment.NewLine) into a sendCommand(serialport, "ATxxx") function? And then you can add waiting for the final result code at the end of that function.

这篇关于GSM mobile通过AT命令发送SMS报错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆