Quried I/O samples using arduino

I want get queried I/O samples from remote Xbee by giving remote AT commands from coordinate xbee.I want to know the status of LED which is connected on DIO4.I am using following code:
int val;
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.write(0x7E);
Serial.write((byte)0x0);
Serial.write(0x0F);
Serial.write(0x17);

Serial.write((byte)0x01);
Serial.write((byte)0x0);
Serial.write((byte)0x13);
Serial.write((byte)0xA2);
Serial.write((byte)0x0);
Serial.write((byte)0x40);
Serial.write((byte)0xA9);
Serial.write((byte)0xD0);
Serial.write((byte)0x84);
Serial.write(0xFF);
Serial.write(0xFE);
Serial.write(0x0);
Serial.write(ā€˜Iā€™);
Serial.write(ā€˜Sā€™);
Serial.write(0x5C);//checksum

delay(500);
if(Serial.available()>=21){
if(Serial.read() == 0x7E){
for(int i = 0;i<23;i++){
byte not_useful = Serial.read();
}
val=Serial.read();

    if(val==0){
     Serial.println("LED is OFF");
    }
    else if(val==16){
      Serial.println("LED is ON");
    }
    
  }

}
}

//First I am requesting a sample using IS command.Then when I receive its response I am interpreting the response frame to get desired output displayed on the arduino serial monitor.The code is not working.PLZ help

have you tried just sending the API frame from the terminal tab of XCTU to verify that the frame is valid?