如何在 C# 中使用 at-command 发送阿拉伯短信

发布于 2024-10-04 04:11:09 字数 754 浏览 0 评论 0原文

如何使用 C# 中的 at 命令发送阿拉伯短信?当我发送阿拉伯语消息时,它显示不正确的字符。

我尝试使用此代码:

serialPort1.BaseStream.Flush();

            string cb = char.ConvertFromUtf32(26);

            System.Threading.Thread.Sleep(2000);

            this.serialPort1.Write("AT+CMGF=1\r");
            this.serialPort1.Write("AT+CSCA=servicecenter\r\n");//Ufone Service Center

            this.serialPort1.Write("AT+CSCS=\"" + "HEX" + "\"\r\n");
            this.serialPort1.Write("AT+CSMP=\"" + 1 + "," + 167 + "," + 0 + ","  +8+ "\"\r\n");
            this.serialPort1.Write("AT+CMGS=\"" + textBox1.Text + "\"\r\n");// message sending
            this.serialPort1.Write(textBox2.Text + cb);//message text

并在文本框中写入 06450631062D06280627 。

How can I send Arabic SMS with the at command in C#? When I send Arabic messages it shows incorrect characters.

I tried using this code:

serialPort1.BaseStream.Flush();

            string cb = char.ConvertFromUtf32(26);

            System.Threading.Thread.Sleep(2000);

            this.serialPort1.Write("AT+CMGF=1\r");
            this.serialPort1.Write("AT+CSCA=servicecenter\r\n");//Ufone Service Center

            this.serialPort1.Write("AT+CSCS=\"" + "HEX" + "\"\r\n");
            this.serialPort1.Write("AT+CSMP=\"" + 1 + "," + 167 + "," + 0 + ","  +8+ "\"\r\n");
            this.serialPort1.Write("AT+CMGS=\"" + textBox1.Text + "\"\r\n");// message sending
            this.serialPort1.Write(textBox2.Text + cb);//message text

and I wrote 06450631062D06280627 in the text box.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

就是爱搞怪 2024-10-11 04:11:10

看起来您必须先将 unicode 字符串转换为十六进制。

来自 http://www.smssolutions.net/tutorials/gsm/sendsmsat/

发送 Unicode SMS 消息

某些调制解调器还能够发送 Unicode 或 UCS2 消息,而无需对 PDU 进行编码。您只需将 Unicode 数据转换为十六进制字符串并将该字符串发送到调制解调器即可发送 Unicode 消息。

要检查您的调制解调器是否支持此模式,只需键入以下命令:
AT+CSCS=?

此命令显示调制解调器支持的代码页。调制解调器将如下响应:
+CSCS: ("GSM","PCCP437","CUSTOM","HEX")

如果此字符串包含“HEX”或“UCS2”,则似乎支持 Unicode。要指定使用十六进制字符串发送消息,请根据调制解调器响应将代码页设置为“HEX”或“UCS2”。在我们的示例中,我们将调制解调器设置为“HEX”:
AT+CSCS="HEX"

接下来,我们必须为 Unicode 消息指定正确的 DCS(数据编码方案),即 0x08。我们可以通过将 AT+CSMP 命令的第四个参数更改为“8”来设置该值:
AT+CSMP=1,167,0,8

调制解调器现在已准备好以 Unicode 形式发送消息。现在是发送实际消息的时候了:
AT+CMGS="+31638740161"

将上面的电话号码替换为您自己的手机号码。调制解调器将响应:
>

您唯一需要自己编程的就是一个简单的例程,它将 Unicode 字符串转换为十六进制字符串,如下所示:

阿拉伯语中的“Hello”将被转换如下
"06450631062D06280627"

您可以将此十六进制字符串发送到调制解调器:
06450631062D06280627

几秒钟后,调制解调器将响应消息的消息 ID,表明消息已正确发送:
+CMGS: 63

消息很快就会到达手机上。

Looks like you have to convert your unicode strings to hexadecimal first.

From http://www.smssolutions.net/tutorials/gsm/sendsmsat/ :

Sending an Unicode SMS message

