Skip to main content
InSource Solutions

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

insource logo large.jpg

 

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;