原帖由
ukonline2000
发自:dev.eefocus.com
------------------------------------------------------------------------------------------------------------------------------------------
今天用以前arduino 网络扩展板Ethernet Shield插在Uno32简单测试了一下没问题,正常使用! 测试了一下telnet,功能正常! 代码如下:
#include <SPI.h> #include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //设置arduino的MAC地址 byte ip[] = { 192,168,1,177}; //设置arduino的IP
byte server[] = { 192,168,1,77 }; //设置需要连接的telnet服务器IP
Client client(server, 23); //服务器端口23
void setup() { Ethernet.begin(mac, ip); Serial.begin(9600); delay(1000); Serial.println("connecting..."); if (client.connect()) { Serial.println("connected"); } else { Serial.println("connection failed"); } }
void loop() { if (client.available()) { char c = client.read(); Serial.print(c); }
while (Serial.available() > 0) { char inChar = Serial.read(); if (client.connected()) { client.print(inChar); } } if (!client.connected()) { Serial.println(); Serial.println("disconnecting."); client.stop(); while(true); } }
|