Pages: [1]   Go Down
Author Topic: Problem reading written Data  (Read 562 times)
0 Members and 1 Guest are viewing this topic.
Germany
Offline Offline
Jr. Member
**
Karma: 1
Posts: 98
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hallo everyone,

i just got my Ethernetshield and i`m trying to store some Data in an MicroSD card and read it back.

My Writing function is:
Code:
createFile("VERSION.NUM", "Versionsnummer")

void createFile(char* dateiname , String dateiinhalt) {
  int bytewritten = 0;
  // Erstellt eine Datei mit dem übergebenem Inhalt
   myFile = SD.open(dateiname , FILE_WRITE);
   bytewritten = myFile.print(dateiinhalt);
   myFile.close();
}

The file is created on the card. now i try to read the just written data back

Code:
readfromFile("VERSION.NUM");

void readfromFile(char* dateiname) {
  String incommingData = "";
  myFile = SD.open(dateiname , FILE_READ);
  while (myFile.available()) {
      Serial.println(myFile.read());
  }
  myFile.close();
}

In the Serial Monotor i get: 86
101
114
115
105
111
110
115
110
117
109
109
101
114

I guess these are the bytes wich were read, but how do i get a "humanreadable" String of this to use the stored data in the programm?

CL
« Last Edit: June 11, 2012, 06:52:38 am by Chaos_Lord » Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 148
Posts: 6105
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this instead:
Code:
  while (myFile.available()) {
      Serial.write(myFile.read());
  }

Serial.println() converts the integer return to a number. Serial.write() does not.
Logged

Germany
Offline Offline
Jr. Member
**
Karma: 1
Posts: 98
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah ok thank you,

but now i got another Problem. After the Data is now correctly shown on the screen i want to get it into some form, that i can use in the programm. Trying to make a string leaves an if Check going false? An Idea?
Logged

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

Quote
Trying to make a string leaves an if Check going false? An Idea?
I don't understand this statement. I don't see any attempt at codding this, either, though.
Logged

Germany
Offline Offline
Jr. Member
**
Karma: 1
Posts: 98
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone

got the problem solved, i need to use an internal buffer to read from the file and put this buffer together to a char so i can use it...

Tnx for the help here smiley-grin

Logged

Pages: [1]   Go Up
Jump to: