Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a project where I need to send an Text Message (SMS) to any mobile number using itegno 3800 GSM modem attached to a USB cable.
I can send SMS for only ordinary message like alphabet and numbers.

my problem is when i used to send a message containing (~) character it doesn't appear on the receiving mobile/device.

here is my code on sending:

C#
port.PortName = p_strPortName;                 //COM1
              port.BaudRate = p_uBaudRate;                   //9600
              port.DataBits = p_uDataBits;                   //8
              port.StopBits = StopBits.One;                  //1
              port.Parity = Parity.None;                     //None
              port.ReadTimeout = p_uReadTimeout;             //300
              port.WriteTimeout = p_uWriteTimeout;           //300
              port.Encoding = Encoding.GetEncoding("iso-8859-1");
              port.Handshake = Handshake.None;
              port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);

              System.Threading.Thread.Sleep(50);

              port.Open();
              port.DtrEnable = true;
              port.RtsEnable = true;


C#
string recievedData = ExecCommand(port, "AT", 300, "No phone connected");
                   recievedData = ExecCommand(port, "AT+CMGF=1", 300, "Failed to set message format.");
                   String command = "AT+CMGS=\"" + PhoneNo + "\"";
                   recievedData = ExecCommand(port, command, 300, "Failed to accept phoneNo");
                   command = Message + char.ConvertFromUtf32(26) + "\r";

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

                   if (recievedData.EndsWith("\r\nOK\r\n"))
                   {
                       isSend = true;
                   }
                   else if (recievedData.Contains("ERROR"))
                   {
                       isSend = false;
                   }



C#
port.DiscardOutBuffer();
               port.DiscardInBuffer();
               receiveNow.Reset();
               port.Write(command + "\r");

               string input = ReadResponse(port, responseTimeout);
               if ((input.Length == 0) || ((!input.EndsWith("\r\n> ")) && (!input.EndsWith("\r\nOK\r\n"))))
               {
                   return input;
               }
               else
               {
                   return input;
               }



please don't mind some missing scripts as I only included some major codes.

my intent is to send SMS completely even it has a special character like (~).

Your feedback and comments are highly appreciated.

Thank you.

Michael John Bernarte
Posted
Comments
[no name] 29-Oct-15 5:05am    
What is the debugger telling you?
Mshadow17 29-Oct-15 6:27am    
there is no error on my application/debugger. the ~ sign is just missing when the receiver/mobile phone received the message with ~ sign.

example: I've encoded "~test sms". then i will only receive "test sms".
[no name] 29-Oct-15 6:31am    
As pointed out by JA Tilde must be encoded as 0x1B3D - it is not.
Jochen Arndt 29-Oct-15 9:30am    
According to your link Tilde must be encoded as 0x1B3D. Even then the receiving device must support the escape extension.
[no name] 29-Oct-15 9:56am    
Yes indeed. I'll update my comment.

1 solution

SMS use specific character sets where the basic 7-bit set which must be always supported is not identical to ASCII. See the Wikipedia[^].

So you must encode your message string according to the used GSM encoding scheme.

[EDIT]
You might have a look at the CP article Library for Decode/Encode SMS PDU[^].
 
Share this answer
 
v2
Comments
Mshadow17 29-Oct-15 5:38am    
Hi Jochen, can you give me a recommendation on this matter?

thank you.
Jochen Arndt 29-Oct-15 5:46am    
See my updated answer.
[no name] 29-Oct-15 10:01am    
As you mention the network must support the escape sequence. This might be worth adding to answer.
Jochen Arndt 29-Oct-15 11:23am    
It must be supported by the receiving device. If it is not supported the Escape is displayed as space and the escaped code according to the table (equal sign for 0x1B30). This is mentioned in the above Wikipedia link.

But I think this is not relevant for now while the message text itself is not converted.

Finally I guess that most phones support it.
Mshadow17 31-Oct-15 6:19am    
I still can't get the correct code. I've tried "\x07E" and different hex value but still missing on my SMS. my intent is to receive the "~" value.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900