voiceCall()
描述
播打電話至指定的電話號碼。該函式回傳的值在同步與非同步的情況下意義不同,底下會有詳細的介紹。
語法
voice.voiceCall(number)
參數
number:存放電話號碼的字元陣列
回傳
int:在非同步模式中回傳 0 表示最後呼叫的指令仍然在執行中,回傳 1 表示播打電話成功,而回傳大於 1 的值代表有錯誤發生;在同步模式中回傳 1 表示播打電話成功,回傳 0 表示播打電話失敗
範例
#include <GSM.h>
// PIN 碼
#define PINNUMBER ""
// 初始化 GSM 函式庫
GSM gsmAccess;
GSMVoiceCall vcs;
// 用來存放電話號碼
String remoteNumber = "";
char charbuffer[20];
void setup()
{
// 初始化 Serial
Serial.begin(9600);
Serial.println("Make 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);
}
}
Serial.println("GSM initialized.");
Serial.println("Enter phone number to call.");
}
void loop()
{
// 把序列埠監控視窗的輸入加入到 String
while (Serial.available() > 0)
{
char inChar = Serial.read();
// 如果看到換行字元表示電話號碼輸入完成,可以播打電話了
if (inChar == '\n')
{
// 檢查電話號碼是否太長
if (remoteNumber.length() < 20)
{
// 輸出開始播打電話的訊息到序列埠監控視窗
Serial.print("Calling to : ");
Serial.println(remoteNumber);
Serial.println();
remoteNumber.toCharArray(charbuffer, 20);
// 檢查播打電話是否成功
if(vcs.voiceCall(charbuffer))
{
Serial.println("Call Established. Enter line to end");
// 等待使用者輸入換行字元
while(Serial.read() !='\n' && (vcs.getvoiceCallStatus()==TALKING));
// 掛斷電話
vcs.hangCall();
}
Serial.println("Call Finished");
remoteNumber="";
Serial.println("Enter phone number to call.");
}
else
{
Serial.println("That's too long for a phone number. I'm forgetting it");
remoteNumber = "";
}
}
else
{
// 加入讀到的字元到 remoteNumber
if(inChar!='\r')
remoteNumber += inChar;
}
}
}
See also
- GSMVoiceCall
- getVoiceCallStatus()
- ready()
- answerCall()
- hangCall()
- retrieveCallingNumber()
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.
