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

I have finally found out how to resolve this problem. As I said in in the "Additional Information" section of my question, sending line ends with line feeds caused this mismatching between SerialPort in C# and AT commands in hyperterminal for sending Unicode messages. I have just replaced \r with \n line feeds. The modified code is as follow:

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("0633064406270645" + "\x1A"); 

Leave SerialPort.Encoding and SerialPort.NewLine properties unchanged. It is not necessary to change their default values, just set AT+CSCS="UCS2" to send messages in Unicode format.


First of all check your modem support unicode then change your code to this
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

    GSMPort.Write("AT\r");
    Thread.Sleep(1000);
    GSMPort.Write("AT+CSCS=\"UCS2\"\r");
    Thread.Sleep(1000);
    GSMPort.Write("AT+CMGF=1\r");
    Thread.Sleep(1000);
    GSMPort.Write("AT+CSMP=1,167,0,8\r"); //AT+CSMP=1,167,0,8
    Thread.Sleep(1000);
    GSMPort.WriteLine("AT+CMGS=\"" + destinationNumber + "\"\r\n");
    Thread.Sleep(1000);
    GSMPort.WriteLine("0633064406270645" + "\x1A");

The default encoding for SerialPort is Encoding.ASCII. Either set SerialPort.Encoding to an encoding to supports the character set you're using (like Encoding.UTF32) or use SerialPort.Write(char[], int, int) and convert your Unicode string to bytes in whatever way'd prefer.