2015-10-19 213 views
0

嘿傢伙我試圖從窗口窗體使用AT命令發送短信。但是陷入這個功能。它說:「Failed to set message format.C#短信發送錯誤(AT命令)

recievedData = ExecCommand(port,"AT+CMGF=1", 1000, "Failed to set message format."); // Error in this line => Failed to set message format 

String command = "AT+CMGS=\"" + PhoneNo + "\""; 
       recievedData = ExecCommand(port,command, 300, "Failed to accept phoneNo");   
       command = Message + char.ConvertFromUtf32(26) + "\r"; 
       recievedData = ExecCommand(port,command, 3000, "Failed to send message"); //3 seconds 
       if (recievedData.EndsWith("\r\nOK\r\n")) 
       { 
        isSend = true; 
       } 
       else if (recievedData.Contains("ERROR")) 
       { 
        isSend = false; 
       } 
       return isSend; 
      } 
      catch (Exception ex) 
      { 
       throw ex; 
      } 

     }  
+0

http://www.codeproject.com/Articles/38705/發送和閱讀短信通過GSM調制解調器使用AT-Com閱讀此頁可能對您有所幫助... –

+0

@AnantDabhi感謝您考慮我的帖子..但事實上,已從您提到的網站獲取此代碼,並且錯誤來自相同的代碼。 我的手機連接到正確的端口,但無法獲得通過該錯誤 –

回答

0

首先嚐試使用超級終端發送的短信.. 那麼這是我的代碼有

_serialPort.Open(); 
_serialPort.Write("AT+CMGF=1\r"); 
_serialPort.Write("AT+CMGS=\"" + mobilenumber + "\"\r\n"); 
_serialPort.Write("My Mesage" + "\x1A"); 
_serialPort.Close(); 
+0

謝謝拉希德...我會檢查出來,但將該代碼發送短信到我的手機號碼? –

+0

是的,你可以通過這個代碼發送短信任何人..當你正確配置你的端口 –

+0

謝謝拉希德...我會檢查你讓你知道。 :) –