Arduino Uno and Mega, compatibility of ports

I have been using Uno for communicating with Xbee wifi through softwareserial.
I've been seeing a lot of data missing while receiving from a server. So I thought I would use the Mega for its extra hardware serial port.

Before using the hardware serial ports, I ran the code (with software serial) in the Mega and it works fine.

However, when I am trying to run the same code with hardware serial port(with just port name changed to Serial1 or Serial2), the part of the code where I try to set the Xbee through remote AT commands, are not working. I can see "OK" response coming from the xbee but the parameters are not getting set.

Am I missing something ? I am new in using Arduino, so I will appreciate any input.

Am I missing something ?

Code.
Info about the XBees - what model, how they are configured, how they are attached, etc.

Before using the hardware serial ports, I ran the code (with software serial) in the Mega and it works fine.

Using which pins? Not all pins on the Mega support pin change interrupts, which is the heart of SoftwareSerial.

This is Xbee wifi model.

I am trying to set up using the code given here : Internet Datalogging With Arduino and XBee WiFi - SparkFun Learn

However when using hardware serial, i changed the pin and the part of the code.

I used pin 10 and 11 for software serial. That worked fine. I am having trouble with the hardware serial communication

for example if i had my softwareserial as myserial, i replaced it with 'serial2'. Is there any other step one should follow when transferring the code.

for example if i had my softwareserial as myserial, i replaced it with 'serial2'. Is there any other step one should follow when transferring the code.

Posting the f**king code would be the first step. serial2 does NOT exist!

Replacing xB. with Serial2. should work.

I presume you actually spelled it Serial2 rather than serial2.

I don't know what xB.flush() does with SoftwareSerial but its purpose changed in hardware serial. What it does now is wait until all the data that is in the output buffer has been transmitted. It's generally not much use any more. Try commenting it out and see what happens.

...R

Thanks Robin, I will try that in the morning.

Ofcourse i used Serial2, error is not in the syntax. I just wanted to make sure thats how its supposed to be.