日期:2014-05-18 浏览次数:20776 次
private void button1_Click(object sender, EventArgs e) { this.GetSMS(); } public string GetSMS() { System.IO.Ports.SerialPort sp = new System.IO.Ports.SerialPort("COM1", 9600); sp.Open(); sp.DiscardInBuffer(); sp.Write("at+cmgl=\"ALL\"\r"); sp.DiscardInBuffer(); int tick = Environment.TickCount; int timeout = 60000; bool at_finish = false; StringBuilder sb = new StringBuilder(); while (Environment.TickCount - tick < timeout && !at_finish) { sb.Append(sp.ReadExisting()); } sp.Close(); string result = sb.ToString(); return result; }
at+cmgl="ALL" +CMGL: 1,"REC READ","10658830",,"10/11/07,17:49:46+32" (一些内容,略) +CMGL: 2,"REC READ","10658300",,"10/11/07,17:49:11+32" (一些内容,略) +CMGL: 3,"REC READ","10086",,"10/11/07,17:50:36+32" (一些内容,略) OK
at+cmgl="ALL" +CMGL: 1,"REC READ","10658830",,"10/11/07,17:49:46+32" (一些内容,略)