2012-03-06 3 views
1

퍼티를 통해 내 SMS를 읽는 데 문제가 있습니다. 그 beacuse에 AT + CMGL = "ALL"을 입력했지만 메시지 (텍스트)와 숫자는 숫자 일뿐입니다. gms 모뎀은 노키아 s10에서 UCS2를 사용합니다. 여기서 무엇을 해야할지 몰라? 어떻게 내 숫자를보고 그냥 내 메시지를 읽을 수 있습니까 ?? (내가 CodeProject의에서이 코드를 사용하고 내가이 줄을 변경내가 UCS2에서 숫자를 얻는 이유는 무엇입니까? 어떻게 명령과 C#에서 해결할 수 있습니까?

또한

하시기 바랍니다 도움이되지만 UCS-2 인코딩 저장소에서 결과를 변환하려면 UCS2

public ShortMessageCollection ReadSMS(SerialPort port, string p_strCommand) 
    { 

     // Set up the phone and read the messages 
     ShortMessageCollection messages = null; 
     try 
     { 

      #region Execute Command 
      // Check connection 
      ExecCommand(port,"AT", 300, "No phone connected"); 
      // Use message format "Text mode" 
      ExecCommand(port,"AT+CMGF=1", 300, "Failed to set message format."); 
      // Use character set "PCCP437" 
      **ExecCommand(port, "AT+CSCS=\"UCS2\"", 300, "Failed to set character set.")**; 
      // Select SIM storage 
      ExecCommand(port,"AT+CPMS=\"SM\"", 300, "Failed to select message storage."); 
      // Read the messages 
      string input = ExecCommand(port, p_strCommand, 5000, "Failed to read the messages."); 
      #endregion 

      #region Parse messages 
      messages = ParseMessages(input); 
      #endregion 

     } 
     catch (Exception ex) 
     { 
      throw ex; 
     } 

     if (messages != null) 
      return messages; 
     else 
      return null;  

    } 

답변

0

에서 퍼티 단지 수와 같은 결과입니다 UCS-2 인코딩 빅 엔디안 다음 System.Text.Encoding enc = Encoding.BigEndianUnicode;System.Text.Encoding enc = Encoding.Unicode; 변경이면 바이트 배열 대신 문자열에서 입력)

System.Text.Encoding enc = Encoding.Unicode; 
string myString = enc.GetString(myByteArray); 

전화.

관련 리소스는 다음과 같습니다 AT+CSCS문자열을 명령 및 응답에 매개 변수에 영향을 미친다

2

알 수 있습니다. AT+CMGL의 경우 메시지의 내용은 문자열이 아니지만 <data> 형식입니다. 해당 형식에 대한 자세한 내용은 27.005 사양을 참조하십시오. 조금 복잡합니다 (첫 번째 In the case of SMS 부분에만주의하고 두 번째 부분은 무시하십시오). In the case of CBS 부분.

는 그러나 그것의 짧은 버전은 UCS-2는 데이터 진수를 인코딩 (예를 들어, 두 개의 문자 '2''A'0x2A (ASCII/UTF-8 문자 '*') 한 바이트를 나타낸다) 얻을 것입니다. 따라서 4 바이트와 4 바이트를 UCS-2 문자의 16 비트 16 진수 인코딩으로 디코딩해야합니다.

바이트 배열로 디코딩 한 다음 문자열로 변환하려면 Appleman1234의 answer을 참조하십시오 (그의 대답은 핵심 문제, 즉 16 진수 디코딩을 다루지 않습니다).