why I get just numbers in UCS2 how can I fixed at commands and c#?

前端 未结 2 1620
独厮守ぢ
独厮守ぢ 2021-01-16 06:12

I am having a problem with reading my sms through putty, Its beacuse I type AT+CMGL=\"ALL\" but the message(text) and number are just numbers, I read that my gms modem nokia

相关标签:
2条回答
  • 2021-01-16 06:42

    Notice that AT+CSCS only affects string parameters to commands and responses. In the case of AT+CMGL the content of the message is not a string, but a <data> format. See the 27.005 specification for more details on that format, it is a bit complicated (only pay attention to the first In the case of SMS part, ignore the second In the case of CBS part).

    But the short version of it is that for UCS-2 you will get the data hex encoded (e.g. two characters '2' and 'A' represents one byte with value 0x2A (ASCII/UTF-8 character '*')). So you should decode 4 and 4 received bytes as the hex encoding of the 16 bits in a UCS-2 character.

    So decode into a byte array and then convert to string, see Appleman1234's answer for that (his answer does not address the core issue, namely the hex decoding).

    0 讨论(0)
  • 2021-01-16 06:52

    To convert from the UCS-2 encoding store the result (input) in a byte array instead of a string and then call

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

    If the UCS-2 encoding is Big Endian then change System.Text.Encoding enc = Encoding.Unicode; to System.Text.Encoding enc = Encoding.BigEndianUnicode;.

    Related resources include:

    • Unicode and .NET
    • C# big-endian UCS-2
    0 讨论(0)
提交回复
热议问题