flush()

描述

删除所有未读的简讯内容。

flush() 是从 Stream 继承而来。

语法


SMS.flush()

参数

无参数

回传

无回传值

范例

/*
SMS receiver


 监控是否有收到简讯,收到简讯时把简讯内容输出到序列埠监控视窗

 Circuit:
 * GSM shield 

 created 25 Feb 2012
 by Javier Zorzano / TD

 This example is in the public domain.
*/

// 函式库
#include <GSM.h>

// PIN 码
#define PINNUMBER ""

// 初始化 GSM 函式库
GSM gsmAccess; // include a 'true' parameter for debug enabled
GSM_SMS sms;

// 用来存放电话号码的字元阵列
char remoteNumber[20];

void setup() 
{
  // 初始化 Serial
  Serial.begin(9600); 

  Serial.println("SMS Messages Receiver");

  // 连线状态
  boolean notConnected = true;

  // 启动 Arduino GSM shield,如果你的 SIM 卡有 PIN 码,请当作 begin() 的参数
  while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");
}

void loop() 
{
  char c;

  // 检查是否有未读的简讯
  if (sms.available())
  {
    Serial.println("Message received from:");

    // 取得传送简讯的电话号码
    sms.remoteNumber(remoteNumber, 20);
    Serial.println(remoteNumber);

    // 这是一个删除简讯的范例,在这裡把开头为 # 的简讯删除
    if(sms.peek()=='#')
    {
      Serial.println("Discarded SMS");
      sms.flush();
    }

    // 读取简讯内容并输出到序列埠监控视窗
    while(c=sms.read())
      Serial.print(c);

    Serial.println("\nEND OF MESSAGE");

    // 删除简讯
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }

  delay(1000);

}

See also

GSM_SMS
beginSMS()
ready()
endSMS()
available()
remoteNumber()
read()
write()
print()
peek()


函式库参考主页面

The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.