0

when i am sending sms first time it send successfully but when i press button second time it does not send message i confuse where serial port open or close or where AT Commands work properly

sorry for bad english

here is my full code

 SerialPort serialPort = new SerialPort();  
    private void Form1_Load(object sender, EventArgs e)
        {
            this.serialPort = new SerialPort();
            this.serialPort.PortName = "COM6";
            this.serialPort.BaudRate = 921600;
            this.serialPort.Parity = Parity.None;
            this.serialPort.DataBits = 8;
            this.serialPort.StopBits = StopBits.One;
            serialPort.WriteBufferSize = 300;
            this.serialPort.Handshake = Handshake.RequestToSend;
            this.serialPort.DtrEnable = true;
            this.serialPort.RtsEnable = true;
            serialPort.Open();

        }
         public bool send_sms()
         {
             String SMSMessage = txtmsg.Text;
             String CellNumber = cellNum.Text;
             String messageToSend = null;
             if (SMSMessage.Length <= 160)
             {
                 messageToSend = SMSMessage;
             }
             else
             {
                 messageToSend = SMSMessage.Substring(0, 160);
             }
             if (serialPort.IsOpen)
             {
                 this.serialPort.Write("AT\r");
                 Thread.Sleep(1000);
                 this.serialPort.Write("AT+CMGF=1\r");
                 Thread.Sleep(1000);
                 this.serialPort.Write("AT+CMGS=\"" + CellNumber + "\"\r\n");
                 Thread.Sleep(1000);
                 this.serialPort.Write(SMSMessage + "\x1A");
                 return true;
             }
             return false;
         }

        private void sendbtn_Click(object sender, EventArgs e)
        {
            send_sms();
        }
  • Instead of "\x1A" try using (char)26 : https://social.msdn.microsoft.com/Forums/vstudio/en-US/2c3947e6-cc03-4822-a70e-3cba86747ced/how-to-send-ctrlz-through-serial-in-c-?forum=csharpgeneral & https://stackoverflow.com/questions/7188566/sending-ctrlz-to-a-serial-port – PaulF Jun 23 '17 at 08:12
  • It may be worth checking the responses from the modem & also check if the RTS line is set (possibly an LED on the modem). – PaulF Jun 23 '17 at 08:21

1 Answers1

0

After sending the message, put a delay of 3 secs before the next message sending.

this.serialPort.Write("AT+CMGS=\"" + CellNumber + "\"\r\n");
this.serialPort.Write(SMSMessage + "\x1A");
Thread.Sleep(3000);

and keep the message length < 150 characters