begin()
描述
连接到 GSM 网路。
语法
gsm.begin()
gsm.begin(pin)
gsm.begin(pin, restart)
gsm.begin(pin, restart, sync)
参数
pin:储存 PIN 码的字元阵列,预设为 0
restart :如果 restart 为 true 会重新启动 Arduino GSM shield,接着再初始化,反之则不会重新启动,直接初始化。restart 预设为 true,型态为 boolean
sync:如果 sync 为 true 则为同步(synchronous)模式,反之为非同步(asynchronous)模式,sync 预设为 true,型态为 boolean
回传
char:如果是非同步状态回传 0;如果是同步状态,回传连线的状态:ERROR, IDLE, CONNECTING, GSM_READY, GPRS_READY, TRANSPARENT_CONNECTED
范例
#include <GSM.h>
#define PINNUMBER ""
GSM gsm;
void setup()
{
// 初始化 Serial
Serial.begin(9600);
// 连线状态
boolean notConnected = true;
// 启动 Arduino GSM shield,如果你的 SIM 卡有 PIN 码,请当作 begin() 的参数
while(notConnected)
{
if(gsm.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
}
void loop()
{
// 不做任何事
}
See also
- GSM constructor
- shutdown()
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.
