乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      C# at命令發(fā)送&&接收短信測(cè)試程序

       昵稱10504424 2013-02-19

      此文轉(zhuǎn)載,出處不明。

      1. using System;  
      2. using System.Collections.Generic;  
      3. using System.ComponentModel;  
      4. using System.Data;  
      5. using System.Drawing;  
      6. using System.Linq;  
      7. using System.Text;  
      8. using System.Windows.Forms;  
      9.    
      10. namespace SPAT  
      11. {  
      12.    
      13.     delegate void del_ShowMsg(string msg);  
      14.    
      15.     public partial class Form1 : Form  
      16.     {  
      17.         public Form1()  
      18.         {  
      19.             InitializeComponent();  
      20.             button1.Enabled = false;  
      21.             button3.Enabled = false;  
      22.             button4.Enabled = false;  
      23.             button5.Enabled = false;  
      24.             button6.Enabled = false;  
      25.             button7.Enabled = false;  
      26.             textBox7.Enabled = true;  
      27.             textBox7.Text = "0";  
      28.             textBox8.Text = "0";  
      29.             textBox7.Enabled = false;  
      30.             textBox10.Enabled = false;  
      31.             button8.Enabled = false;  
      32.             button9.Enabled = false;  
      33.             button10.Enabled = false;  
      34.    
      35.         }  
      36.    
      37.         private void Form1_Load(object sender, EventArgs e)  
      38.         {  
      39.         }  
      40.    
      41.         private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)  
      42.         {  
      43.             if (serialPort1.IsOpen)  
      44.                 Invoke(new del_ShowMsg(ShowMsg), serialPort1.ReadLine());  
      45.             else  
      46.                 return;  
      47.         }  
      48.         private void ShowMsg(string msg)  
      49.         {  
      50.             textBox9.Text += msg;  
      51.             int index = msg.IndexOf("+CSCA:");  
      52.             if (index != -1)  
      53.             {  
      54.                 textBox10.Enabled = true;  
      55.                 textBox10.Text = msg.Substring(index + 11, 11);  
      56.                 textBox10.Enabled = false;  
      57.                 return;  
      58.             }  
      59.             {  
      60.                 int number = int.Parse(msg.Substring(msg.IndexOf("\"SM\",") + 5));  
      61.                 int number7 = int.Parse(textBox7.Text);  
      62.                 textBox8.Text = msg.Substring(msg.IndexOf("\"SM\",") + 5);  
      63.                 if (number7 < number)  
      64.                 {  
      65.                     textBox7.Enabled = true;  
      66.                     textBox7.Text = number.ToString();  
      67.                     textBox7.Enabled = false;  
      68.                 }  
      69.                 return;  
      70.             }  
      71.             if (msg.Length > 33)  
      72.             {  
      73.                 string telnum = "+" + DecodeTelnum(msg);  
      74.                 string msgDestination = DecodeMessage(msg);  
      75.                 string time = DecodeTime(msg);  
      76.                 textBox1.Text = telnum;  
      77.                 textBox4.Text = msgDestination;  
      78.                 textBox5.Text = time;  
      79.             }  
      80.             else  
      81.             {  
      82.                 {  
      83.                     textBox1.Text = "";  
      84.                     textBox4.Text = "";  
      85.                     textBox5.Text = "";  
      86.                 }  
      87.                 int index1 = msg.IndexOf("+CMGL:");  
      88.                 int index2 = msg.IndexOf(",");  
      89.                 if (index1 != -1)  
      90.                 {  
      91.                     string strTemp = msg.Substring(index1 + 6, index2 - index1 - 6);  
      92.                     if (textBox7.Text.Trim().CompareTo(strTemp) > 0)  
      93.                     {  
      94.                         textBox7.Enabled = true;  
      95.                         textBox7.Text = strTemp.Trim();  
      96.                         textBox7.Enabled = false;  
      97.                     }  
      98.                 }  
      99.                 textBox6.Text = msg;  
      100.             }  
      101.             //{  
      102.             //    //string telnum = DecodeTelnum(msg);  
      103.             //    //string msgDestination = DecodeMessage(msg);  
      104.             //    //textBox1.Text = msgDestination;  
      105.             //    //    textBox1.Text = msg;  
      106.             //    //else  
      107.             //    //    textBox1.Text = textBox1.Text + Environment.NewLine + " " + msg;  
      108.             //    //button1.Enabled = true;  
      109.             //}  
      110.             //if (msg.Length > 5)  
      111.             //    {  
      112.             //        numberRead = msg.Substring(msg.LastIndexOf(',') + 1);  
      113.             //    }  
      114.         }  
      115.         /// <summary>  
      116.         /// 將電話號(hào)碼奇偶位對(duì)換進(jìn)行編碼  
      117.         /// </summary>  
      118.         /// <param name="str"></param>  
      119.         /// <returns></returns>  
      120.         private string EncodeTelnum(string str)  
      121.         {  
      122.             //源電話號(hào)碼  
      123.             string strSource = "86" + str;  
      124.             if (strSource.Length % 2 == 1)//如果為奇數(shù),補(bǔ)F  
      125.             //變換號(hào)碼  
      126.             char[] strchar = strSource.ToCharArray();  
      127.             char temp;  
      128.             if (strchar.Length % 2 == 1)  
      129.             else  
      130.             {  
      131.                 for (int i = 0; i < strchar.Lengthi = i + 2)  
      132.                 {  
      133.                     temp = strchar[i];  
      134.                     strchar[i] = strchar[i + 1];  
      135.                     strchar[i + 1] = temp;  
      136.                 }  
      137.             }  
      138.             string strDestination = new string(strchar);  
      139.             return strDestination;  
      140.    
      141.         /// <summary>  
      142.         /// 中文英文混合編碼  
      143.         /// </summary>  
      144.         /// <param name="str"></param>  
      145.         /// <returns></returns>  
      146.         private string EncodeUnicode(string str)  
      147.         {  
      148.             byte[] tmpSmsText = Encoding.Unicode.GetBytes(str);//轉(zhuǎn)換成UTF-16編碼  
      149.             string strDestination = Convert.ToString(tmpSmsText.Length, 16);//將長(zhǎng)度表示為16進(jìn)制數(shù)(以字符串形式)  
      150.             if (strDestination.Length == 1)  
      151.                 strDestination = "0" + strDestination;  
      152.             else  
      153.                 if (strDestination.Length == 0)  
      154.                     strDestination = "00";  
      155.             for (int i = 0; i < tmpSmsText.Length; i += 2) //高低字節(jié)對(duì)調(diào)   
      156.             {  
      157.                 string strTemp = Convert.ToString(tmpSmsText[i + 1], 16);  
      158.                 if (strTemp.Length == 1)  
      159.                     strTemp = "0" + strTemp;  
      160.                 else  
      161.                     if (strTemp.Length == 0)  
      162.                         strTemp = "00";  
      163.                 strDestination += strTemp;  
      164.                 strTemp = Convert.ToString(tmpSmsText[i], 16);  
      165.                 if (strTemp.Length == 1)  
      166.                     strTemp = "0" + strTemp;  
      167.                 else  
      168.                     if (strTemp.Length == 0)  
      169.                         strTemp = "00";  
      170.                 strDestination += strTemp;  
      171.             }  
      172.             return strDestination;  
      173.         }  
      174.         /// <summary>  
      175.         /// 漢字PDU編碼  
      176.         /// </summary>  
      177.         /// <param name="str"></param>  
      178.         /// <returns></returns>  
      179.         private string EncodeMessage(string str)  
      180.         {  
      181.             string strDestination;  
      182.             if (str.Length * 2 < 16)  
      183.                 strDestination = "0" + Convert.ToString(str.Length * 2, 16);  
      184.             else  
      185.                 if (str.Length * 2 < 256)  
      186.                     strDestination = Convert.ToString(str.Length * 2, 16);  
      187.                 else  
      188.                 {  
      189.                 }  
      190.             foreach (char item in str)  
      191.             {  
      192.                 int i = item;  
      193.                 strDestination += Convert.ToString(i, 16);  
      194.             }  
      195.             return strDestination;  
      196.         }  
      197.         /// <summary>  
      198.         /// 英文編碼  
      199.         /// </summary>  
      200.         /// <param name="str"></param>  
      201.         /// <returns></returns>  
      202.         private string EncodeEnglish(string str)  
      203.         {  
      204.             string strDestination = Convert.ToString(str.Length, 16);  
      205.             if (str.Length < 16)  
      206.                 strDestination = "0" + strDestination;  
      207.    
      208.             for (int i = 0; i < str.Length; i++)  
      209.             {  
      210.                 if (i < (str.Length - 1))  
      211.                 {  
      212.                     if (i % 8 != 7)  
      213.                         strDestination += EncodeLetter(str[i], str[i + 1], i % 8);  
      214.                     else  
      215.                         continue;  
      216.                 }  
      217.                 else  
      218.    
      219.             }  
      220.             return strDestination;  
      221.    
      222.         }  
      223.         /// <summary>  
      224.         /// 單個(gè)字符編碼  
      225.         /// </summary>  
      226.         /// <param name="a1"></param>  
      227.         /// <param name="a2"></param>  
      228.         /// <param name="i"></param>  
      229.         /// <returns></returns>  
      230.         private string EncodeLetter(char a1, char a2, int i)  
      231.         {  
      232.             string stra1 = Convert.ToString(a1, 2);  
      233.             char[] strChara1 = new char[8];  
      234.             int j = 0k = 0;  
      235.             //賦值  
      236.             for (j = stra1.Length - 1, k = 0; k < 8; j--)  
      237.             {  
      238.                 if (j >= 0)  
      239.                     strChara1[k++] = stra1[j];  
      240.                 else  
      241.             }  
      242.             //右移i位  
      243.    
      244.             for (j = 0k = i; j < 8; )  
      245.             {  
      246.                 if (k < 8)  
      247.                     strChara1[j++] = strChara1[k++];  
      248.                 else  
      249.             }  
      250.    
      251.             char[] strChara2 = new char[8];  
      252.             //賦值  
      253.             if (a2 == '\0')  
      254.             {  
      255.                 for (int m = 0; m < 8; m++)  
      256.             }  
      257.             else  
      258.             {  
      259.                 string stra2 = Convert.ToString(a2, 2);  
      260.                 for (j = stra2.Length - 1, k = 0; k < 8; j--)  
      261.                 {  
      262.                     if (j >= 0)  
      263.                         strChara2[k++] = stra2[j];  
      264.                     else  
      265.                 }  
      266.             }  
      267.             for (int s = 0; s < i + 1; s++)  
      268.             {  
      269.                 strChara1[7 - i + s] = strChara2[s];  
      270.             }  
      271.             strChara1 = Inversion(strChara1);  
      272.             stra1 = new string(strChara1);  
      273.             int inta1 = Convert.ToInt32(stra1, 2);  
      274.             string strDestion = Convert.ToString(inta1, 16);  
      275.             if (strDestion.Length == 1)  
      276.                 strDestion = "0" + strDestion;  
      277.             else  
      278.                 if (strDestion.Length == 0)  
      279.                     strDestion = "00";  
      280.             return strDestion;  
      281.         }  
      282.         /// <summary>  
      283.         /// 逆置字符數(shù)組  
      284.         /// </summary>  
      285.         /// <param name="a1"></param>  
      286.         /// <returns></returns>  
      287.         private char[] Inversion(char[] a1)  
      288.         {  
      289.             char[] a2 = new char[a1.Length];  
      290.             for (int i = 0j = a1.Length - 1; i < a1.Length; i++, j--)  
      291.             {  
      292.                 a2[j] = a1[i];  
      293.             }  
      294.             return a2;  
      295.         }  
      296.    
      297.         //關(guān)閉串口  
      298.         private void button1_Click(object sender, EventArgs e)  
      299.         {  
      300.             textBox1.Text = EncodeTelnum(textBox2.Text.Trim().ToString());  
      301.             serialPort1.Close();  
      302.             textBox1.Text = "";  
      303.             textBox4.Text = "";  
      304.             textBox5.Text = "";  
      305.             textBox6.Text = "";  
      306.             button1.Enabled = false;  
      307.             button2.Enabled = true;  
      308.             button3.Enabled = false;  
      309.             button6.Enabled = false;  
      310.             button5.Enabled = false;  
      311.             button4.Enabled = false;  
      312.             button7.Enabled = false;  
      313.             button8.Enabled = false;  
      314.             button9.Enabled = false;  
      315.             button10.Enabled = false;  
      316.             label1.Text = serialPort1.IsOpen.ToString();  
      317.         }  
      318.         //打開串口  
      319.         private void button2_Click(object sender, EventArgs e)  
      320.         {  
      321.             //serialPort1.NewLine = Environment.NewLine;  
      322.             serialPort1.BaudRate = 115200;  
      323.             serialPort1.PortName = "com1";  
      324.             try  
      325.             {  
      326.                 serialPort1.Open();  
      327.             }  
      328.             catch  
      329.             {  
      330.                 return;  
      331.             }  
      332.             textBox1.Text = "";  
      333.             textBox1.Text = EncodeMessage(textBox3.Text);  
      334. cmgf=1");//Text模式發(fā)送英文  
      335. cmgf=0\x0a");//PDU模式發(fā)送  
      336. cnmi=2,1");//  
      337.             //int count = 14 + EncodeUnicode(textBox3.Text).Length / 2;//PDU模式混發(fā)  
      338. cmgs=" + count);//PDU模式發(fā)送  
      339.             //string message = "0011000D91" + EncodeTelnum(textBox2.Text.Trim()) + "000800" + EncodeUnicode(textBox3.Text.Trim()).ToUpper() + "\x01a";//PDU模式混發(fā)  
      340.             //serialPort1.WriteLine(message);//PDU模式發(fā)送  
      341.             label1.Text = serialPort1.IsOpen.ToString();  
      342.             button2.Enabled = false;  
      343.             button1.Enabled = true;  
      344.             button3.Enabled = true;  
      345.             button6.Enabled = true;  
      346.             button7.Enabled = true;  
      347.             button8.Enabled = true;  
      348.             button9.Enabled = true;  
      349.             button10.Enabled = true;  

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多