Dear all ...
I´ve got a problem working with several local files at the same time. I´m trying to open a file for reading and another for writting. Basically, the first one includes different constants and the other stores the measured data. The code is the following ...
- include "mbed.h"
LocalFileSystem local("local");
float mean_S1, mean_S2, mean_S3;
float L_S1, L_S2, L_S3;
float V_micro, alfa_S1, beta_S1, alfa_S2, beta_S2, alfa_S3, beta_S3;
int i;
/*-------------*/
/*---- M A I N P R O G R A M ----*/
/*-------------*/
int main() {
FILE *fp_2 = fopen("/local/Calib.txt", "a");
fscanf(fp_2, "%f %f %f %f %f %f %f", V_micro, alfa_S1, beta_S1, alfa_S2, beta_S2, alfa_S3, beta_S3);
fclose(fp_2);
FILE *fp = fopen("/local/Results.txt", "a");
fprintf(fp, "Sensor 1 Sensor 2 Sensor 3\n");
fclose(fp);
while(1) {
mean_S1 = 0;
mean_S2 = 0;
mean_S3 = 0;
i = 0;
for(i=0; i<1000; i++){
mean_S1 = mean_S1 + V_micro;
mean_S2 = mean_S2 + V_micro;
mean_S3 = mean_S3 + V_micro;
}
mean_S1 = mean_S1/i;
mean_S2 = mean_S2/i;
mean_S3 = mean_S3/i;
L_S1 = mean_S1*alfa_S1+beta_S1;
L_S2 = mean_S2*alfa_S2+beta_S2;
L_S3 = mean_S3*alfa_S3+beta_S3;
FILE *fp = fopen("/local/Results.txt", "a");
fprintf(fp, "\n%f %f %f", L_S1, L_S2, L_S3);
fclose(fp);
}
}
Previously, I´ve created both files "Results.txt" and "Calib.txt". The problem is very easy ... no data is taken from the Calib file and the "Results" equals zero. Does anyone know why the constant are not loaded?
Thanks in advance.
Dear all ...
I´ve got a problem working with several local files at the same time. I´m trying to open a file for reading and another for writting. Basically, the first one includes different constants and the other stores the measured data. The code is the following ...
LocalFileSystem local("local");
float mean_S1, mean_S2, mean_S3; float L_S1, L_S2, L_S3; float V_micro, alfa_S1, beta_S1, alfa_S2, beta_S2, alfa_S3, beta_S3; int i;
/*
-------------*/ /*----M A I N P R O G R A M----*/ /*-------------*/int main() {
FILE *fp_2 = fopen("/local/Calib.txt", "a"); fscanf(fp_2, "%f %f %f %f %f %f %f", V_micro, alfa_S1, beta_S1, alfa_S2, beta_S2, alfa_S3, beta_S3); fclose(fp_2);
FILE *fp = fopen("/local/Results.txt", "a"); fprintf(fp, "Sensor 1 Sensor 2 Sensor 3\n"); fclose(fp);
while(1) {
mean_S1 = 0; mean_S2 = 0; mean_S3 = 0; i = 0;
for(i=0; i<1000; i++){ mean_S1 = mean_S1 + V_micro; mean_S2 = mean_S2 + V_micro; mean_S3 = mean_S3 + V_micro; }
mean_S1 = mean_S1/i; mean_S2 = mean_S2/i; mean_S3 = mean_S3/i;
L_S1 = mean_S1*alfa_S1+beta_S1; L_S2 = mean_S2*alfa_S2+beta_S2; L_S3 = mean_S3*alfa_S3+beta_S3;
FILE *fp = fopen("/local/Results.txt", "a"); fprintf(fp, "\n%f %f %f", L_S1, L_S2, L_S3); fclose(fp); } }
Previously, I´ve created both files "Results.txt" and "Calib.txt". The problem is very easy ... no data is taken from the Calib file and the "Results" equals zero. Does anyone know why the constant are not loaded?
Thanks in advance.