Some content on this site is available only to logged-in subscribers. Contact Us for information on becoming a subscriber.

InSource.Solutions | InSource Training | InSource Client Portal
InSource Solutions Logo
Log In Sign Up
InSource.Solutions InSource Training InSource Client Portal Log In Sign Up
  • Home
  • AVEVA MES & Model Driven MES
  • AVEVA MES Tech Notes

TN MES115 Example Script to Fill Application Server Arrays with MES OEE Data

Last updated: March 11th, 2025

Description

  • Author: Brian Schneider
  • Published: March 11th, 2025

Details:

Description

This article from InSource describes When showing OEE related data within an application, an alternative to calling an API or SQL Script on load of the graphic is to hold the OEE dataset in an array of an application object.  When a client Graphic loads it can parse through the array to display data. Below is an example script of how to do this. 

  • Author: Michael Walker
  • Published: 09/25/2015
  • Applies to: Wonderware Application 2014 R2, Wonderware MES 2014

Details

'Start try
try
'Declarations
dim oResult as aaFactMES.Result;
dim oClientSession as aaFactMES.aaClientSession;
dim oEnt as aaFactMES.aaEnt;
dim sEntity as string;
dim iEntityID as integer;
dim iFilterStartHour as integer; 
dim iFilterEndHour as integer; 
dim iStartHour as integer;
dim iIterator as integer; 
dim tsNowToStart as System.TimeSpan; 'time from now to specified start time.
dim tsStartToEnd as System.TimeSpan; 'time span from speciried start to end time.
dim dtStartTime as System.DateTime;
dim dtEndTime as System.DateTime;
dim dtCurrentTime as System.DateTime;
dim aarEmptyFloat[1] as float;
dim aarEmptyTime[1] as float;

'Set timespan data
dtCurrentTime = System.DateTime.Now.Date.AddHours(System.DateTime.Now.Hour);
dtStartTime = Me.ValStartTime;
dtEndTime = Me.ValEndTime;
tsNowToStart = (dtCurrentTime - dtStartTime);
tsStartToEnd = (dtEndTime - dtStartTime);
iFilterStartHour = tsNowToStart.TotalHours;
iStartHour = iFilterStartHour;
iFilterEndHour = iFilterStartHour - tsStartToEnd.TotalHours;

'Set iterator
iIterator = 1;

'Set entity name
sEntity = Me.Tagname;

'Clear arrays
Me.aarOEEVals = aarEmptyFloat;
Me.aarOEETimes = aarEmptyTime;
Me.aarAvailabilityVals = aarEmptyFloat;
Me.aarAvailabilityTimes = aarEmptyTime;
Me.aarDYVals = aarEmptyFloat;
Me.aarDYTimes = aarEmptyTime;
Me.aarPerformanceVals = aarEmptyFloat;
Me.aarPerformanceTimes = aarEmptyTime;

'resize arrays;
Me.aarOEEVals.Dimension1 = tsStartToEnd.TotalHours;
Me.aarOEETimes.Dimension1 = tsStartToEnd.TotalHours;
Me.aarAvailabilityVals.Dimension1 = tsStartToEnd.TotalHours;
Me.aarAvailabilityTimes.Dimension1 = tsStartToEnd.TotalHours;
Me.aarDYVals.Dimension1 = tsStartToEnd.TotalHours;
Me.aarDYTimes.Dimension1 = tsStartToEnd.TotalHours;
Me.aarPerformanceVals.Dimension1 = tsStartToEnd.TotalHours;
Me.aarPerformanceTimes.Dimension1 = tsStartToEnd.TotalHours;

'Get Client Session
oResult = aaFactMES.aaClientSession.GetInstance();
if (oResult.Success == false) then
    LogMessage("WARNING -:- unable to get Client Session" );
