Pages: [1]   Go Down
Author Topic: ExtendedDatabaseLibrary in conjunction with the standard Arduino SD library  (Read 1514 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 4
Posts: 187
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to use this library ExtendedDatabaseLibrary in conjunction with the standard Arduino SD library. I explore function like readblock and writeblock in "SD2CARD.cpp" but still i am confuse how to use them.
I really appreciate your suggestions

The read and write handlers which i want to use for SDcard


Code:
// Uncomment the line appropriate for your platform
#define TABLE_SIZE 512 // Arduino 168 or greater

// The number of demo records that should be created.  This should be less
// than (TABLE_SIZE - sizeof(EDB_Header)) / sizeof(LogEvent).  If it is higher,
// operations will return EDB_OUT_OF_RANGE for all records outside the usable range.
#define RECORDS_TO_CREATE 10

// Arbitrary record definition for this table.  
// This should be modified to reflect your record needs.
struct LogEvent {
  int id;
  int temperature;
}
logEvent;

// The read and write handlers which i want to use for SDcard
void writer(unsigned long address, byte data)
{
  //EEPROM.write(address, data);
}

byte reader(unsigned long address)
{
  //return EEPROM.read(address);
}

// Create an EDB object with the appropriate write and read handlers
EDB db(&writer, &reader);

void setup()
{
  Serial.begin(9600);
  Serial.println("Extended Database Library + Arduino Internal EEPROM Demo");
  Serial.println();

  db.create(0, TABLE_SIZE, sizeof(logEvent));

  Serial.print("Record Count: "); Serial.println(db.count());

  Serial.println("Creating Records...");
  int recno;
  for (recno = 1; recno <= RECORDS_TO_CREATE; recno++)
  {
    logEvent.id = recno;
    logEvent.temperature = recno * 2;
    db.appendRec(EDB_REC logEvent);
  }

  Serial.print("Record Count: "); Serial.println(db.count());
  for (recno = 1; recno < RECORDS_TO_CREATE; recno++)
  {
    db.readRec(recno, EDB_REC logEvent);
    Serial.print("ID: "); Serial.println(logEvent.id);
    Serial.print("Temp: "); Serial.println(logEvent.temperature);  
  }
}

void loop()
{
}
Logged

From Idea To Invention

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13664
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

why not open a file for append and write to it?

With fseek() you can reposition the filepointer if you want to read back from the file
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Full Member
***
Karma: 4
Posts: 187
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
why not open a file for append and write to it?

With fseek() you can reposition the filepointer if you want to read back from the file

will you show me any example related to fseek()
because i did not find it in SD library Arduino 1.0

thankyou for your reply
Logged

From Idea To Invention

Offline Offline
Full Member
***
Karma: 4
Posts: 187
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thnx
i find a function which works like "fseek"
"seekSet()"
« Last Edit: November 13, 2012, 10:44:19 pm by Cybernetician » Logged

From Idea To Invention

Pages: [1]   Go Up
Jump to: