Software Serial in User made classes - IMPOSSIBLE

Alright guys, I’m at my wits end. I think this may be impossible. I am trying to use SoftwareSerial in my own library (DX160.h, DX160.cpp). I’ve come to the realization that this is impossible. Below, I’ve shorted the library files and the .pde file. First, the .h file, second the .cpp file, and third the .h file.

When I go to compile this, the following message appears:

DX160.cpp: In member function ‘void DX160::init(int)’:
DX160.cpp:13: error: insufficient contextual information to determine type
o: In function setup': undefined reference to DX160::init(int)’

my .pde file

#include <SoftwareSerial.h>
#include "DX160.h"


DX160 example;

void setup()
{
  example.init(57600);
}


void loop()
{
    //example.helloWorld();
  delay(3000);

}

DX160.cpp

#include "DX160.h"

#include "avr/interrupt.h"
#include <inttypes.h>
#include "SoftwareSerial.h"
//#include "WProgram.h"

void DX160::init(int baud)
{
      Com.begin(57600);
}

void DX160::helloWorld()
{
      for(int i=0;i<5;i++)
      {
      digitalWrite(13,HIGH);
      delay(1000);
      digitalWrite(13,LOW);
      delay(1000);
      }      
      //Com.print("x");
}

DX160.h

#include "WConstants.h"
#include "SoftwareSerial.h"

#ifndef DX160_h
#define DX160_h

class DX160
{
      public:
            void init(int baud);      
            void helloWorld();
            SoftwareSerial Com(uint8_t receivePin = 0, uint8_t transmitPin = 1);            
      private:            
};
#endif

Essentially, anytime I want to use the SoftwareSerial commands (in this case, Com.print or Com.begin), I get that error message mentioned above.

I know that I am defining things all over the place, feel free to tell me what I do and do not need.

Thanks

You need a bit of strange C++ syntax to do this.

In the header file, change:

SoftwareSerial Com(uint8_t receivePin = 0, uint8_t transmitPin = 1);

to:

SoftwareSerial Com;

And add a line (inside the public: section of the class):

DX160();

And in the .cpp file, add:

DX160::DX160() : Com(2, 3) {}

where 2 and 3 are the pins you want to use the SoftwareSerial on.

Hi, did you get software serial to work in you library? I’m also trying to use it in a library, both with mellis approach and by modifying the software serial constructor. It compiles fine but the mp3 player I’m trying to interface doesn’t respond to the serial communication, though the communication worked fine before I moved it to a library. I #include <SoftwareSerial.h> in my library as well as in my sketch (which seems to be necessary for it to be needed for the include path)…