Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 8 Replies) build errors with ethercard (Read 2219 times)
David450
Newbies
*
Offline


Posts: 6
Joined: Feb 21st, 2020
build errors with ethercard
Feb 21st, 2020 at 2:06pm
Print Post  
In the EtherCard example sketch udpListener I get build errors if I have these two lines at the top of the sketch:
Code
Select All
// #include <net.h>
int xyz = 1;
 



If I uncomment the first line there are no errors. I am trying to add udp to my own sketch. It has code before
Code
Select All
#include <EtherCard.h>
 


and I get the same errors.
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
David450
Newbies
*
Offline


Posts: 6
Joined: Feb 21st, 2020
Re: build errors with ethercard
Reply #1 - Feb 21st, 2020 at 2:30pm
Print Post  
I should also add it has something do with this line 
Code
Select All
void udpSerialPrint(uint16_t dest_port, uint8_t src_ip[IP_LEN], uint16_t src_port, const char *data, uint16_t len){
  IPAddress src(src_ip[0],src_ip[1],src_ip[2],src_ip[3]);

 


It can't find the value for IP_LEN. It is defined as 4 in net.h.
If I replace IP_LEN with 4 it also compiles without error. 
I have uninstalled Visual Micro and deleted all the files I could find for it, then reinstalled. It still has an error. 

If I open the file in the Arduino IDE it compiles without error.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: build errors with ethercard
Reply #2 - Feb 21st, 2020 at 2:39pm
Print Post  
The build output you posted shows a successful build. Are you reporting intellisense errors? Intellisense is different to build.


Code
Select All
Program udpListener size: 8,676 bytes (used 28% of a 30,720 byte maximum) (2.31 secs)
Minimum Memory Usage: 944 bytes (46% of a 2048 byte maximum) 

« Last Edit: Feb 21st, 2020 at 2:40pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
David450
Newbies
*
Offline


Posts: 6
Joined: Feb 21st, 2020
Re: build errors with ethercard
Reply #3 - Feb 21st, 2020 at 2:47pm
Print Post  
Here is the example sketch
Code
Select All
//#include <net.h>
int xyz = 1;



// 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>
//
// License: GPLv2

#include <EtherCard.h>
#include <IPAddress.h>

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

#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,0,200 };
// gateway ip address
static byte gwip[] = { 192,168,0,1 };
#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

//callback that prints received packets to the serial port
void udpSerialPrint(uint16_t dest_port, uint8_t src_ip[IP_LEN], uint16_t src_port, const char *data, uint16_t len){
  IPAddress src(src_ip[0],src_ip[1],src_ip[2],src_ip[3]);

  Serial.print("dest_port: ");
  Serial.println(dest_port);
  Serial.print("src_port: ");
  Serial.println(src_port);


  Serial.print("src_port: ");
  ether.printIp(src_ip);
  Serial.println("data: ");
  Serial.println(data);
}

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

  // Change 'SS' to your Slave Select pin, if you arn't using the default pin
  if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0)
    Serial.println(F("Failed to access Ethernet controller"));
#if STATIC
  ether.staticSetup(myip, gwip);
