日期:2014-05-18 浏览次数:21039 次
string strTemp = ""; SerialPort sp = new SerialPort(); serialPort.BaudRate = baudRate; serialPort.PortName = "COM" + id.ToString(); serialPort.DataBits = 8; serialPort.Open(); strTemp = "AT+CMGF=0\r"; serialPort.Write(Encoding.ASCII.GetBytes(strTemp), 0, Encoding.ASCII.GetBytes(strTemp).Length); Thread.Sleep(500); byte[] buffer1 = new byte[serialPort.BytesToRead]; serialPort.Read(buffer1, 0, buffer1.Length); string str = Encoding.ASCII.GetString(buffer1); if (str.Contains("OK")) { strTemp = string.Format("AT+CMGS={0}\r", de.smsDecodedsms("8613800200500", 接收短信的号码, "abc你好!").Length); serialPort.Write(Encoding.ASCII.GetBytes(strTemp), 0, Encoding.ASCII.GetBytes(strTemp).Length); Thread.Sleep(500); byte[] buffer2 = new byte[serialPort.BytesToRead]; serialPort.Read(buffer2, 0, buffer2.Length); string str = Encoding.ASCII.GetString(buffer2); if (str.Contains(">")) { strTemp = de.smsDecodedsms("8613800200500", 接收短信的号码, "abc你好!") + "\x01a"; serialPort.Write(Encoding.ASCII.GetBytes(strTemp), 0, Encoding.ASCII.GetBytes(strTemp).Length); } } serialPort.Close();