Variable type of a variable that can be assigned "Serial" or "Serial1"


#1

I have a need to output things to Serial or Serial1 under different circumstances, so I need a

serial_t *ptrSeriaPort = &Serial;

Is there a type for this that applies to both USB and USART and acn communicate over either one??


#2

@JAndle,

It looks like they are two different object types: USARTSerial and USBSerial.
Maybe the Elites on the forum can suggest an elegant solution.
In the meantime, I think I found the correct files with the details:



#3

Would using Stream as common ancestor help?


#4

I will see if something like this works:

Stream* pDebug = &Serial, *pDevice = &Serial1;
pDebug->print();


#5

@JAndle, I confirm that the following works (using the Logging class) to set up the Logger to output either via Serial or USBSerial1

// Select debug output destination
// -------------------------------
Print *pStream;
if (bUseSerial1)
    pStream = &USBSerial1;
else
    pStream = &Serial;

auto logHandler1 = new StreamLogHandler(*pStream, LOG_LEVEL_WARN /* Default level */, filters);

logManager->addHandler(logHandler1);