#else
  if (!ether.dhcpSetup())
    Serial.println(F("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, 1337);

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

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


/*
//Processing sketch to send test UDP packets.

import hypermedia.net.*;

 UDP udp;  // define the UDP object


 void setup() {
 udp = new UDP( this, 6000 );  // create a new datagram connection on port 6000
 //udp.log( true );     // <-- printout the connection activity
 udp.listen( true );           // and wait for incoming message
 }

 void draw()
 {
 }

 void keyPressed() {
 String ip       = "192.168.0.200";  // the remote IP address
 int port        = 1337;    // the destination port

 udp.send("Greetings via UDP!", ip, port );   // the message to send

 }

 void receive( byte[] data ) {       // <-- default handler
 //void receive( byte[] data, String ip, int port ) {  // <-- extended handler

 for(int i=0; i < data.length; i++)
 print(char(data[i]));
 println();
 }
*/

 



  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: build errors with ethercard
Reply #4 - Feb 21st, 2020 at 4:23pm
Print Post  
You have not answered my question. I confirmed your build output shows compile is okay so where are you seeing an error?
  
Back to top
WWW  
IP Logged
 
David450
Newbies
*
Offline


Posts: 6
Joined: Feb 21st, 2020
Re: build errors with ethercard
Reply #5 - Feb 21st, 2020 at 5:27pm
Print Post  
I included two build outputs. The first one is with the error. About 1/2 way down the file the second output starts and does build correctly, but only when the first line is uncommented. I will attached only the build output with the error.
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: build errors with ethercard
Reply #6 - Feb 21st, 2020 at 9:36pm
Print Post  
Ah sorry missed the first output was two combined.

Please email the udpListener.cpp from the following folder to the email address in yellow abve along with a link to this post.
C:/Users/CoxDa/AppData/Local/Temp/VMBuilds/udpListener/nano_atmega328/Release

Thanks
  
Back to top
WWW  
IP Logged
 
David450
Newbies
*
Offline


Posts: 6
Joined: Feb 21st, 2020
Re: build errors with ethercard
Reply #7 - Feb 22nd, 2020 at 1:13am
Print Post  
Ok, I have sent the email. As a work-around I will use the value 4 instead of IP_LEN.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: build errors with ethercard
Reply #8 - Feb 22nd, 2020 at 5:21pm
Print Post  
Thanks. Okay sorry I should have spotted something earlier. During compilation we have to automatically add any missing c++ prototypes. For example if you add a method called void test(){} we have to add the void test(); prototype if you have not already done that. This happens in the temp build folder, does not alter your own code.

We are about to release a version of visual micro that determines a better location in the .ino code where auto generated prototypes should be inserted. Currently missing prototypes are inserted before the 1st line of actual code.  The Arduino IDE has already moved to the new way of working but it's not 100% reliable (see note at end of this post). I think it is the one difference we have right now but easily solved.

In your case  you have added a line of code ( "int xyz = 1;") before you have #included the libraries you want to use, well at least before the Ethernet library is #included. A "type" from the Enter lib is used in a method signature, that required a prototype.

In your example the prototypes are added before int "xyz = 1;", therefore I have moved that line of code down so that the eter lib "#include" is before it. Then missing prototypes are added after the enter lib is available to the code.

Solution 1
Code
Select All
//#include <net.h>
// 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>
//
// License: GPLv2

#include <EtherCard.h>
#include <IPAddress.h>

int xyz = 1;

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

 



An alternative is to add the missing prototype(s) yourself. (Then the code will continue to work if you ever move it into .cpp files)

You can see below your code is unchanged except a prototype has been added after the enter lib has been included, because the method used a "type" from the lib.

Solution 2
Code
Select All
//#include <net.h>
int xyz = 1;



// 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>
//
// License: GPLv2

#include <EtherCard.h>
#include <IPAddress.h>

// adding c++ prototypes when types are available
//
void udpSerialPrint(uint16_t dest_port, uint8_t src_ip[IP_LEN], uint16_t src_port, const char *data, uint16_t len);


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

#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,0,200 };
// gateway ip address
static byte gwip[] = { 192,168,0,1 };
#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

//callback that prints received packets to the serial port
void udpSerialPrint(uint16_t dest_port, uint8_t src_ip[IP_LEN], uint16_t src_port, const char *data, uint16_t len){
  IPAddress src(src_ip[0],src_ip[1],src_ip[2],src_ip[3]);

  Serial.print("dest_port: ");
  Serial.println(dest_port);
  Serial.print("src_port: ");
  Serial.println(src_port);


  Serial.print("src_port: ");
  ether.printIp(src_ip);
  Serial.println("data: ");
  Serial.println(data);
}

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

  // Change 'SS' to your Slave Select pin, if you arn't using the default pin
  if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0)
    Serial.println(F("Failed to access Ethernet controller"));
#if STATIC
  ether.staticSetup(myip, gwip);
#else
  if (!ether.dhcpSetup())
    Serial.println(F("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, 1337);

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

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


/*
//Processing sketch to send test UDP packets.

import hypermedia.net.*;

 UDP udp;  // define the UDP object


 void setup() {
 udp = new UDP( this, 6000 );  // create a new datagram connection on port 6000
 //udp.log( true );     // <-- printout the connection activity
 udp.listen( true );           // and wait for incoming message
 }

 void draw()
 {
 }

 void keyPressed() {
 String ip       = "192.168.0.200";  // the remote IP address
 int port        = 1337;    // the destination port

 udp.send("Greetings via UDP!", ip, port );   // the message to send

 }

 void receive( byte[] data ) {       // <-- default handler
 //void receive( byte[] data, String ip, int port ) {  // <-- extended handler

 for(int i=0; i < data.length; i++)
 print(char(data[i]));
 println();
 }
*/

  



Final Important Note

The Arduino IDE (and shortly visual micro), includes prototypes before the first valid method in the code. This will still leave room for "types" from different #includes to be used in method signatures at the wrong time. This is more likely if  if the #includes in .ino code are added in an ad-hoc order.
« Last Edit: Feb 22nd, 2020 at 5:27pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
David450
Newbies
*
Offline


Posts: 6
Joined: Feb 21st, 2020
Re: build errors with ethercard
Reply #9 - Feb 22nd, 2020 at 7:02pm
Print Post  
If I understand this correctly, since I put the first line of actual code before the #include statements, not all prototypes were added. It only checks for prototypes the one time, not after every #include?

I should put all the #include statements at the start of the sketch so all required prototypes will be added.

Thanks for your help.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: build errors with ethercard
Reply #10 - Feb 25th, 2020 at 1:03pm
Print Post  
Yes that's right
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint