tags:

views:

498

answers:

3

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

Try to see if there is a pattern to the messages which are not sent. Because then there might be a problem with the number format or invalid characters in the message.

Also, some notes:

  1. You are not doing any error checking. I would make sure that I got the expected reply after calling each command.

  2. You are using Environment.NewLine to finish each row. I assume that this is a property that changes with the underlying operating system. The AT standard is however very clear on exactly which characters to use for terminating commandlines.

  3. Mobile phones are real bastards. Just because YOU follow the specification or documentation does not mean they do. Assume that each phone model behaves different from all other. See point 1.

kigurai
Thanks for reply, but as I wrote that some sms are going and some showing error in sending. So what should be the reason behind it. Because I am sending a bulk of sms. I am getting reply of each command by this. serialport.ReadExisting();Can you tell me that why some SMS are going and reply 'OK' and some not going and reply 'Error'?
Deepak
Have you checked if the errors are random or if some messages always pass and some always fail?My guess is still malformed message or address, or your phone is not able to handle that many messages.
kigurai
Hi, Yes, you are right. I am getting problem randomly to sent sms. Many times sms is being sent to some members and next time they will not be sent to those members. Could you please let me know that what problem can be in my code. Thanks for reply
Deepak
A: 

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 Aborting commands

...

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

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

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.

hlovdal
A: 

Is it possible to send AT Command to O2 mobile? Does it supports Serial Port communication? I tried to connect O2 with my PC using BlueTooth but it does not allocate serial port. DoYouKnow

DoYouKnow.IN