簡體   English   中英

Microduino ENC28J60以太網模塊(與Arduino兼容)UDP發送不起作用

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

我正在使用新的Microduino ENC28J60以太網模塊(與Arduino兼容)。

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

我收到的消息還可以,但是回調方法中的udpSend無法正常工作。

這在帶有以太網屏蔽的Arduino Uno上運行良好

誰能幫忙。

提前致謝

這是代碼:

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

=====其他信息====

嗨,

抱歉,包括:

include EtherCard.h include IPAddress.h在c ++中,它們似乎已從帶有左箭頭和右箭頭符號的文本中刪除。

我注意到你關於以太坊的情況。 我使用了Ethercard文件夾中的一個名為“ udpListener”的示例,並對未聲明該類感到困惑。 我以為是在ethercard.h中完成的。

該程序照常運行,並使用udpSerialPrint方法偵聽並顯示正確接收的udp數據包,因此偵聽端可以正常工作。 我想將某些信息回顯到udp數據包的發送者,這是udpSend不起作用的。

我使用的屏蔽位於鏈接上: http : //hobbycomponents.com/index.php/microduino-enc28j60-ethernet-module-arduino-compatible.html

可通過同一網頁找到兼容的庫:

https://github.com/jcw/ethercard

我希望這會在必要時為您提供更多信息。

首先,發布的代碼似乎並不完整。 還有幾個不完整的#include ,我也看不到ether類的定義位置。

接下來,如果您的代碼用來在Ethernet Shield上工作,那么使用了哪些庫,更具體地說是在Ethernet Shield上使用了什么芯片?

ENCJ2860是“自己的”芯片。 也就是說,控制ENCJ2860所需的庫可能與以太網Shield上使用的庫不同,只要且僅當以太網Shield上的芯片不是 ENCJ2860時。

根據問題中給出的信息無法確定這一點。 但是,這是我要看的第一件事。

PS:我目前正在為ENCJ2860整理庫,並且正在等待具有ENCJ2860的以太網屏蔽,因此我可以為您提供幫助,或者將您的庫發送給您(尚待調試!)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM