| 149 | } |
| 150 | |
| 151 | void readWriteTest() |
| 152 | { |
| 153 | //2. Open file, write a few bytes, close reopen and read |
| 154 | Serial.println(_F("2. Open file \"test.txt\" and write some data...")); |
| 155 | FIL file; |
| 156 | FRESULT fRes = f_open(&file, "test.txt", FA_WRITE | FA_CREATE_ALWAYS); |
| 157 | |
| 158 | if(fRes == FR_OK) { |
| 159 | //you can write directly |
| 160 | uint32_t actual = 0; |
| 161 | f_write(&file, "hello ", 5, &actual); |
| 162 | |
| 163 | //or using printf for convenience |
| 164 | f_printf(&file, _F(" has %d letters\r\n"), actual); |
| 165 | |
| 166 | if(actual != 5) { |
| 167 | Serial << _F("Only written ") << actual << _F(" bytes") << endl; |
| 168 | } |
| 169 | f_close(&file); |
| 170 | } else { |
| 171 | Serial << _F("fopen FAIL: ") << fRes << endl; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | void readTest() |
| 176 | { |