Showing results 1 to 5 of 5

Thread: How to read values of variable from arhive

  1. #1

    Default How to read values of variable from arhive

    Hello
    Can you write a example how to read values of variable from arhive.
    I tried VBA example from V460 HELP, It's work good. After it I translated this code to C# but couldn't get values.

    In VBA ArchiveFilter.StartTime is type Double. In C# I used zenOn.IArchiveFilter.StartTime and it types is INT. How do convert System time to zenon time using C# ?

    Best regards

  2. #2
    Join Date
    20.08.2009
    Posts
    293

    Default Re: How to read values of variable from arhive

    Hi,

    the .NET framework can do the Time Zone conversion for you.
    Please have a look at: http://msdn.microsoft.com/en-us/library/5hh873ya.aspx

    Regards,
    Bernhard

  3. #3
    Join Date
    20.08.2009
    Posts
    293

    Default Re: How to read values of variable from arhive

    Hi again,

    here is a small sample code for reading values from archive variables:

     public void Macro_GetArvValues()
            {
               
                zenOn.IArchive zArchive;
                zenOn.IArchiveFilter zArvFilter;
                zenOn.IArchiveFilterVariable zArvFilterVar;
                zenOn.IArchiveFilterVariables zArvFilterVars;
                int i;
                int j;
    
                
    
                zArchive = this.Archives().Item(0);
                
                zArvFilter = zArchive.ArchiveFilters().CreateArchiveFilter();
    
                for (i = 0; i < zArchive.ArchiveVariables().Count; i++)
                {
                    zArvFilter.AddArchiveVariable(zArchive.ArchiveVariables().Item(i));
                    MessageBox.Show(zArvFilter.ItemArchiveVariable(i).Name);
    
                }
              
                double tmp_time;
                //convert and set start time
                tmp_time = (DateTime.Parse("17.06.2010 14:39:50").ToUniversalTime().ToOADate() - 25569) * 86400;
                zArvFilter.StartTime = (int)tmp_time;
    
                //convert and set end time
                tmp_time = (DateTime.Parse("17.06.2010 14:40:30").ToUniversalTime().ToOADate() - 25569) * 86400;
                zArvFilter.EndTime = (int)tmp_time;
    
                zArvFilterVars = zArvFilter.Query();
    
                //iterate through archive variables
                for (i = 0; i < zArvFilterVars.Count; i++)
                {
                    zArvFilterVar = zArvFilter.ArchiveFilterVariables().Item(i);
                    //iterate through variable values
                    for (j = 0; j < zArvFilterVar.ArchiveValues().Count; j++)
                    {
                        MessageBox.Show(zArvFilterVar.ArchiveValues().Item(j).Value.ToString());
                    }
                }
    
            }

    Regards,
    Bernhard

  4. #4

    Default Re: How to read values of variable from arhive

    Thank you. It works good.

  5. #5

    Default Re: How to read values of variable from arhive

    .NET does not support a method to convert the Windows Date and Time, to unix epoch time (or unix time) which is used in zenon to store timestamps.

    timestamps for values in archives are stored in UTC, therefore first a normalization of the entered time (local PC time) to UTC is done. (adoption of the time in the local timezone, to UTC time)

    DateTime.Parse("17.06.2010 14:39:50").ToUniversalTime()

    After that, the time is converted to OLE Automation date, which is the number of days, and decimal hours passed since midnight 31 december 1899.

    .ToOADate()

    After that, the time is converted to unix epoch time, which is the number of seconds passed since 01/01/1970 midnight UTC.

    25569 * 86400; (25569 days between 31.12.1899 midnight and 01/01/1970 midnight) * 86400 seconds per day


    Another way to convert windows Date and Time to unix epoch time is to take the number of 100 nanoseconds (ticks) between midnight 01/01/0001 and midnight 01/01/1970, and divide by 10.000.000 to get the number of seconds.

    tmp_time = (DateTime.Parse("17.06.2010 14:40:30").ToUniversalTime().Ticks - 621355968000000000) / 10000000;

Similar Threads

  1. How to set column width for Arhive revizion
    By captain in forum zenon Supervisor
    Replies: 9
    Last Post: 30th September 2014, 07:49
  2. Replies: 5
    Last Post: 4th September 2013, 00:16
  3. Sum of 2 variable values
    By dragosmoss in forum zenon Supervisor
    Replies: 2
    Last Post: 18th March 2009, 14:17
  4. Read Real variables in VBA
    By joulz in forum VBA
    Replies: 4
    Last Post: 5th February 2009, 13:29
  5. Read dBase does not work
    By bjoerndavid in forum zenon Supervisor
    Replies: 3
    Last Post: 26th November 2007, 13:15

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •