VBA AF Wrapper Extension GetValueByTime for Processbook

Version 1

    I have been extending the original base wrapper to allow me to pull data based on a time.  I am running into an issue that the value doesn't change for each interval and I'm not even sure where the number it is getting is coming from.  If someone could take a look at what I've done and see if you notice any mistakes, that would be helpful.

     

    First the change to the Wrapper:

     

     

     

     // Gets the current value for an attribute path
            [ComVisible(true)]
            public string GetAttributeValue(string fullAttributePath)
            {
                AFObject obj = AFObject.FindObject(fullAttributePath);
                AFAttribute attr = obj as AFAttribute;
    
                if (attr == null) return "";
    
                return attr.GetValue().ToString();
            }
            [ComVisible(true)]
            public string GetAttributeValueByTime(string fullAttributePath, DateTime dt)
            {
                AFObject obj = AFObject.FindObject(fullAttributePath);
                AFAttribute attr = obj as AFAttribute;
    
                if (attr == null) return "";
                AFTime time = new AFTime(dt);
    
                return attr.GetValue(time).ToString();
            }
    
            // Gets the current value for an attribute of a given element path
            [ComVisible(true)]
            public string GetAttributeValueForElement(string elementPath, string attribute)
            {
                return GetAttributeValue(elementPath + @"|" + attribute);
            }
            [ComVisible(true)]
            public string GetAttributeValueForElementByTime(string elementPath, string attribute, DateTime dt)
            {
                return GetAttributeValueByTime(elementPath + @"|" + attribute, dt);
            }
    

    Now the VBA Code:

     

     

     

    Public Sub GetAttrValue()
        
        Set AFW = New Wrapper
        
        Dim dt As Date
        dt = Now
        If (Hour(dt) > last) Then
            Dim itor As Integer
            ListBox1.Clear
            itor = 0
            last = Hour(dt)
            Do While (itor <= last)
                Dim dv As String
                dv = Month(Now) & "/" & Day(Now) & "/" & Year(Now) & " " & itor & ":00:00"
                ListBox1.AddItem (dv & " - " & AFW.GetAttributeValueForElementByTime("\\BATTLESTAR\TF\Rev Qual Meters", "City Load", DateValue(dv)) & "MW")
                itor = itor + 1
            Loop
            
            
        End If
        
        
           
        
    End Sub
    

    The Result when this code is run looks like this:

     

    3487.Screen-Shot-2013_2D00_06_2D00_06-at-9.16.29-AM.png

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    looks like my post got truncated.

     

    The value changes much more than this.  The midnight value should be close to 317 and the 9am value should be close to 366.  My two questions are, do I need to worry about timezone vs UTC in the wrapper, and why doesn't the value change through each time value sent by the loop?  See the trend of the same AF Attribute below:

     

    7624.Screen-Shot-2013_2D00_06_2D00_06-at-9.19.06-AM.png

     

    Hello Ethan,

     

    I have tested your new AF Wrapper version, but I did a small change: the time variable in my case is a string. The advantage is that I can use expressions like “*-10d” in my application.

     

    The code snippet is below:

     

     

     

    [ComVisible(true)]
            public string GetAttributeValueByTime(string fullAttributePath, string valueTime)
            {
                AFObject obj = AFObject.FindObject(fullAttributePath);
                AFAttribute attr = obj as AFAttribute;
    
                if (attr == null) return "";
                AFTime time = new AFTime(valueTime);
    
                return attr.GetValue(time).ToString();
            }
    
    public string GetAttributeValueForElementByTime(string elementPath, string attribute, string valueTime)
            {
                return GetAttributeValueByTime(elementPath + @"|" + attribute, valueTime);
            }
    

     

     

    Then, I have tested using PI ProcessBook, using the following VBA code:

     

     

     

    Private Sub Display_Open()
    
    Dim Wrapper As New AFWrapper.Wrapper
    Dim SinusoidValue As String
    SinusoidValue = Wrapper.GetAttributeValueForElementByTime("\\marc-pi2012\Piperfmon\TagsValue", "Sinusoid", "11-May-2012")
    MsgBox SinusoidValue
    
    End Sub
    

     

     

    I have compared this result with PI DataLink, using the  Archived Value function, and they both are the same. Therefore, it seems to be working fine.

     

    Please make a quick test with the VBA code above and check the results.  My other suggestion is to develop a console application using the GetValue() method of the AF SDK library to compare the results.

     

    该文档由下列讨论生成:VBA AF Wrapper Extension GetValueByTime for Processbook