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

冷暖自知 提交于 2019-12-01 12:53:27
hlovdal

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).

Appleman1234

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:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!