为什么我只能在UCS2中得到数字,如何固定在命令和C#上? [英] why I get just numbers in UCS2 how can I fixed at commands and c#?

查看:104
本文介绍了为什么我只能在UCS2中得到数字,如何固定在命令和C#上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通过腻子读取短信时遇到问题,因为我键入AT + CMGL ="ALL",但消息(文本)和数字只是数字,我读到我的gms调制解调器诺基亚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中的putty just number是相同的结果

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,消息的内容不是字符串,而是<data>格式.有关该格式的更多详细信息,请参见 27.005 规范,有点复杂(只注意第一个In the case of SMS部分,忽略第二个In the case of 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的答案(他的答案未解决核心问题,即十六进制解码).

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