Some modems also have the capability to send Unicode or UCS2 messages without encoding a PDU. You can send Unicode messages by only converting the Unicode data to a HEX string and send this string to the modem.

To check whether your modem supports this mode, just type the following command:
AT+CSCS=?

This commands displays the codepages supported by the modem. The modem will respond like this:
+CSCS: ("GSM","PCCP437","CUSTOM","HEX")

If this string contains "HEX" or "UCS2", Unicode seems to be supported. To specify that you will use an HEX string to send the message, set the codepage to "HEX" or "UCS2" depending on the modem response. In our example we will set the modem to "HEX" :
AT+CSCS="HEX"

Next, we have to specify the correct DCS (Data Coding Scheme) for Unicode messages, which is 0x08. We can set this value by changing the fourth parameter of the AT+CSMP command to '8':
AT+CSMP=1,167,0,8

The modem is now ready to send messages as Unicode. Now is the time to send the actual message:
AT+CMGS="+31638740161"

Replace the above phone number with your own cell phone number. The modem will respond with:
>

The only thing you have to program by yourself, is a simple routine which converts the Unicode string to an hexidecimal string like this:
مرحبا

Which is 'Hello' in arabic will be converted like this:
"06450631062D06280627"

You can send this hexidecimal string to the modem:
06450631062D06280627

After some seconds the modem will respond with the message ID of the message, indicating that the message was sent correctly:
+CMGS: 63

The message will arrive on the mobile phone shortly.

白龙吟 2024-10-11 04:11:10

我对 Unicode(波斯语或阿拉伯语消息)也有类似的问题。请检查我的问题和答案 此帖子。在此线程中,您可以了解如何正确发送 Unicode 消息,并且您的问题将得到解决。

首先请阅读本文,然后将您的 Unicode 消息转换为十六进制格式并设置 AT+CSCS="UCS2"。你的代码的核心应该是这样的:

GSMPort.Write("AT\n");
Thread.Sleep(1000);
GSMPort.Write("AT+CSCS=\"UCS2\"\n");
Thread.Sleep(1000);
GSMPort.Write("AT+CMGF=1\n");
Thread.Sleep(1000);
GSMPort.Write("AT+CMGS=\"" + destinationNumber + "\"\n");
Thread.Sleep(1000);
GSMPort.Write("06450631062D0628062706450631062D0628062706450631062D06280627" + "\x1A");

“06450631062D06280627”是“Миба”的十六进制格式!

I had similar problem with Unicodes (Persian or Arabic messages). Please check my question and answer in this thread. In this thread you can find out how to send Unicode messages correctly and your problem will be resolved.

First please read this article then convert your Unicode message to Hex format and set AT+CSCS="UCS2". The core of your code should look like this:

GSMPort.Write("AT\n");
Thread.Sleep(1000);
GSMPort.Write("AT+CSCS=\"UCS2\"\n");
Thread.Sleep(1000);
GSMPort.Write("AT+CMGF=1\n");
Thread.Sleep(1000);
GSMPort.Write("AT+CMGS=\"" + destinationNumber + "\"\n");
Thread.Sleep(1000);
GSMPort.Write("06450631062D0628062706450631062D0628062706450631062D06280627" + "\x1A");

"06450631062D06280627" is the Hex format of "مرحبا"!

转瞬即逝 2024-10-11 04:11:10

我尝试根据这篇文章用波斯语发送短信:
http://www.smssolutions.net/tutorials/gsm/sendsmsat/
这太容易了。
这是我在 c# 中的代码:

string recievedData = ExecCommand(port, "AT+CSCS=\"HEX\"", 300, "Failed to set message encoding.");
            recievedData = ExecCommand(port, "AT+CSMP=1,167,0,8", 300, "Failed to set message format.");
            //recievedData = ExecCommand(port, "AT+CMGF=1", 300, "Failed to set message format.");

            String command = "AT+CMGS=\"" + Str2Hex(PhoneNo) + "\"";
            recievedData = ExecCommand(port, command, 300, "Failed to accept phoneNo");

            command = Str2Hex(Message) + char.ConvertFromUtf32(26) + "\r";

            recievedData = ExecCommand(port, command, 3000, "Failed to send message"); //3 seconds

