2013-08-23 36 views
1

我正在使用新的Microduino ENC28J60以太網模塊(與Arduino兼容)。Microduino ENC28J60以太網模塊(與Arduino兼容)UDP發送不工作

我正在使用udpListener草圖並希望在UDP數據包到達時將消息回顯給發件人。

我正在接收消息確定,但回調方法中的udpSend不起作用。

也能正常工作的Arduino的烏諾與以太網屏蔽

誰能幫助。

由於提前

這裏是代碼:

// Demonstrates usage of the new udpServer feature. 
//You can register the same function to multiple ports, and multiple functions to the same port. 
// 
// 2013-4-7 Brian Lee [email protected] 

#include 
#include 

#define STATIC 1 // set to 1 to disable DHCP (adjust myip/gwip values below) 

#if STATIC 
// ethernet interface ip address 
static byte myip[] = { 192,168,0,201 }; 
// gateway ip address 
static byte gwip[] = { 192,168,0,1 }; 

static byte ipDestination[] = {192, 168, 0, 9}; 

unsigned int portMy = 8888; 
unsigned int portDestination = 9000; 

#endif 

// ethernet mac address - must be unique on your network 
static byte mymac[] = { 0x70,0x69,0x69,0x2D,0x30,0x31 }; 

byte Ethernet::buffer[500]; // tcp/ip send and receive buffer 

char msg[] = {"Hello World"}; 

//callback that prints received packets to the serial port 
void udpSerialPrint(word port, byte ip[4], const char *data, word len) { 
IPAddress src(ip[0], ip[1], ip[2], ip[3]); 
Serial.println(src); 
Serial.println(port); 
Serial.println(data); 
Serial.println(len); 

//I Added this to echo the packet <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
ether.sendUdp(msg, sizeof msg, portMy, ipDestination, portDestination); 
Serial.println("UDP Sent !!"); 

} 

void setup(){ 
Serial.begin(9600); 
Serial.println("\n[backSoon]"); 

if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
Serial.println("Failed to access Ethernet controller"); 
#if STATIC 
ether.staticSetup(myip, gwip); 
Serial.println("Serial Started on FixedIP"); 
#else 
if (!ether.dhcpSetup()) 
Serial.println("DHCP failed"); 
#endif 

ether.printIp("IP: ", ether.myip); 
ether.printIp("GW: ", ether.gwip); 
ether.printIp("DNS: ", ether.dnsip); 

//register udpSerialPrint() to port 1337 
ether.udpServerListenOnPort(&udpSerialPrint, portMy); 

//register udpSerialPrint() to port 42. 
//ether.udpServerListenOnPort(&udpSerialPrint, 42); 
} 

void loop(){ 
//this must be called for ethercard functions to work. 
ether.packetLoop(ether.packetReceive()); 
} 

=====附加信息====

嗨,

對不起了包括有:

包括EtherCard.h 包括IPAddress.h 他們似乎從左邊的箭頭&中刪除了文本,正如在C++中使用的右箭頭符號。

我把你的筆記關於以太類。我使用了一個名爲「udpListener」的Ethercard文件夾中的示例,並對該類未聲明感到困惑。我假設在ethercard.h中完成了。

程序按原樣工作,並使用udpSerialPrint方法監聽並顯示正確接收的udp數據包,因此偵聽側工作。我想向udp數據包的發送者回送一些內容,它是udpSend不起作用。

,我使用的屏蔽是鏈接:

https://github.com/jcw/ethercard

我希望這爲你提供必要的進一步信息:http://hobbycomponents.com/index.php/microduino-enc28j60-ethernet-module-arduino-compatible.html

兼容庫通過相同的網頁中找到。

+0

我與該庫有相同的問題。你解決了嗎?一個問題是,當你發送像這樣的upd數據包時,你的目的地mac地址爲0. – Gossamer

回答

1

首先,發佈的代碼似乎並不完整。有幾個不完整的#include's,我也看不到ether類定義在哪裏。

接下來,如果您的代碼使用以太網盾工作,那麼使用什麼庫,更具體地說什麼芯片在以太網盾上?

ENCJ2860是「自己的」芯片。也就是說,控制ENCJ2860所需的庫可能與以太網屏蔽器上使用的庫不同,當且僅當以太網屏蔽上的芯片是不是和ENCJ2860。

從這個問題給出的信息是不可能的。但是,這是我首先想到的。

P.S.我目前正在研究ENCJ2860的庫文件,並且正在等待一個ENCJ2860的以太網盾牌,所以我可以幫你解決這個問題,或者向你發送我的庫文件(還有待調試!!)。

+0

我在回覆你的問題時在第一篇文章中增加了額外的信息。謝謝 –

+0

嗨,你有關於這個問題的任何信息,因爲我需要幫助,不能在任何地方找到它。謝謝 –

相關問題