gpt4 book ai didi

c# - 如何通过 GSM 调制解调器使用 AT 命令在 C# 中读取 Unicode 消息(例如波斯语和阿拉伯语)?

转载 作者:行者123 更新时间:2023-11-30 20:55:08 24 4
gpt4 key购买 nike

我阅读这篇文章是为了发送 Unicode 短信,但我想知道如何读取 utf8 短信?

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

我发送了这个命令,但收到的消息文本是这样的:

 AT+CMGL="ALL"

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

我读取短信的命令:

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

最佳答案

    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;
}

关于c# - 如何通过 GSM 调制解调器使用 AT 命令在 C# 中读取 Unicode 消息(例如波斯语和阿拉伯语)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18480643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com