Reputation: 16407
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.
Upvotes: 3
Views: 13300
Reputation: 16
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;
}
Upvotes: 0
Reputation: 21
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;
}
Upvotes: 2
Reputation: 463
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 "مرحبا"!
Upvotes: 2
Reputation: 1312
it seems that you should use PDU
format.
start with this link!
Upvotes: 0
Reputation: 161002
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.
Upvotes: 2