Delphi 7-tel szeretném etherneten kommunikációra bírni az arduinomat.
A delphi-s kódhoz ez volt a mintám: http://delphi.about.com/od/networking/l/aa112602a.htm
A delphis socket megjelenítését ezzel a linkkel oldottam meg: http://www.entwickler-ecke.de/topic_TCl ... 438,0.html
A kód működik két pc közt, igaz túl sok hibakezelés nincs benne.
A nagy sikerélménytől felbuzdulva nekiestem, hogy valami hasonlót összeeszkábáljak arduinoval is:
(minta: http://vellamy.blogspot.de/p/sockettcpiparduino.html)
Kód: Egész kijelölése
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // ez lenne az arduino ethernetshield mac-je
IPAddress server(192,168,1,176); //ez lenne a gep amivel kommunikalok
byte port = 502; // ezen a porton fogadná az adatokat a pc
EthernetClient client;
void setup() {
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, port)) {
Serial.println("connected");
// Make a HTTP request:
client.println("Connecting with Arduino Ethernet");
client.println();
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop() {
// if you get a connection, report back via serial:
if (client.connect(server, port)) {
client.print("Uno1_");
client.println("info");
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
delay(1000);
// if there are incoming bytes available from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
delay(1000);
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
for(;;)
;
}
delay(1000);
}
itt akad le(még a setupban): if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet"); ...
Ha a kód második felét jól értem akkor fogadnék is adatot, ahhoz viszont kellene talán a saját shieldre is egy ip-t megadni, az viszont nincs a kódban. (a cél pc ip-je meg a küldés miatt hasznos, de az fentebb található, ha jól értem)
Köszi előre is!
Üdv!
Bazs87