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.