ExecCommand 是一个例程,它将命令发送到串行端口并等待从端口获取答案。

米拉德


    public static string Str2Hex(string strMessage)
    {
        byte[] ba = Encoding.BigEndianUnicode.GetBytes(strMessage);
        string strHex = BitConverter.ToString(ba);
        strHex = strHex.Replace("-", "");
        return strHex;
    }

I try to send sms in farsi language according to this article:
http://www.smssolutions.net/tutorials/gsm/sendsmsat/
and it was so easy.
this is my code in c#:

string recievedData = ExecCommand(port, "AT+CSCS=\"HEX\"", 300, "Failed to set message encoding.");
            recievedData = ExecCommand(port, "AT+CSMP=1,167,0,8", 300, "Failed to set message format.");
            //recievedData = ExecCommand(port, "AT+CMGF=1", 300, "Failed to set message format.");

            String command = "AT+CMGS=\"" + Str2Hex(PhoneNo) + "\"";
            recievedData = ExecCommand(port, command, 300, "Failed to accept phoneNo");

            command = Str2Hex(Message) + char.ConvertFromUtf32(26) + "\r";

            recievedData = ExecCommand(port, command, 3000, "Failed to send message"); //3 seconds

ExecCommand is a routine that send command to serial port an wait to get answer from the port.

MILAD


    public static string Str2Hex(string strMessage)
    {
        byte[] ba = Encoding.BigEndianUnicode.GetBytes(strMessage);
        string strHex = BitConverter.ToString(ba);
        strHex = strHex.Replace("-", "");
        return strHex;
    }
蝶舞 2024-10-11 04:11:10

看来你应该使用 PDU 格式。

从这个链接开始!

it seems that you should use PDU format.

start with this link!

梦情居士 2024-10-11 04:11:10

这可以发送孟加拉语或任何语言,也可以发送 unicode AT 命令

   SP.Write("AT\r");
    Thread.Sleep(2000);
    progressSending.Value = 40;
    SP.Write("AT+CSCS=HEX\r\n");
    Thread.Sleep(2000);
    progressSending.Value = 50;
    SP.Write("AT+CMGF=1\r\n");
    Thread.Sleep(2000);
    progressSending.Value = 60;
    SP.Write("AT+CSMP=1,173,0,8\r\n");
    Thread.Sleep(2000);
    progressSending.Value = 70;
    SP.Write("AT+CMGS=" + here write receive number + Char.ConvertFromUtf32(13));
    Thread.Sleep(2000);           
    progressSending.Value = 80;                          
    SP.Write(Str2Hex(your stirng value) + "\x1A" + "\r\n");
    Thread.Sleep(2000);
    progressSending.Value = 90;

这是将字符串转换为十六进制

public static string Str2Hex(string strMessage)
{
    byte[] ba = Encoding.BigEndianUnicode.GetBytes(strMessage);
    string strHex = BitConverter.ToString(ba);
    strHex = strHex.Replace("-", "");
    return strHex;
 }

This is working to send bangla or any language and also unicode send AT Command

   SP.Write("AT\r");
    Thread.Sleep(2000);
    progressSending.Value = 40;
    SP.Write("AT+CSCS=HEX\r\n");
    Thread.Sleep(2000);
    progressSending.Value = 50;
    SP.Write("AT+CMGF=1\r\n");
    Thread.Sleep(2000);
    progressSending.Value = 60;
    SP.Write("AT+CSMP=1,173,0,8\r\n");
    Thread.Sleep(2000);
    progressSending.Value = 70;
    SP.Write("AT+CMGS=" + here write receive number + Char.ConvertFromUtf32(13));
    Thread.Sleep(2000);           
    progressSending.Value = 80;                          
    SP.Write(Str2Hex(your stirng value) + "\x1A" + "\r\n");
    Thread.Sleep(2000);
    progressSending.Value = 90;

This is Converted string to HexaDecimal

public static string Str2Hex(string strMessage)
{
    byte[] ba = Encoding.BigEndianUnicode.GetBytes(strMessage);
    string strHex = BitConverter.ToString(ba);
    strHex = strHex.Replace("-", "");
    return strHex;
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文