jremington:
Don't use that loop, write non-blocking code instead.
Yeah. That is the question.
UKHeliBob:
Why use a while loop ? Replace it with an if and let loop() do the looping for you.
It would help considerably if you posted a complete program rather than just a snippet
I'm working on how to post it. Code tags is so far out of the question it isn't even a question.
gcjr:
i wouldn't describe that code as blocking. it should read until there is nothing else to read (i.e. EOF end-of-file) and then continue (execute code following the loop).
blocking is waiting for an event that occurs at an unpredictable time (e.g. input from a keyboard)
Yes a bad description but the only one I had. it does in fact block the rest of the program from running which is predicated on ISR flagged subroutines.
Robin2:
You need to provide more information.
In what circumstances should the data be read from the SD Card and in what circumstances should the program be doing something different?
How does the data get to be on the SD Card?
What does "record the data on it's interval" mean?
...R
The data logger records the data to the SD card in one minute intervals.
I have been working to develop a DOS like structure (though those posts went completely unresponded, so I'm on my own) with a few basic commands (rename, del, type) to access the data on the SD card. Most of the commands are short or have a short response time (like rename and del). Type and transfer (created to initiate sending data to PLC-DAQ spreadsheet) will have longer response as they transfer the data. Data files are created daily and expected to be about 1M each. The snippet is reach after serial data command initiates it.
Block Pseudo Code
loop()
if Serial.Available() then receive_serial()
receive_serial() // called from loop()
...follow serial basics to receive data
If end marker received (char 10 or 13) then process_command()
process_command() // called from receive_serial()
if command = type then type_command()
if command = transfer then transfer _command()
type_command() // called from process_command()
file.open()
while ((n = rdfile.fgets(line, sizeof(line))) > 0)
{ Serial.print(line); }
file.close()
Once the command is received for type or transfer, the program is 'stuck' in the command subroutine until the transfer completes. The timer ISR may flag a one-minute interval for data logging, but that check is in loop() which is not accessible while the type or transfer commands are executing.