我正在使用Arduino进行套接字通信,并且我需要使用try/catch块来进行适当的处理,你们有什么建议?我的互联网搜索没有成功。
编辑:
我正在使用WiFly模块与移动应用程序交互的代码来构建一个机器人模块,使用Android对移动应用程序进行一些控制,一切都运作得非常好,但有时套接字会断开连接,因此我需要添加处理此类情况的代码,类似于try/catch块,但我没有找到适用于Arduino的类似块。
我的代码:
编辑:
我正在使用WiFly模块与移动应用程序交互的代码来构建一个机器人模块,使用Android对移动应用程序进行一些控制,一切都运作得非常好,但有时套接字会断开连接,因此我需要添加处理此类情况的代码,类似于try/catch块,但我没有找到适用于Arduino的类似块。
我的代码:
void loop() {
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
// Serial.print("client connected \n");
char c = client.read();
if(c == 'L')
turnLeft();
if(c == 'R')
turnRight();
if(c == 'F')
goForward();
if(c == 'B')
goBackward();
if(c == 'S')
Stop();
Serial.print(c);
}
}
// give the web browser time to receive the data
delay(100);
client.stop();
}
}