else
    oClientSession = oResult.Value;
    'Validate client session and get entity id
    if (oClientSession.SessionId > 0) then
        oResult= aaFactMES.aaEnt.EntIdFromName(sEntity.ToString());
        if (oResult.Success == true) then
            iEntityID = oResult.Value;    
        endif;        
    
        'Loop through hours in date range and get OEE data. 
        while (iFilterStartHour > iFilterEndHour)    
            'get OEE    
            oResult = aaFactMES.aaEnts.GetOEEValue(iEntityID, aaFactMES.aaKPIType.OEE, aaFactMES.aaFilterType.Custom, iStartHour, aaFactMES.aaFilterTimeUnit.Hour, iFilterStartHour, iFilterEndHour);
                 if (oResult.Success == true) then
                    Me.aarOEEVals[iIterator] = oResult.Value;
                    Me.aarOEETimes[iIterator] = dtCurrentTime.AddHours(0 - iFilterStartHour);
                else
                    LogMessage("WARNING --:-- Unable to get OEE Values for: " + Me.Tagname);
                endif;
            'get Availability
            oResult = aaFactMES.aaEnts.GetOEEValue(iEntityID, aaFactMES.aaKPIType.Availability, aaFactMES.aaFilterType.Custom, iStartHour, aaFactMES.aaFilterTimeUnit.Hour, iFilterStartHour, iFilterEndHour);
                 if (oResult.Success == true) then
                    Me.aarAvailabilityVals[iIterator] = oResult.Value;
                    Me.aarAvailabilityTimes[iIterator] = dtCurrentTime.AddHours(0 - iFilterStartHour + 1);
                else
                    LogMessage("WARNING --:-- Unable to get Availability Values for: " + Me.Tagname);
                endif;
            'get Performance
            oResult = aaFactMES.aaEnts.GetOEEValue(iEntityID, aaFactMES.aaKPIType.Performance, aaFactMES.aaFilterType.Custom, iStartHour, aaFactMES.aaFilterTimeUnit.Hour, iFilterStartHour, iFilterEndHour);
                 if (oResult.Success == true) then
                    Me.aarPerformanceVals[iIterator] = oResult.Value;
                    Me.aarPerformanceTimes[iIterator] = dtCurrentTime.AddHours(0 - iFilterStartHour + 1);
                else
                    LogMessage("WARNING --:-- Unable to get Performance Values for: " + Me.Tagname);
                endif;
            'get Quality (DY)
            oResult = aaFactMES.aaEnts.GetOEEValue(iEntityID, aaFactMES.aaKPIType.Quality, aaFactMES.aaFilterType.Custom, iStartHour, aaFactMES.aaFilterTimeUnit.Hour, iFilterStartHour, iFilterEndHour);
                 if (oResult.Success == true) then
                    Me.aarDYVals[iIterator] = oResult.Value; 
                    Me.aarDYTimes[iIterator] = dtCurrentTime.AddHours(0 - iFilterStartHour + 1);
                else
                    LogMessage("WARNING --:-- Unable to get Quality Values for: " + Me.Tagname);
                endif;
            'increment counters    
            iFilterStartHour = iFilterStartHour - 1;    
            iIterator = iIterator + 1;    
        endwhile;
    else
        LogMessage("WARNING --:-- Unable to verify sessoin ID for:" + Me.Tagname);
    endif;
endif;

'Reset Trigger
Me.trgGetOEEVals = false; 

'Catch exception
catch 
    'Reset Trigger
    Me.trgGetOEEVals = false; 
    LogError(error.InnerException.Message);
endtry;

 

array fill application data
Give feedback about this article

Recommended articles

TN 1242 Aveva Historian Storage Locations and Best Practices

Read More

How to receive group emails

Read More
Support Icon

CONTACT SUPPORT

How to reach us

10800 Midlothian Turnpike Tpke, Suite 209, Richmond, VA 23235

1.877.INSOURCE

Technical Support - 1.888.691.3858

Contact Us

  • InSource Solutions
  • InSource Training
  • InSource Client Portal
  • Log In
InSource Solutions Logo

© 2025 InSource Solutions. All Rights Reserved.

Knowledge Base Software powered by Helpjuice

Expand