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