reading data from robo claw motor controller

Hi everyone,

http://downloads.basicmicro.com/downloads/datasheets/motor_controller_robo_claw_B0099.pdf Using the roboclaw quadrature encoders, it is possible to read data from the controller about encoder position, direction, speed, ect.

But when the roboclaw transmits this data, its in a 6byte string, with 4bytes denoting the encoder value, 1byte a direction, and 1byte a check sum. If I'm reading all this data into the arduino, what is the easiest way to separate the data, i.e the first 4bytes, then 5th byte.

Received: [Value1.Byte3, Value1.Byte2, Value1.Byte1, Value1.Byte0, Value2, CRC]

If you use the generic read command example, all the data is truncated into a single int, but I need to separate it before assigning it like so. Any suggestions?

int incomingByte = 0; // for incoming serial data

void setup() { Serial.begin(9600); // opens serial port, sets data rate to 9600 bps }

void loop() {

// send data only when you receive data: if (Serial.available() > 0) { // read the incoming byte: incomingByte = Serial.read();

// say what you got: Serial.print("I received: "); Serial.println(incomingByte, DEC); } }

Store the 6 values in an array:

byte allData[6];

void setup()
{
   Serial.begin(9600);   // opens serial port, sets data rate to 9600 bps
}

void loop()
{
   // send data only when you receive data:
   if (Serial.available() >= 6) // Wait for all 6 bytes to be available
   {
      // read the incoming data:
      for(int i=0; i<6; i++)
      {
          allData[i] = Serial.read();
      }
     // Now, do what you need to do with the 6 bytes
   }
}