sparkfun / OpenLog

Open Source Hardware Datalogger
https://www.sparkfun.com/products/9530
Other
553 stars 216 forks source link

disk command OpenLog v 3.21 #158

Closed KMartinII closed 10 years ago

KMartinII commented 11 years ago

I have written a sketch that reads the file size of a given file (working) and the disk size using disk command to compare and perform a file cleanup. However after issuing the disk command (Serial1.println("disk");) what is returned simply stops at the 'c' in the word product. I have tried a number of different things to get to Card Size: but is doesn't appear to be sending.

Here is my code.

void MaintCheck(){ //get size of log file and size of disk and compare char filesize[50]; char disk[400]; char disksize[50]; unsigned long flsz; unsigned long dsksz; int i; char tok, a;

// Get File size of pumplog

Serial1.println("size PUMPLOG.TXT"); delay(200); i = 0; while(Serial1.available()){ filesize[i++] = (char) Serial1.read(); } Serial.println(""); Serial.println("Size of PUMPLOG.TXT is: "); //Serial.println(filesize); tok = strtok_r(filesize, "\n", &a); tok = strtok_r(NULL, "\n", &a); Serial.println("Token: "); Serial.println(tok); flsz = atol(tok); Serial.println(flsz);

// Get size of disk

i=0; Serial1.println("disk"); delay(300); while(Serial1.available()){ disk[i++] = (char) Serial1.read(); Serial.println(disk[i-1]); delay(300); }

Serial.println(disk); tok = strtok_r(disk, "\n", &a); Serial.println("Token: "); Serial.println(tok);

dsksz = atol(disksize); Serial.println(dsksz);

Serial1.flush();

if(flsz > (dsksz - 1000)) { Serial.println("Running Disk Maint. "); //DiskMaint(); } }

nseidle commented 11 years ago

I believe you are running into an issue because you are trying to print characters as you are reading them in. Try buffering (reading) 100 or so characters between Serial.print()s.

Here's some code I just wrote for the OpenLog_ReadExample:

//This will listen for characters coming from OpenLog and print them to the terminal
//This relies heavily on the SoftSerial buffer not overrunning. This will probably not work
//above 38400bps.
//This loop will stop listening after 1 second of no characters received
for(int timeOut = 0 ; timeOut < 1000 ; timeOut++) {
  while(OpenLog.available()) {
    char tempString[100];

    int spot = 0;
    while(OpenLog.available()) {
      tempString[spot++] = OpenLog.read();
      if(spot > 98) break;
    }
    tempString[spot] = '\0';
    Serial.write(tempString); //Take the string from OpenLog and push it to the Arduino terminal
    timeOut = 0;
  }

  delay(1);
}
ToniCorinne commented 10 years ago

Has this issue been resolved? Can we close it out?