如何在 C# 中使用 at-command 发送阿拉伯短信
如何使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
看起来您必须先将 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.
我对 Unicode(波斯语或阿拉伯语消息)也有类似的问题。请检查我的问题和答案 此帖子。在此线程中,您可以了解如何正确发送 Unicode 消息,并且您的问题将得到解决。
首先请阅读本文,然后将您的 Unicode 消息转换为十六进制格式并设置
AT+CSCS="UCS2"
。你的代码的核心应该是这样的:“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:"06450631062D06280627" is the Hex format of "مرحبا"!
我尝试根据这篇文章用波斯语发送短信:
http://www.smssolutions.net/tutorials/gsm/sendsmsat/
这太容易了。
这是我在 c# 中的代码:
ExecCommand 是一个例程,它将命令发送到串行端口并等待从端口获取答案。
米拉德
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#:
ExecCommand is a routine that send command to serial port an wait to get answer from the port.
MILAD
看来你应该使用
PDU
格式。从这个链接开始!
it seems that you should use
PDU
format.start with this link!
这可以发送孟加拉语或任何语言,也可以发送 unicode AT 命令
这是将字符串转换为十六进制
This is working to send bangla or any language and also unicode send AT Command
This is Converted string to HexaDecimal