public PDUData getSms(int id) { this.Write("AT+CMGR=" + id + endFlag); this.ReadTo("AT+CMGR=" + id + endFlag); this.ReadTo(endFlag); PDUData data = null; string line; while (true) { line = this.ReadTo(endFlag); Console.WriteLine(line); if (line.StartsWith("OK")) { return(data); } else if (line.StartsWith("ERROR")) { throw new Exception("获取短信[" + id + "]失败"); } else if (line.StartsWith("+CMGR:")) { line = this.ReadTo(endFlag); Console.WriteLine(line); data = PDUData.parseSmsDeliverPUD(line); } } }
public ArrayList getAllSms() { string p = "4"; if (this.getSmsMode().Equals("1")) { p = "\"ALL\""; } this.Write("AT+CMGL=" + p + endFlag); this.ReadTo("AT+CMGL=" + p + endFlag); this.ReadTo(endFlag); ArrayList smsArray = new ArrayList(); string line; while (true) { line = this.ReadTo(endFlag); if (line.StartsWith("OK")) { return(smsArray); } else if (line.StartsWith("ERROR")) { throw new Exception("获取所有短信失败"); } else if (line.StartsWith("+CMGL:")) { line = this.ReadTo(endFlag); Console.WriteLine(line); PDUData data = PDUData.parseSmsDeliverPUD(line); smsArray.Add(data); } } }