SD-card read problem

Hello. I have a few month programing with XOD. I´m not c++ programer, but i have a general idea. I´m trying to make a node to read from a .txt file into de SD-card. I´v succes making a “file erase” node. But when i store information into the file with sd-log, then i read with the new node, it´s shows only one digit and it seems that it´s on hexadecimal format. I mean that into the file is the number 21 saved, but the node only reads the first digit “2”, and shows it like in byte format plus 30. For example: 32, but then output in decimal: 50. Simplyfing: i saved 2, but reads 32, and shows me 50. I post the code here. It´s based on the sd-log. The “while (myFile.available())” doesn´t work, so y hide from the code with dash //. I´v edited the node with a byte output that displays the 32 i mean. Also i linked the table of conversion by refference. Thanks alot.

#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_W
#pragma XOD error_raise enable

{{#global}}
#include <SPI.h>
#include <SD.h>
{{/global}}

struct State {
bool begun;
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
auto state = getState(ctx);
if (!isInputDirty<input_W>(ctx))
return;

if (!state->begun) {
    // First time use, initialize
    auto csPin = getValue<input_CS>(ctx);
    state->begun = SD.begin(csPin);
}
if (!state->begun) {
    raiseError(ctx);
    return;
}

char filename[16] = { 0 };
dump(getValue<input_FILE>(ctx), filename);
// re-open the file for reading:
File myFile = SD.open(filename, O_READ);
if (myFile) {
// while (myFile.available()){
emitValue<output_OUT>(ctx, myFile.read());
// }
} else {
state->begun = false;
raiseError(ctx); // Can’t open file
return;
}
// close the file:
myFile.close();
emitValue<output_DONE>(ctx, 1);

}

1 Like

My guess would be that your logging converts number to string. Reading the first byte returns the “letter” 2, which in ASCII is hex 32 or decimal 50. You will either need to change logging to write the number to SD (which could be done in many different formats) or read in the string and convert it to a number instead of just casting (the programming equivalent of assuming) it as a number.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.