How do I alias/instantiate the Serial class?

I'm trying to connect an RN-XV wifi module to a duemilenove. I'm finding the software serial interface to be a bit unstable for anything over 9600. I want to use the UART interface in normal operation but without rewriting all of my code. The best solution might be to use an alias, but you can't instantiate/alias the Serial class the way you can SoftwareSerial. I'm a hardware guy :confused:

How can I do something like the following?

#ifdef DEBUG
  #include <SoftwareSerial.h>
  SoftwareSerial wifiSerial(8,9); 
  Serial debugSerial;
#else
  Serial wifiSerial;
#endif

void setup()
{
  
#ifdef DEBUG    
    char buf[32];

    debugSerial.begin(57600);
    debugSerial.println("Starting");
    debugSerial.print("Free memory: ");
    debugSerial.println(wifly.getFreeMemory(),DEC);
etc...

but you can't instantiate/alias the Serial class the way you can SoftwareSerial.

Of course not. Because it has already been done for you (Serial is the only instance of HardwareSerial on the 328-based Arduino. Serial, Serial1, Serial2 and Serial3 are the instances on HardwareSerial on the Mega).

You can but you have to use the #define statement:

#ifdef DEBUG
  SoftwareSerial softSerial(8,9);
  #define wifiSerial softSerial
  #define debugSerial Serial
#else
  #define wifiSerial Serial
#endif

You can declare a reference to an existing instance of a serial port. I do this occasionally to make my Mega projects at least somewhat functionally on regular Arduinos.

#if defined(__AVR_ATmega2560__)
//Serial1 on Mega2560 communicates through Xbee at 57600
HardwareSerial& cmdPort = Serial1;
#else
HardwareSerial& cmdPort = Serial;
#endif

daemach:
you can't instantiate/alias the Serial class the way you can SoftwareSerial. I'm a hardware guy :confused:

That's right - your sketch can't instantiate hardware.

There is a predefined Serial object corresponding to the physical serial UART. If you want to do serial output on different pins, you have to do it in software (you can't use the hardware driver) and you can do that using the SoftwareSerial class. You can't use the hardware serial driver to manipulate pins that are not connected to the serial UART, that makes no sense.

I think both Serial and SoftwareSerial derive from Print so you can use a Print * to store a pointer to either.