Hi! Im buidling a library for interfacing with serial device. So far i have
program.c which includes device.h, now device.c is using a lot of calls to Serial1.write() and Serial.write() both "WProgram.h" and <Serial.h> are #included in device.c.
When i "verify" program.c i get an error saying: device.c: 'Serial' undeclared.. what other files do i need to include to build my program?
Hi,
you need one less.
It's enough to include "WProgram.h". This makes the Serial.whatever() functions available to your code. Remove the #include<Serial.h> statement and try again. (actually there is no "Serial.h" file the arduino-core, so this include will always fail)
Eberhard
I finally reduced the number of errors down to a bunch of errors of this type:
In function 'serial_buf_read':
error: 'Serial1' undeclared (first use in this function)
-i -basically have this:
dev.c (containing a bunch of functions implementing a device protocol using the Serial class)
dev.h (Defining some magic number and structers, also, function prototypes)
program.c (talks to the hardware using the dev-library)
Hi,
the static variables Serial1, Serial2 or Serial3 are only available when you comile the library/your sketch for an ArduinoMega.
This is not limited to libraries. Here is a short sketch
I think including WProgram first, as wayoda says, will resolve your errors.
[edit]As all of you can see [below] wayoda was too quick for me (quoted me before I saw my err.) , I replied to this thread before reading it from the top.
/me is guilty :-[[/edit]
@wayoda
Does it work like this:
Code: #include <gx.h>
void setup() {
readserial();
}
void loop() {
}
Why not? It's just a (public) function from a library.
Compiles for ArduinoMega, fails for an Arduino Nano. This is not an error! It is supposed to fail for a Nano, because it does not have a Serial1. (A more descriptive message would be a nice feature for future versions)
You could #include <HardwareSerial.h>
Don't do this. All the core functions are available to your library when "WProgram.h" is included. That's why someone named it the Core
Eberhard
Don't do this. All the core functions are available to your library when "WProgram.h" is included. That's why someone named it the Core
Eberhard
I disagree with you.
When writing a library I think it is much cleaner to explicitly show what you are using. It also takes less time to compile.
If one does not need all the core functions, there is no need to make them available either.
I disagree with you.
When writing a library I think it is much cleaner to explicitly show what you are using.
If its your 13'th lib, you may be right. Otherwise you will have a hard time finding and adding #include-statements for all of the functions provided by the core.
So I'll try again : [ch945][ch946]
You could #include <HardwareSerial.h>
Don't do this unless you have a good knowledge about the inner workings of the Core. All the core functions are available to your library when "WProgram.h" is included.
It also takes less time to compile.
No to this one.
All the files that belong to the core are compiled and linked with the code that gets uploaded, no matter if you use any of the functions the core provides.
But this is only academic : compile times don't really matter when writing software with the IDE.
@gliderboy
After this little dog-member shootout is over, did this get you anywhere?
Otherwise you should probably post the library-code.
Eberhard