Code to send 2 analog values over xbee

I am trying to send 2 different analog IN values over xbee. I found that the receiving side xbee will give an UART out for both the analogs by default. And that will of course be a serial out and will follow a pattern like ADC0 then ADC1 then ADC2 and so on. Does anyone have any code that I could use on the receiving end that will separate out the 2 different analog's value on the receiving side Arduino. I am using series 1 xbee. Any help would be greatly appreciated.

When the Serial.print function outputs a value, it converts the value to a string, and sends it one character at a time. If your 2 values are 27 and 456, the output will be:

27456

This makes it difficult to tell where one value ends, and another begins.

There are 2 solutions. The first is for you to convert the values to strings before Serial.print sends them, and make the strings all fixed length.

Then, the output would be:

27 456

You'd then read 4 bytes, and convert that back to a number, and read another 4 bytes, and convert that to a number.

The other possibility is to add a separator between the values, like this:

char token = ';';
Serial.print(token);
Serial.print(val1);
Serial.print(token);
Serial.print(val2);
Serial.print(token);

This way, the output would be:

;27;456;

Then, on the receiver, you look for the ; as the start and end of a string that represents a number.

The advantage of this method is that you know when your data starts (a ; showed up), and when it ends (another ; shows up). There is no question, then, about whether all the data was received.