If you just want to send the command once at startup, and then read the response you want to do this:
byte GetData[] = {0x02,0x12,0x00}
byte GetDataACK[] = {0x02,0x06,0x06,0x06,0x06,0x06};
void setup(){
Serial.begin(9600);
Serial.write(GetData,sizeof(GetData)); //Send the byte array
}
void loop(){
if(Serial.available() > 5) {
for(int i=0;i<6;i++){
if(GetDataACK[i]!=Serial.read()){
// Do something
}
}
}
}
Now I'm not sure what you're trying to accomplish with the inner if statement of loop, but it seems kind of backwards to me. Wouldn't you only want to "do something" after you have successfully read the data Ack? I think what you really want is a little state machine:
#define DATA_LENGTH 14 // or whatever the length of your data segment is
#define STATE_IDLE 0
#define STATE_SEND_COMMAND 1
#define STATE_WAITING_FOR_ACK 2
#define STATE_GET_DATA 3
byte GetData[] = {0x02,0x12,0x00}
byte GetDataACK[] = {0x02,0x06,0x06,0x06,0x06,0x06};
byte RxData[DATA_LENGTH] = {0};
byte state = STATE_SEND_COMMAND;
void setup(){
Serial.begin(9600);
state = STATE_SEND_COMMAND; // redundant
}
void loop(){
switch(state){
case STATE_IDLE: break;
case STATE_SEND_COMMAND:
Serial.write(GetData,sizeof(GetData)); //Send the byte array
state = STATE_WAITING_FOR_ACK;
break;
case STATE_WAITING_FOR_ACK:
if(Serial.available() > 5) {
for(int i=0;i<6;i++){
if(GetDataACK[i]!=Serial.read()){
// ACK doesn't match what you expect
// you should go to some other state at this point
// i'll just send you to idle
state = STATE_IDLE;
break;
}
}
}
break;
case STATE_GET_DATA:
if(Serial.available() > DATA_LENGTH) {
for(int i = 0; i < DATA_LENGTH; i++){
RxData[i] = Serial.read();
}
// congratulations you have data in your array
// presumably now you want to something with it
// and then switch back to some other state
// i'll send you back to IDLE :)
state = STATE_IDLE;
break;
}
}
}