阅读短信使用GSM调制解调器没有得到所有的短信

时间:2016-01-19 11:13:58

标签: c# c#-3.0

这是为此创建的代码:

private void button1_Click(object sender, EventArgs e)
 {
    SerialPort srp = new SerialPort("com5", 115145);
    srp.Parity = Parity.None;
    srp.DataBits = 8;
    srp.StopBits = StopBits.One;
    srp.Handshake = Handshake.XOnXOff;
    srp.DtrEnable = true;
    srp.RtsEnable = true;
    srp.NewLine = Environment.NewLine;
    srp.Open();

    srp.WriteLine("AT" + (char)(13));
    Thread.Sleep(1000);

    srp.WriteLine("AT+CMGF=1" + System.Environment.NewLine);
    Thread.Sleep(1000);
    srp.WriteLine("AT+CMGL=\"ALL\"" + (char)(13));
    Thread.Sleep(1000);
    Regex rex = new Regex(@"\+CMGL: (\d+),""(.+)"",""(.+)"",(.*),""(.+)""\r\n(.+)\r\n");
    Match m = rex.Match(srp.ReadExisting());
  //  MessageBox.Show(srp.ReadExisting());
    MessageBox.Show("Plzz Wait ");
    while (m.Success)
    {
        string a = m.Groups[1].Value;
        string c = m.Groups[3].Value;
        string ee = m.Groups[5].Value;
        string f = m.Groups[6].Value;
        ListViewItem item = new ListViewItem(new string[] { a, c, ee, f });
        listView1.Items.Add(item);
       if (textBox1.Text == "" && textBox2.Text == "")
        {
            textBox1.Text = item.SubItems[1].Text;
            textBox2.Text = item.SubItems[3].Text;
            string mess = textBox2.Text;
            string num = textBox2.Text;
           MessageBox.Show(mess + num);

            srp.BaseStream.Flush();
            System.Threading.Thread.Sleep(1000);
            string cb = char.ConvertFromUtf32(26);
            srp.Write("AT+CMGF=1\r");
            MessageBox.Show("baby");
            srp.Write("AT+CMGS=\"" + num + "\"\r\n");// 
            srp.Write("hello !! " + mess + " Logged At  " + cb);//message text message sending               
            MessageBox.Show("Message Send ", "information ", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
           m = m.NextMatch();

    }
       srp.Close();
   }

我无法接收所有短信。

0 个答案:

没有答案