简体   繁体   English

Microduino ENC28J60以太网模块(与Arduino兼容)UDP发送不起作用

[英]Microduino ENC28J60 Ethernet Module (Arduino compatible) UDP Send not working

I am using the new Microduino ENC28J60 Ethernet Module (Arduino compatible). 我正在使用新的Microduino ENC28J60以太网模块(与Arduino兼容)。

I am using the udpListener sketch and want to echo a message back to the sender when a UDP packet arrives. 我正在使用udpListener草图,并希望在UDP数据包到达时将消息回显给发送方。

I am receiving messages OK, but the udpSend in the callback method will not work. 我收到的消息还可以,但是回调方法中的udpSend无法正常工作。

This works fine on the Arduino Uno with Ethernet shield 这在带有以太网屏蔽的Arduino Uno上运行良好

Can anyone help. 谁能帮忙。

Thanks in Advance 提前致谢

Here is the Code: 这是代码:

// 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 cybexsoft@hotmail.com

#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());
}

===== ADDITIONAL INFORMATION ==== =====其他信息====

Hi, 嗨,

Sorry the includes are: 抱歉,包括:

include EtherCard.h include IPAddress.h They seem to get removed from the text with the left arrow & right arrow symbol as used in c++. include EtherCard.h include IPAddress.h在c ++中,它们似乎已从带有左箭头和右箭头符号的文本中删除。

I take your note about the ether class. 我注意到你关于以太坊的情况。 I used an example from the Ethercard folder called "udpListener" and was puzzled about the class not being declared. 我使用了Ethercard文件夹中的一个名为“ udpListener”的示例,并对未声明该类感到困惑。 I assumed in was done in the ethercard.h. 我以为是在ethercard.h中完成的。

The program as is does work and listens to and displays correctly received udp packets with the udpSerialPrint method, so the Listening side works. 该程序照常运行,并使用udpSerialPrint方法侦听并显示正确接收的udp数据包,因此侦听端可以正常工作。 I wanted to echo back something to the sender of the udp packet and it is udpSend does not work. 我想将某些信息回显到udp数据包的发送者,这是udpSend不起作用的。

The shield that I am using is as on the link: http://hobbycomponents.com/index.php/microduino-enc28j60-ethernet-module-arduino-compatible.html 我使用的屏蔽位于链接上: http : //hobbycomponents.com/index.php/microduino-enc28j60-ethernet-module-arduino-compatible.html

The compatible libraries are found through the same webpage: 可通过同一网页找到兼容的库:

https://github.com/jcw/ethercard https://github.com/jcw/ethercard

I hope this provides you with further info as necessary. 我希望这会在必要时为您提供更多信息。

First of all, the posted code doesn't seem complete. 首先,发布的代码似乎并不完整。 There are several incomplete #include 's, also, I don't see where the ether class is defined. 还有几个不完整的#include ,我也看不到ether类的定义位置。

Next, if your code use to work on Ethernet Shield, then what libs were used and more specifically what chip is on the Ethernet shield? 接下来,如果您的代码用来在Ethernet Shield上工作,那么使用了哪些库,更具体地说是在Ethernet Shield上使用了什么芯片?

The ENCJ2860 is "its own" chip. ENCJ2860是“自己的”芯片。 That is, the libs required to control the ENCJ2860 might be different than the ones used on the Ethernet Shield, if and only if, the chip on the Ethernet Shield was NOT an ENCJ2860. 也就是说,控制ENCJ2860所需的库可能与以太网Shield上使用的库不同,只要且仅当以太网Shield上的芯片不是 ENCJ2860时。

It is impossible to determine this from the information given in this question. 根据问题中给出的信息无法确定这一点。 But, this is the first thing I would look at. 但是,这是我要看的第一件事。

PS I am currently working on sprucing up the libs for an ENCJ2860, and am waiting for an ethernet shield that has an ENCJ2860, so I can help you with this, or send you my libs (still to be debugged!!). PS:我目前正在为ENCJ2860整理库,并且正在等待具有ENCJ2860的以太网屏蔽,因此我可以为您提供帮助,或者将您的库发送给您(尚待调试!)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM