Pages: [1]   Go Down
Author Topic: SDFat / openNext does not return all the directory entries within Webduino  (Read 1757 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The openNext example on its own returns all the 13 file names in my root directory, however when I place the identical code within a webduino web page it only returns 8, I deleted a few files down to 6 and again openNext on its own works fine, but this time in webduino it only returns 3, it seems the same files are missing in both cases.
Any idea why this is happening?
Is there another way of getting the file names from a directory with SDFat to workaround this?
Thanks in anticipation
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 640
Posts: 50335
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
however when I place the identical code within a webduino web page it only returns 8, I deleted a few files down to 6 and again openNext on its own works fine, but this time in webduino it only returns 3, it seems the same files are missing in both cases.
Be nice to see some code. I'm wondering if the code is REALLY identical.

Be nice to know WHICH files do not show up, and which do. Perhaps there is something about the file/name that causes the issue.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for looking at this, code in the webduino handler is cut and pasted from the example with a change to variable names viz;

Code:


if (!sd.init(SPI_FULL_SPEED, chipSelect)) fatalError("SD init error");
...

while (myFile.openNext(sd.vwd(), O_READ)) {
    myFile.getFilename(name);
    cout << name << endl;
    myFile.close();
  }

...

Files are all YYYYMMDD.LOG or ALPARMS.TXT, some of the .LOG files are missing as is ALPARMS.TXT and I'm using the latest SDFAT code (Sept 2nd 2011).

I worked around it with the following which works fine;

Code:

...
   if (!card.init(SPI_FULL_SPEED, chipSelect)) fatalError("SD init error");
   if (!volume.init(&card)) fatalError("vol.init failed!");
   if (!root.openRoot(&volume)) fatalError("openRoot failed");
...

  while (root.readDir(p) >0) {       
    if (p.name[0] == DIR_NAME_FREE) break; 
    if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.') continue;     
    if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue; 
    nameS = "";
    for (uint8_t i = 0; i < 11; i++) {
      if (p.name[i] == ' ') continue;
      if (i == 8) {
        nameS += '.';
      }
      nameS += String(p.name[i]);
    }   
    Serial.print(nameS);
...
 
  }

This is part of a very large sketch (1,381 lines) so difficult to produce a minimum reproducible case, its probably not worth spending much time getting to the bottom of this unless others have similar problems.
Logged

0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1656
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there a reason why you didn't use ls() like this?
Code:
  sd.ls();

Try putting a rewind before the loop like this.
Code:
  sd.vwd()->rewind();
  while (myFile.openNext(sd.vwd(), O_READ)) {
    myFile.getFilename(name);
    cout << name << endl;
    myFile.close();
  }
This is needed if there are any file operations before the loop.

If there are file operations on a directory between openNext calls, you need to restore the position of the directory like this:
Code:
  uint32_t pos = 0;
  while (1) {
    sd.vwd()->seekSet(pos);
    if (!file.openNext(sd.vwd(), O_READ)) break;
    pos = sd.vwd()->curPosition();
   ...
   // position of vwd() is changed by some operation
   ...
    file.getFilename(name);
    cout << name << endl;
    file.close();
  }
  cout << "Done" << endl;
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The rewind fixed it - thanks
Logged

Pages: [1]   Go Up
Jump to: