• This project uses two files on the SD card to layout CSV file format for data logging and read analog inputs in engineering units.
    Mylog.cfg
    Mycalibrations.cal
    The following link lays out the object used to calibrate the analog inputs into engineering units. It was used to create the file “Mycalibrations.cal” on the SD card.
    http://forum.espruino.com/conversations/­286215/

    The following code was used to create the log configuration file:
    SaveLog.js

    var LogObj1={
      Fname:"xxx.csv",
      Interval:1000, //milliseconds between samples
      items:[
        // header is text at top of column in csv file
        // cmd source for data in each column
        // can be in a different order
        // and have more or fewer items
        {header:"N",cmd:"count"},
        {header:"Date",cmd:"DMY",Args:["-","-"]}­,
        {header:"Time",cmd:"HMS",Args:[":",":"]}­,
        {header:"A0",cmd:"AR",Args:["A0",2]},
        {header:"A0",cmd:"SAR",Args:["A0",2]},
        {header:"Board Temp C",cmd:"BTC",Args:[2]},
        {header:"Board Temp F",cmd:"BTF",Args:[2]}
      ],
    
      count:0, // Number of lines logged
      N:10 // stop logging after count>N
    }; //end LogObj1
    
    
    function saveObject(myobject) {
      var Q;
      var sss=JSON.stringify(myobject);
     if (Q===undefined) {
      Q = E.openFile("Mylog.cfg", "w");
      Q.write(sss);
      Q.close();
      Q = undefined;
     }//endif
    }//end doLog
    
    saveObject(LogObj1); 
    var a=require("fs").readFileSync("Mylog.cfg"­);
    console.log(a);
    console.log(' ');
    
    

    The left screen when the log configuration file is created:

    >echo(0);
    {"Fname":"xxx.csv","Interval":1000,"item­s":[{"header":"N","cmd":"count"},{"heade­r":"Date","cmd":"DMY","Args":["-","-"]},­{"header":"Time","cmd":"HMS","Args":[":"­,":"]},{"header":"A0","cmd":"AR","Args":­["A0",2]},{"header":"A0","cmd":"SAR","Ar­gs":["A0",2]},{"header":"Board Temp C","cmd":"BTC","Args":[2]},{"header":"Bo­ard Temp F","cmd":"BTF","Args":[2]}],"count":0,"N­":10}
     
    =undefined
    >
    
    

    The logging program. The test portion opens the calibration file and the configuration file and creates a calibration object and two instances of the configuration. The layout is identical (could be different) except that the filename to write, and logging interval in one is 1 second and the other is 3 seconds.
    LogCSV3.js
    The console output when the program executes:

    >echo(0);
    N,Date,Time,A0,Inlet psig,Board Temp C,Board Temp F
    N,Date,Time,A0,Inlet psig,Board Temp C,Board Temp F
    =undefined
    1,4-4-2016,21:27:21,0.79,79.96,34.43,94.­32
    2,4-4-2016,21:27:22,0.79,79.96,34.62,93.­93
    3,4-4-2016,21:27:23,0.79,80.06,34.46,93.­93
    1,4-4-2016,21:27:23,0.79,79.98,34.84,93.­93
    4,4-4-2016,21:27:24,0.79,79.96,34.40,94.­26
    5,4-4-2016,21:27:25,0.79,79.96,34.25,94.­32
    6,4-4-2016,21:27:26,0.79,80.01,34.62,93.­93
    2,4-4-2016,21:27:26,0.79,79.96,34.46,93.­93
    7,4-4-2016,21:27:27,0.79,79.98,34.62,93.­59
    8,4-4-2016,21:27:28,0.79,79.98,34.22,93.­93
    9,4-4-2016,21:27:29,0.79,79.96,34.62,94.­26
    3,4-4-2016,21:27:29,0.79,79.98,34.59,93.­93
    10,4-4-2016,21:27:30,0.79,80.01,34.62,93­.98
    4,4-4-2016,21:27:32,0.79,80.01,34.25,93.­93
    5,4-4-2016,21:27:35,0.79,80.03,34.84,93.­54
    6,4-4-2016,21:27:38,0.79,79.98,35.02,94.­26
    7,4-4-2016,21:27:41,0.79,80.01,35.24,94.­26
    8,4-4-2016,21:27:44,0.79,80.06,34.40,93.­93
    9,4-4-2016,21:27:47,0.79,79.98,34.62,94.­32
    10,4-4-2016,21:27:50,0.79,79.96,34.25,94­.26
    >
    
    

    The CSV files created are: xxx.csv and xx1.csv


    6 Attachments

About