使用PDU串发送手机短信息

来源:互联网 发布:linux 移动文件夹指令 编辑:程序博客网 时间:2024/04/29 16:23

                        .......

            try
            {

                private   SerialPort    COM1 = new SerialPort("COM1", 19200, Parity.None, 8, StopBits.One);
                COM1.Open();
            }
            catch
            {
                MessageBox.Show("初始化串口失败!", "一般错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            
           

            string pdu = "";  //开始合成PDU串
            pdu += "089168";
            char[] tmpSmscNumber = (SmscNumber + "F").ToCharArray();  //信息中心号码
            for (int i = 0; i < tmpSmscNumber.Length; i += 2)
            {
                pdu += tmpSmscNumber[i + 1].ToString();
                pdu += tmpSmscNumber[i].ToString();
            }

            pdu += "11000D9168";
            char[] tmpDestNumber = (DestNumber + "F").ToCharArray();  //对方手机号码
            for (int i = 0; i < tmpDestNumber.Length; i += 2)
            {
                pdu += tmpDestNumber[i + 1].ToString();
                pdu += tmpDestNumber[i].ToString();

            }

            pdu += "000800";  //08表示采用UCS2编码

            byte[] tmpSmsText = Encoding.Unicode.GetBytes(SmsText);
            pdu += tmpSmsText.Length.ToString("X2");         //短信息长度

            for (int i = 0; i < tmpSmsText.Length; i += 2)  //短信息内容
            {
                pdu += tmpSmsText[i + 1].ToString("X2");
                pdu += tmpSmsText[i].ToString("X2");

           }//完成PUD串的合成

            COM1.Write("AT+CMGC=" + (pdu.Length - 18) / 2 + (char)13);  //将pdu字符串的<length>及回车符写入缓冲区
            Thread.Sleep(500);
            COM1.Write(pdu);
            COM1.Write(((char)26).ToString());  //将pdu字符串及CTRL+Z写入输出缓冲区,并发送数据

..................

 

原创粉丝点击