User Log File Being Deleted

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by pspeirs, Sep 20, 2018.

  1. pspeirs

    pspeirs

    Joined:
    Nov 23, 2013
    Messages:
    185
    Likes Received:
    10
    Location:
    Sydney
    Hi All,
    I am writing out the energy values once an hour to a CSV file and downloading it as required via a "Refresh Unit to Project" operation. This CSV file lives in the PROJECT folder and during the dev phase I am downloading mostly on the hour after each "Send Project to Unit" to see the changes. What I've noticed the next morning in a lot of instances is that the data prior to the last refresh has disappeared and new data from that point only is available.

    What exactly is able to remove this file?

    The refresh to project should copy all the relevant data down to the project folder, which it does, and then the send data from project to unit once any changes are done should send that same file to the unit with data intact.

    The log below as created during the run at 21:59 rather than just appending to what was there already.

    DateTime,Date,Time,Total (kWh),PhaseA (kWh),PhaseB (kWh),PhaseC (kWh),Test Time
    20/09/2018 21:00:00,20/09/2018,21:00:00, 2.46078100586E+0003, 7.82808593750E+0002, 9.18520812988E+0002, 7.59451477051E+0002, 79141
    20/09/2018 22:00:00,20/09/2018,22:00:00, 3.26243164063E+0003, 9.03330444336E+0002, 1.28092504883E+0003, 1.07817639160E+0003,10:59:01 PM
    20/09/2018 23:00:00,20/09/2018,23:00:00, 3.99415527344E+0003, 1.09194934082E+0003, 1.41850915527E+0003, 1.48369677734E+0003,11:59:01 PM
    21/09/2018 0:00:00,21/09/2018, 0:00:00, 6.78724426270E+0002, 1.74798965454E+0002, 3.96676940918E+0002, 1.07248527526E+0002,12:59:01 AM
    21/09/2018 1:00:00,21/09/2018, 1:00:00, 5.74991882324E+0002, 1.66436965942E+0002, 3.54570556641E+0002, 5.39843597412E+0001,1:59:01 AM
    21/09/2018 2:00:00,21/09/2018, 2:00:00, 5.74750183105E+0002, 1.43288589478E+0002, 3.78044708252E+0002, 5.34168624878E+0001,2:59:01 AM
    21/09/2018 3:00:00,21/09/2018, 3:00:00, 6.22904785156E+0002, 2.02589141846E+0002, 3.66009155273E+0002, 5.43064994812E+0001,3:59:01 AM
    21/09/2018 4:00:00,21/09/2018, 4:00:00, 6.25731140137E+0002, 2.10184692383E+0002, 3.60230285645E+0002, 5.53161659241E+0001,4:59:01 AM
    21/09/2018 5:00:00,21/09/2018, 5:00:00, 7.67389526367E+0002, 3.50173370361E+0002, 3.60861938477E+0002, 5.63542213440E+0001,5:59:01 AM


    For completeness, the function I'm using is below and the log file covering this period is attached . . .

    Code:
    procedure Energy_SaveCSV;
    begin
    
      //TimeToString(time, tmpstr);
    
      sTime := '';
      if (Hour < 10) then
        sTime := '0';
     
      format(sTime, Hour:2, ':00:00');
      writeln(sTime);
        
      DateToString(Date, sDate);
    
      if FileExists(fn_EnergyUsage) then
      begin
        AssignFile(file2, fn_EnergyUsage);
        AppendFile(file2);
    
        PrevHourTotal := GetRealIBSystemIO("Power Meter Total Energy", 0, 1, 0, 0, 0, -1);
        PrevHourPhaseA := GetRealIBSystemIO("Measurement App Energy Value", 254, 1, 1, 0, 1, 0, 0, 0);
        PrevHourPhaseB := GetRealIBSystemIO("Measurement App Energy Value", 254, 1, 2, 0, 1, 0, 0, 0);
        PrevHourPhaseC := GetRealIBSystemIO("Measurement App Energy Value", 254, 1, 3, 0, 1, 0, 0, 0);
        WriteLn(file2, sDate, ' ', sTime, ',', sDate, ',', sTime, ',', PrevHourTotal, ',', PrevHourPhaseA, ',', PrevHourPhaseB, ',', PrevHourPhaseC);
        CloseFile(file2);
    
        LogMessage('Appending Energy Data to CSV');
      end
      else
      begin
        AssignFile(file2, fn_EnergyUsage);
        ReWrite(file2);
        WriteLn(file2, 'DateTime', ',', 'Date', ',', 'Time', ',', 'Total (kWh)', ',', 'PhaseA (kWh)', ',', 'PhaseB (kWh)', ',', 'PhaseC (kWh)');
    
        // If this file is new, save the last 50 entries
        //for index := 60 downto 1 do
        //begin
        // PrevHourTotal := GetRealIBSystemIO("Power Meter Total Energy", 0, 1, index, 0, 0, -1);
        // PrevHourPhaseA := GetRealIBSystemIO("Measurement App Energy Value", 254, 1, 1, 0, 1, index, 0, 0);
        // PrevHourPhaseB := GetRealIBSystemIO("Measurement App Energy Value", 254, 1, 2, 0, 1, index, 0, 0);
        // PrevHourPhaseC := GetRealIBSystemIO("Measurement App Energy Value", 254, 1, 3, 0, 1, index, 0, 0);
        // writeln(file2, ' ', ',', ' ', ',', ' ', ',', PrevHourTotal:2, ',', PrevHourPhaseA:1, ',', PrevHourPhaseB:1, ',', PrevHourPhaseC:1 );
        //end;
    
        PrevHourTotal := GetRealIBSystemIO("Power Meter Total Energy", 0, 1, 0, 0, 0, -1);
        PrevHourPhaseA := GetRealIBSystemIO("Measurement App Energy Value", 254, 1, 1, 0, 1, 0, 0, 0);
        PrevHourPhaseB := GetRealIBSystemIO("Measurement App Energy Value", 254, 1, 2, 0, 1, 0, 0, 0);
        PrevHourPhaseC := GetRealIBSystemIO("Measurement App Energy Value", 254, 1, 3, 0, 1, 0, 0, 0);
        WriteLn(file2, sDate, ' ', sTime, ',', sDate, ',', sTime, ',', PrevHourTotal, ',', PrevHourPhaseA, ',', PrevHourPhaseB, ',', PrevHourPhaseC);
        CloseFile(file2);
    
        LogMessage('Creating New Energy Data CSV File');
      end;
    end;
    


    Cheers,

    Paul
     

    Attached Files:

    pspeirs, Sep 20, 2018
    #1
  2. pspeirs

    pspeirs

    Joined:
    Nov 23, 2013
    Messages:
    185
    Likes Received:
    10
    Location:
    Sydney
    I should say before anyone gets pedantic that since the log file entry above, I have changed the script to log new and appends, and removed the last column of the CSV.
     
    pspeirs, Sep 20, 2018
    #2
  3. pspeirs

    DarylMc

    Joined:
    Mar 24, 2006
    Messages:
    1,313
    Likes Received:
    49
    Location:
    Cleveland, QLD, Australia
    Interesting work.
    Could it just be because you are restarting CGate?
    Have you had a look and read how CGate creates and names the log files?
     
    DarylMc, Sep 21, 2018
    #3
  4. pspeirs

    pspeirs

    Joined:
    Nov 23, 2013
    Messages:
    185
    Likes Received:
    10
    Location:
    Sydney
    It isn’t a standard log, I’ll call it a user file. I think I need to include it in the list of additional files rather than just relying on it being in the projects folder. I’ll see how this goes.

    This is one of the simpler scripts, but I want to be able to save it now and again
     
    pspeirs, Sep 22, 2018
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.