Decoding data sent as BINARY via RS232

I'm back asking for help please with another problem which is again causing me stress. I've been trying to understand how a stream of data which is presented in binary data format can be correctly deciphered.

The data is coming from an HRXL-MaxSonar-WR device and the manual explains it is presented as follows:

Pin 5-Serial Output: The MB7366 sensors have an RS232 data format (with 0V to Vcc levels) and the output is an ASCII capital “R”, followed by four ASCII character digits representing the range in millimeters, followed by a carriage return (ASCII 13).
The serial data format is 9600 baud, 8 data bits, no parity, with one stop bit (9600-8-N-1).
Because the data is presented in a binary data format, the serial output is most accurate.

I've cobbled together the following sketch to see what is coming out of the sensor:

byte Bite;

void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  Serial1.begin(9600, SERIAL_8N1);
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    Bite = Serial1.read();
    Serial.print("Decimal \t:"); Serial.println(Bite, DEC);
    Serial.print("HEX \t:");     Serial.println(Bite, HEX);
    Serial.print("Bin \t:");     Serial.println(Bite, BIN);
    Serial.print("Ascii \t:");   Serial.write(Bite);
    Serial.println();
    Serial.println("\n------------------\n");

    if (Bite == 'R') Serial.println("Match");
    delay(1000); // delay to check ouput
  }
}

I've included the output below; the data stream repeats a set of 6 characters but although the received start and end characters are consistent they are not what is expected. The start-of-data character should be a capital R

Am I missing a fundamental point somewhere?

Dec 	:43
HEX 	:2B
Bin 	:101011
Ascii 	:+

------------------

Dec 	:99
HEX 	:63
Bin 	:1100011
Ascii 	:c

------------------

Dec 	:99
HEX 	:63
Bin 	:1100011
Ascii 	:c

------------------

Dec 	:99
HEX 	:63
Bin 	:1100011
Ascii 	:c

------------------

Dec 	:99
HEX 	:63
Bin 	:1100011
Ascii 	:c

------------------

Dec 	:121
HEX 	:79
Bin 	:1111001
Ascii 	:y

------------------

Dec 	:43
HEX 	:2B
Bin 	:101011
Ascii 	:+

------------------

Dec 	:99
HEX 	:63
Bin 	:1100011
Ascii 	:c

------------------

Dec 	:99
HEX 	:63
Bin 	:1100011
Ascii 	:c

------------------

Dec 	:99
HEX 	:63
Bin 	:1100011
Ascii 	:c

------------------

Dec 	:99
HEX 	:63
Bin 	:1100011
Ascii 	:c

------------------

Dec 	:121
HEX 	:79
Bin 	:1111001
Ascii 	:y

------------------

The data is coming from an HRXL-MaxSonar-WR device

Specifically, which one?

Pin 5-Serial Output: The MB736X sensors have an RS232 data format (with 0V to Vcc levels) and the MB738X sensors have a TTL outputs. The output is an ASCII capital “R”, followed by four ASCII character digits representing the range in millimeters, followed by a carriage return (ASCII 13). The maximum range reported is 4999 mm (5-meter models) or 9998 mm (10-meter models). A range value of 5000 or 9999 corresponds to no target being detected in the field of view.
The serial data format is 9600 baud, 8 data bits, no parity, with one stop bit (9600-8-N-1).
Because the data is presented in a binary data format, the serial output is most accurate .

It's an HRXL-MaxSonar-WR RS232 Maxbotix MB7366 model

Cheers

I've just re-run my programme again and now I am getting inconsistent results, not a repeating sequence as before.

What is coming out of the sensor would not seem to match what you say should be coming out of the sensor.

Has it got RS232 or TTL output ?

@Roddy, you're overthinking it. The device sends an ASCII string, like this: "R0123" which would signify a range of 123 millimeters. The business about binary is a red herring. Stop trying to decode the ASCII into binary. The data is in decimal ASCII.

aarg:
@Roddy, you're overthinking it. The device sends an ASCII string, like this: "R0123" which would signify a range of 123 millimeters. The business about binary is a red herring. Stop trying to decode the ASCII into binary. The data is in decimal ASCII.

But, it does not appear to actually send data in that format.

@UKHeliBoB - it's an RS232 device and I think you have just hit the nail on the head (red face)

I've attached its TX line to RX Serial1 of the Mega with Gnd to Gnd and Vcc to 3.3v (only 3 wires are required). Do I need an adapter between the two devices? (red face again!)

@aarg - Thanks arg, that does make complete sense and once I've sorted out my comms I'll let you know how I go on.

@PaulS - that's correct, what is coming out is not what is expected but I think it's all my fault connecting the RS232 output directly to the Mega RX pin.

Is my assumption correct? If I have answered my own question my apologies if I have wasted anyone's time.

Try putting a MAX232 chip between the Arduino and the device. If the output from the MAX232 chip looks better, then, yes, you have answered your own question.

If you don't have a MX232 handy, then you can cheat by wiring the RS232 backwards. You must have totally independent power supplies, like one should be on battery, which is not connected to anything else.

Connect GND on the sensor to RX and its transmit line to GND on the Arduino. If that works, then it means you do have a strange RS232 and you need the MAX232 chip.

HOWEVER, that is unlikely, given that 0 to Vcc spec. It is more likely that you have the wrong baud rate.