AT commands Send/receive SMS

前端 未结 3 1357

I am new to AT commands. I am using Nokia E71 to send and receive SMS. I am designing an application for sending SMS, but my code is not working.

using Syste         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 00:44

    Try it this way.. You are not opening the connection to the serial port. I have tried it and it is working fine for me.

     private void button1_Click(object sender, EventArgs e)
     {
         this.serialPort = new SerialPort();
         this.serialPort.PortName = "COM5";
         this.serialPort.BaudRate = 9600;
         this.serialPort.Parity = Parity.None;
         this.serialPort.DataBits = 8;
         this.serialPort.StopBits = StopBits.One;
         this.serialPort.Handshake = Handshake.RequestToSend;
         this.serialPort.DtrEnable = true;
         this.serialPort.RtsEnable = true;
         this.serialPort.NewLine = System.Environment.NewLine;
         serialPort.Open();
         send_sms();
     }
     public bool send_sms()
     {
         String SMSMessage = "gsm MESSAGE FROM .NET C#";
         String CellNumber = "+9233333333333";
         String messageToSend = null;
         if (SMSMessage.Length <= 160)
         {
             messageToSend = SMSMessage;
         }
         else
         {
             messageToSend = SMSMessage.Substring(0, 160);
         }
         if (serialPort.IsOpen)
         {
             this.serialPort.WriteLine(@"AT" + (char)(13));
             Thread.Sleep(200);
             this.serialPort.WriteLine("AT+CMGF=1" + (char)(13));
             Thread.Sleep(200);
             this.serialPort.WriteLine(@"AT+CMGS=""" + CellNumber + @"""" + (char)(13));
             Thread.Sleep(200);
             this.serialPort.WriteLine(SMSMessage + (char)(26));
             return true;
             }
         return false;
     }
    

提交回复
热议问题