Codesys 3.5 Trend Record

jadchamas
2020-11-15
2020-11-16
  • jadchamas - 2020-11-15

    Hi all,

    1. I created a trend record in codesys 3.5 (attached picture). However I do not know precisely how much time can the trend record show me backward. Is it days, weeks or months ?
      It is highly important to me to know if I can see old recorded values for 1 week or not.
    2. The recorded files of the trend record graph are SQlite files, but they are incomprehensible integers when opened in DB browser. Is there a way to make them readable ?

    I kindly need your support.

     
  • m.prestel - 2020-11-16

    hey,

    It depends on how many variables you record since the number of variables affect the storage size and that depends on your device.
    The only known limitiation, which may cause some problems, is the 2GB file limit.

    Right now there is no way to export it to csv.

    Best regards,
    Marcel

     
    • kislov - 2020-11-16

      Sir Prestel, there is a problem that user can't understand how many bytes will take one record in database. It will be helpful to show it in CODESYS IDE.
      I'm already ask about it:
      https://forge.codesys.com/forge/talk/Visualization/thread/9850eec96c/

      I also hope that in future versions we get "Export CSV" feature - and not only manually from IDE, but with IEC-code too.

       
      • m.prestel - 2020-11-16

        I agree, number of records is better to use.

         
  • jadchamas - 2020-11-16

    hello Marcel,

    I have 4 variables in the trend with a sampling of 200ms. the storage size in 'Trend storage' is by default 10 MB.
    With these configurations can I see with cursor old data values for 1 week backwards ??
    Is there any way codesys save/show a long trend ranging from 1 week to 1 month ?
    Please it is highly important for me to know if possible to make a long trend and saving in Codesys.
    Otherwise I have to change to a SCADA software to do a long trending.

    Best Regards,
    Jad

     
    • m.prestel - 2020-11-16

      Hey,
      yeah I think you should be good.
      You can also just limit the number of recordings (which is easier to calculate for you).

      Yeah the trace does save longer ranges as well, but then the database size may be a problem for your plc.

      Again, exporting to CSV is currently not possible.

      Best regards,
      Marcel

       
      • jadchamas - 2020-11-16

        hello,

        Just to confirm, can the trace save a long trend for more then 1 month and show it to me in the backward cursor?
        I have no problem with memory, the HMI is the PLC where codesys 3.5 is installed and it has a wide hard disk (500GB). I believe I can put no limit in the 'Trend Storage'.

        Marcel, the SQlite files saved by the trend are not readable in DB Browser, just integers. I think they need to be converted to big endian to become float values.
        How to read these SQlite files? they are very important for trend analysis.

        Best Regards,
        Jad

         
        • Morberis

          Morberis - 2020-11-16

          I use some code in visual designer to do this after I export it from DB Browser as a csv file.

          You'll need to change the redacted to the username for the desktop and the file must be named TrendIn.csv.

          You'll need to change things up for the amount of fields you have etc.

          I'm not sure if it fixes the endian problem you're seeing.

          You can definately see back 1 month. I record values every 5 minutes and the longest I've let it run without clearing the trend file was 2 years. Displaying 2 years at once, or a month, however would crash the visualization.

          class Program
              {
                  static void Main(string[] args)
                  {
                      string rawin = @"C:\Users\**REDACTED**\Desktop\TrendIn.csv";
                      string path = @"C:\Users\**REDACTED**\Desktop\ConvertedTrendData.csv";
          
                      // Create output file "TrendIn.csv"
                      //Input must be TimeStamp, Temp <UInt>
                      using (StreamWriter sw = new StreamWriter(path, true))
                      {
                          // Open input file "ConvertedTrendData.csv"
                          //Output will be Timestamp, DateTime, Temp <single>
                          using (StreamReader sr = new StreamReader(rawin))
                          {
                              while (sr.Peek() >= 0)
                              {
                                  string s = sr.ReadLine();
          
                                  string[] flds = s.Split(',');
                                  flds[1] = EpochToDateTime(flds[0]).ToString();
                                  flds[2] = UIntBinarytoFloat(flds[2]).ToString();
                                  s = string.Join(",", flds);
          
                                  sw.WriteLine(s);
                              }
                          }
                      }
                  }
          
                  // Unix Timestamp to DateTime
                  private static DateTime EpochToDateTime(string strValue)
                  {
                      long.TryParse(strValue, out long timestamp);
                      return EpochToDateTime(timestamp);
                  }
                  private static DateTime EpochToDateTime(long timestamp)
                  {
                      var epoch = new DateTime(1970, 1, 1, 0, 0, 0);
          
                      string ts = timestamp.ToString();
          
                      if (ts.Length <= 11)
                      {
                          return epoch.AddSeconds(timestamp);
                      }
                      else if (ts.Length > 11 && ts.Length <= 14)
                      {  //Assuming  Milliseconds
                          return epoch.AddMilliseconds(timestamp);
                      }
                      else
          
                      {  //Assuming Microseconds - reduce by 1000s down to Milliseconds
                          while (ts.Length > 14)
                          {
                              ts = ts.Substring(0, ts.Length - 3);
                          }
                          timestamp = long.Parse(ts);
                          return epoch.AddMilliseconds(timestamp);
                      }
                  }
          
                  //Convert Unsigned Integer Binary Format to Float (single)
                  private static Single UIntBinarytoFloat(string strValue)
                  {
                      uint.TryParse(strValue, out uint uintValue);
                      return UIntBinarytoFloat(uintValue);
                  }
                  private static Single UIntBinarytoFloat(uint value)
                  {
                      byte[] bytes = BitConverter.GetBytes(value);
                      return BitConverter.ToSingle(bytes, 0);
                  }
              }
          }
          

          If you want something that directly creates a CSV file check out the Datalog_Storage Manager. You'll need to add the library and then the manager to the Modules tab. It does not create a graph though.

           

          Last edit: Morberis 2020-11-16
  • m.prestel - 2020-11-16

    Hello,

    in general yes, if it does work in your case, try it out. (e.g. by increasing the recording interval for a test to simulate the number of records you would have in a month etc etc).

    No, I cannot support you reading the sqlite file.

    Best regards,
    Marcel

     

Log in to post a comment.