Make one instance of SoftwareSerial available in deifferent libraries

Hello! I'm do not know well C++. But I need somehow to define SoftwareSerial instance so, that it will be visible to another libraries, like Serial (im using Nano board). I need it because I have created my own libraries, but classes in librarires must all use same SoftwareSerial definition to send/receive a data. I don't have any idea how to do it. Thank you Pavel

Pass a SoftwareSerial object into your library objects?

Better, do it as the Stream class, so you can pass anything that's inherited from Stream, like SoftwareSerial and HardwareSerial.

Thank you! But to be honest, I do not know how to do it with stream class. :frowning:
Can you please give some short example?
Thank you again.
Pavel

Pass the serial object to a function:

myClassObject.setSerialDevice(&mySoftwareSerialDevice);

which receives it and stores it:

// in def:
private:
  Stream *_dev;

// code:
void myClass::setSerialDevice(Stream *dev) {
  _dev = dev;
}

Then you use it somewhere.

_dev->println("This is printed");

You can call the function what you want, or combine it with an existing one (such as the constructor, or a begin() function).

Thank you very much!! Will try to implement this. ... and it works! XD Pavel