After 27 posts, you'll find you have better responses if you follow the guidelines found in the two posts by Nick Gammon at the top of this Forum. Posting the code the way you do is wrong and you're wasting a lot of pico acres in the process.
void receiveSysex() {
//F0 44 00 00 70 10 60 70 31 F7 request patch from CURRENT SOUND area
byte casioRe[]={0xF0, 0x44, 0x00, 0x00, 0x70, 0x10, 0x60 , 0x70, 0x31 , 0xF7} ;
Serial.write(casioRe, sizeof(casioRe)); //retrive the patch from CURRENT SOUND area
Serial.flush(); //flush all previous received and transmitted data
//--------------------------
byte midiByte;
int doit=0;
int index=0;
while(!Serial.available()) ; // hang program until a byte is received
// only if there are bytes in the serial buffer execute the following code
if (Serial.available()>0)
{
midiByte = Serial.read();
if (midiByte==0xF0)
{
data[0]=0xF0;
index++;
doit=1;
//keep reading and printing from serial untill there are bytes in the serial buffer
while (Serial.available()>0)
{
data[index] = Serial.read();
//Serial.print(data[index], BYTE); //prints the character just read
index++;
}
}
}
if (doit==1)
{ // save to file ....