Wait for serial response 'OK' after each line in while loop

Long time voyeur, first time poster...

I can usually find my solution by bumping my head into the wall a few time, but this time I'm stumped. I'm trying to send this Serial.write command in a while loop, but I can't figure out how to wait for a response after each line is sent. This is complete dump of data here:

// copy file to serial port
int16_t n;
uint8_t buf[7];// nothing special about 7, just a lucky number.
while ((n = myFile.read(buf, sizeof(buf))) > 0) {
for (uint8_t i = 0; i < n; i++) Serial.write(buf*) ;*

  • }*
    My goal is to wait for a response of 'ok' after each line in order to send the next one until they have all been sent.
    Any help is greatly appreciated!

Thank you!

Much better design would be to put the read and write into two separate functions and use a variable to keep track of whether a reply is received. Something like this pseudo code

void loop() {
  receiveStuff();
  sendStuff();
}

void receiveStuff() {
   // code for receiving
   if (all the stuff is received) {
      receivedOK = true;
   }
}

void sendStuff() {
   if (receivedOK == true) {
        receivedOK = false;
        // code to send stuff
   }
}

...R

What happens if the device responds "KO", instead? If you block waiting for "OK", you'll be resetting the Arduino a lot.