Is there such a thing as a null Serial port?

I have been working on a file transfer system whereby a file (a jpg image) is received via LoRa from a remote transmitter.

The file is loaded into a memory array or onto an SD card on the receiver Arduino and can then be transferred via YModem protocol to a PC over the Arduinos programming port. This is working and reliable.

It is useful (sometimes) to be able to see debug or monitoring messages sent to another of the Arduinos serial ports (hardware or software serial) to an attached USB adapter and then viewed on a PC with for example Tera Term.

Its easy enough to setup the transfer program to do these Serial prints to a pre-defined serial port thus;

#define MonitorPort Serial2

MonitorPort.println(F("Send end array write"));

This way you can change the actual serial port so where the monitoring messages go by changing the '#define MonitorPort Serial2' line.

But what if you dont want to send these monitor messages at all ?

You could do this;

#define MonitorPort Serial2

#ifdef MonitorPort
MonitorPort.println(F("Send end array write"));
#endif

Every time there is a Monitor message to print, but is there another way ?

Can you for instance define the MonitorPort such that there is no Serial output or pin use anywhere, a null serial port of some type ?

Why don't you define a preprocessor macro with an argument?

#define Monitor(call) Serial2.call
// or do deactivate
#define Monitor(call)

// usage
Monitor(println(F("Send end array write")));

Cheers, that does work, and the code is definetly less cluttered;

#define Monitor(call) Serial2.call
// or do deactivate
//#define Monitor(call)

// usage

void loop()
{
Monitor(println(F("Send end array write")));
delay(2000);
}

void setup()
{
Monitor(begin(115200));  
}