9
I am developing an application for GSM Modems (D-Link DWM-156) in C#.Net using AT commands. I have a problem sending Unicode messages (Such as messages written in Persian or Arabic). Here it is the core of my program:
SerialPort GSMPort = new SerialPort();
GSMPort.PortName = "COM6";
GSMPort.BaudRate = 9600;
GSMPort.Parity = Parity.None;
GSMPort.DataBits = 8;
GSMPort.StopBits = StopBits.One;
GSMPort.Handshake = HandShake.RequestToSend;
GSMPort.DtrEnable = true;
GSMPort.RtsEnable = true;
GSMPort.Open();
GSMPort.Write("AT\r");
Thread.Sleep(1000);
GSMPort.Write("AT+CMGF=1\r");
Thread.Sleep(1000);
GSMPort.Write("AT+CMGS=\"" + destinationNumber + "\"\r\n");
Thread.Sleep(1000);
GSMPort.Write(shortMessage+ "\x1A");
It works fine for English and ASCII letters. I have read this article and can send Unicode messages in Hyperterminal using AT commands:
AT [Enter]
OK
AT+CSCS="UCS2" or AT+CSCS="HEX" [Enter] ---> We have to convert our message to hex
OK
AT+CMGF=1 [Enter]
OK
AT+CMGS="destinationNumber" [Enter]
> 0633064406270645002006450631062D06280627 ---> The hex format of our message (سلام مرحبا)
+CMGS: 139
OK
Since this commands worked correctly, I have added GSMPort.Write("AT+CSCS=\"UCS2\"\r"); to my application, and tried to send 0645 0631 062D 0628 0627 (مرحبا) or 0633 0644 0627 0645 (سلام).
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+CMGS=\"" + destinationNumber + "\"\r\n");
Thread.Sleep(1000);
GSMPort.Write("0633064406270645" + "\x1A");
But unlike AT commands in Hyperterminal, destination does not receive correct letters. What is the difference between these AT commands in C# code and Hyperterminal code? I