how to reading Unicode Messages (such as in Persian and Arabic) in C# using AT Commands through GSM Modem?

StackOverflow https://stackoverflow.com/questions/18480643

Question

i read this post to send Unicode sms message but i want to know how to read utf8 messages?

Sending Unicode Messages (such as in Persian and Arabic) in C# using AT Commands through GSM Modem

i send this command but recieved message text is something like:

 AT+CMGL="ALL"

  +CMGL: 1,"REC READ","97563937625","","2013/08/28 00:53:30+18"
     0041006A006D0064006A00740020

my commands to read sms:

          ExecCommand(port,"AT", 300, "No phone connected");

            ExecCommand(port,"AT+CSCS=\"UCS2\"\n", 300, "No phone connected");

            ExecCommand(port,"AT+CMGF=1", 300, "Failed to set message format.");

            ExecCommand(port,"AT+CPMS=\"MT\"", 300, "Failed to select message storage.");          

            string input = ExecCommand(port, "AT+CMGL=\"ALL\"", 5000, "Failed to read the messages.");
Était-ce utile?

La solution

I don't think UTF8 is supported by GSM. From http://en.wikipedia.org/wiki/Short_Message_Service

Short messages can be encoded using a variety of alphabets: the default GSM 7-bit alphabet, the 8-bit data alphabet, and the 16-bit UCS-2 alphabet

and from http://en.wikipedia.org/wiki/GSM_03.40

The messages in Chinese, Korean or Japanese languages must be encoded using the UTF-16 character encoding

The Data Coding Scheme (TP-DCS) field contains primarily information about message encoding. GSM recognizes only 2 encodings for text messages and 1 encoding for binary messages:

GSM 7 bit default alphabet (which includes using of National language shift tables as well)

UCS-2

8 bit data

In the same paragraph they tell that there is a new national-based encoding (the National language shift table) that was introduced in 2012. Still this isn't UTF-8.

Autres conseils

    private string decoder(string value)
    {
        Regex lettersOnly = new Regex("^[0-9]|[A-Z]$");
        if ((value.Length % 4 == 0) && lettersOnly.Match(value).Success)
        {
            string data = FromHex(value);

            return data;
        }
        else
            return value;
    }      

    public static string FromHex(string hex)
    {
        short[] raw = new short[hex.Length / 4];
        for (int i = 0; i < raw.Length; i++)
        {
            raw[i] = Convert.ToInt16(hex.Substring(i * 4, 4), 16);
        }
        string s = "";
        //wtf encoding utf32 ride ahmagh kos sher pas mide
        foreach (var item in raw)
        {
            s += char.ConvertFromUtf32(item).ToString();
        }
        return s;
    }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top