retrieveCallingNumber()

描述

取得來電號碼。

語法


voice.retrieveCallingNumber(number, size)

參數

number:用來存放來電號碼的字元陣列
size:字元陣列(number)的大小

回傳

int:在非同步模式中回傳 0 表示最後呼叫的指令仍然在執行中,回傳 1 表示取得來電號碼成功,而回傳大於 1 的值代表有錯誤發生;在同步模式中回傳 1 表示取得來電號碼成功,回傳 0 表示取得來電號碼失敗

範例

#include <GSM.h>

// PIN 碼
#define PINNUMBER ""

// 初始化 GSM 函式庫
GSM gsmAccess;
GSMVoiceCall vcs;

// 用來存放電話號碼的字元陣列
char numtel[20];

void setup()
{
  // 初始化 Serial
  Serial.begin(9600);
  Serial.println("Receive Voice Call");

  // 連線狀態
  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);
    }
  }

  // 先掛斷通話,避免待會誤判
  vcs.hangCall();

  Serial.println("Waiting Call");
}

void loop()
{
  // 檢查通話的狀態
  switch (vcs.getvoiceCallStatus()) 
  {
    // 什麼事都沒發生
    case IDLE_CALL:

      break;

    // 當沒有播打電話的時候,不會發生這個情況
    case CALLING:

      Serial.println("CALLING");
      break;

    // 有來電!
    case RECEIVINGCALL: 

      Serial.println("RECEIVING CALL");

      // 取得來電號碼
      vcs.retrieveCallingNumber(numtel, 20);

      // 輸出來電號碼到序列埠監控視窗
      Serial.print("Number:");
      Serial.println(numtel);

      // 接聽來電
      vcs.answerCall();         
      break;

    // 通話中
    case TALKING:

      Serial.println("TALKING. Enter line to interrupt.");
      while(Serial.read()!='\n')
        delay(100);
      vcs.hangCall();
      Serial.println("HANG. Waiting Call.");      
      break;
  }
  delay(1000);
}

See also

GSMVoiceCall
getVoiceCallStatus()
ready()
voiceCall()
answerCall()
hangCall()


函式庫參考主頁面

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.