为什么我在 UCS2 中只得到数字如何修复命令和 c#? [英] why I get just numbers in UCS2 how can I fixed at commands and c#?
问题描述
我在通过 putty 读取短信时遇到问题,因为我输入了 AT+CMGL="ALL" 但消息(文本)和数字只是数字,我读到我的 gms 调制解调器 nokia s10 使用 UCS2,但是我不知道在这里做什么?我怎样才能阅读我的消息而不是只看到数字?请帮忙
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 s10 uses UCS2, but I dont know what to do here? how can I read my message intead of just seeing numbers?? help please
我也使用 codeproject 中的这段代码,我更改了这一行,但结果与 ucs2 中的腻子只是数字相同
Also I am using this code from codeproject and I changed this line but It is the same result as putty just number in 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;
}
推荐答案
请注意,AT+CSCS
仅影响命令和响应的 string 参数.在AT+CMGL
的情况下,消息的内容不是字符串,而是格式.有关该格式的更多详细信息,请参阅 27.005 规范,它有点复杂(只关注第一个
SMS
部分,忽略第二个CBS
部分)
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).
但它的简短版本是,对于 UCS-2,您将获得十六进制编码的数据(例如,两个字符 '2'
和 'A'
代表一个字节值为 0x2A
(ASCII/UTF-8 字符 '*'
)).因此,您应该将接收到的 4 个和 4 个字节解码为 UCS-2 字符中 16 位的十六进制编码.
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.
因此解码为字节数组,然后转换为字符串,请参阅 Appleman1234 的 answer(他的答案没有解决核心问题,即十六进制解码).
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).
这篇关于为什么我在 UCS2 中只得到数字如何修复命令和 c#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!