I am trying to use the NewSoftSerial Class inside of a Class that I created called Device but I am getting the following error when I try to compile the code:
In file included from Device.cpp:3:
/Device.h:10: error: expected identifier before numeric constant
/Device.h:10: error: expected ',' or '...' before numeric constant
In file included from hardware\libraries\Device/Portal.h:10,
My class definition is:
#include <NewSoftSerial.h>
class Device
{
private:
int _id;
char _name[30];
public:
class NewSoftSerial;
NewSoftSerial Xbee(8,9); // line 10
};
why do you have class NewSoftSerial; inside public. As far as I understand, this would mean that you're trying to create a new class object named NewSoftSerial.
You don't need that line. Modified code below:
#include <NewSoftSerial.h>
class Device
{
private:
int _id;
char _name[30];
public:
//class NewSoftSerial;
NewSoftSerial Xbee(8,9); // line 10
};
I tried this fix but still got the following error:
#include <NewSoftSerial.h>
class Device
{
private:
int _id;
char _name[30];
public:
//class NewSoftSerial;
NewSoftSerial Xbee(8,9); // line 10
};
In file included from Device.cpp:3:
/Device.h:10: error: expected identifier before numeric constant
/Device.h:10: error: expected ',' or '...' before numeric constant
I am trying to use the NewSoftSerial function inside of a class I created called Device but I am unsure how to get it to work. For example where do I put the " #include <NewSoftSerial.h>" in my Device class or in the main code? Where do I declare "NewSoftSerial Xbee(8,9);" in my Device class or in the main body of the code..not sure...please help?
RB
The only constructor NewSoftSerial provides take two arguments. If you want to embed an instance of a NewSoftSerial object in your class, you must initialize it with two arguments in the constructor like this:
Awesome!!!! IT works like a charm!!
One more Question??? Does NewSoftSerial use the same buffer that the Arduino Rx and Tx pins 0 & 1 use?? Can Arduino Rx and Tx operate and the same time as NewSoftSerial Rx and Tx pins???
NewSoftSerial's buffer is not the same one used by the "hardware" serial port that is connected to pins 0 and 1, so it is perfectly ok to use Serial and NewSoftSerial in the same application. Indeed, that is the most common use for NewSoftSerial -- to provide serial transmission when the "hardware" serial port is already occupied.