Main Site Documentation

Cellular board send SMS in PDU mode


#1

Does anyone can send SMS in PDU mode using Cellular module?

I try this, but not work.

 PDU pdeencoding;
 pdeencoding = new PDU("0963354403", "Test", "+886932400821"); 
string pdustring =pdeencoding.Code;
serialLine.Write("AT+CMGF=0");
serialLine.Write("AT+CMGS=" + pdeencoding.Length.ToString());
Thread.Sleep(100);
serialLine.Write(pdustring);
Thread.Sleep(100);
serialLine.Write((char)26 + "\r");

PDU class


class PDU
    {
                public string SCA;     
        public string TYPE;    
        public string MR;        
        public string DA;      
        public string PID;     
        public string DCS;     
        public string VP;      
        public string UDL;     
        public string UD;      

        public static bool IsASCII(string str)
        {
            int strLen = str.Length;
            int byteLen = System.Text.Encoding.UTF8.GetBytes(str).Length;
            return (strLen == byteLen);
        }

        //CenterNumber = 

        //+886932400821,+886932400841, +886932400851, +886932400881, +886932400882
        public PDU(string phone, string msg, string CenterNumber)
        {
            if (CenterNumber.Length == 0)
            {
                SCA = "00";
            }
            else
            {
                SCA = FormatCenterNumber(CenterNumber);
            }
            TYPE = "11";//
            MR = "00";
            DA = FormatPhone(phone);
            PID = "00";
            DCS = "08";
            VP = "C4"; //"AA";
            UD = Msg2Unicode(msg);
            UDL = (UD.Length / 2).ToString("X2");
        }

        public string Code
        {
            get
            {
                return SCA + TYPE + MR + DA + PID + DCS + VP + UDL + UD;
            }
        }

        public int Length
        {
            get
            {
                return (Code.Length - Convert.ToInt32(Code.Substring(0, 2), 16) * 2 - 2) / 2;
            }
        }

        #region 

        private string Msg2Unicode(string msg)
        {
            if (msg.Length == 0) return "";
            if (msg.Length > 70) msg = msg.Substring(0, 70);

            string strUnicode = "";
            foreach (char c in msg)
            {
                strUnicode += ((UInt16)c).ToString("X4");
            }

            return strUnicode;
        }

        private string FormatCenterNumber(string CenterNumber)
        {
            if (CenterNumber.Length != 13) return "";
            //CenterNumber = CenterNumber.Substring(1, CenterNumber.Length - 1) + "F";
            CenterNumber = CenterNumber.Substring(1, CenterNumber.Length - 1) ;
            return "0791" + ParityChange(CenterNumber);
        }
        //+886963354403
        private string FormatPhone(string phone)
        {
            if (phone.Substring(0, 4) == "+886")
            {
                phone = phone.Substring(4, phone.Length - 4);
            }
            if (phone.Length != 10) return "";

           // phone = "886" + phone + "F";
            //phone = "886" + phone ;
            
            return "0A81" + ParityChange(phone);
        }

        private string ParityChange(string str)
        {
            string strTemp = "";
            for (int i = 0; i < str.Length; i += 2)
            {
                strTemp += str[i + 1].ToString() + str[i].ToString();
            }
            return strTemp;
        }

        #endregion
    }



#2

One weeks pass, no answer.
I need to send chinese text, the text mode not work.
Does any one can send text that not using English?