Hugovdberg / PIconnect

A python connector to the OSISoft PI and PI-AF databases
MIT License
91 stars 41 forks source link

Runtime error getting interpolated values for long period/high interval #54

Closed sapdejong closed 3 years ago

sapdejong commented 6 years ago

Description

Tried to get interpolated values for a long period (years) with high interval (minutes). System gives a runetime error

What I Did

start = "01-01-2014"
eind = "13-03-2018"
interval = '2m'

for item in lijst: 
    with PI.PIServer() as server:
        tags = server.search(item)
        for tag in tags:
            data = tag.interpolated_values(start, eind, interval)
            data.to_csv(tag.tag + ".csv")
PITimeoutException: [-10722] PINET: Timeout on PI RPC or System Call.
   bij OSIsoft.AF.PI.PIException.ConvertAndThrowException(PIServer piServer, Exception ex, String message)
   bij OSIsoft.AF.PI.PIPoint.InterpolatedValuesByCount(AFTimeRange timeRange, Int32 numberOfValues, String filterExpression, Boolean includeFilteredValues)
   bij OSIsoft.AF.PI.PIPoint.InterpolatedValues(AFTimeRange timeRange, AFTimeSpan interval, String filterExpression, Boolean includeFilteredValues)
Hugovdberg commented 6 years ago

Thanks for your report. I think this can be solved by extending the OperationTimeout, I'll try to add it as an option to the PI.PIServer() constructor.

anjazgodic commented 6 years ago

@Hugovdberg I was wondering if you could provide some hints or a bit more guidance on this and I can try to add the option myself. I am facing the same issue.

Hugovdberg commented 6 years ago

The PIServer object has an attribute connection which is an AF.PI.PIServer() object. This itself has a property ConnectionInfo.OperationTimeOut which is a System.TimeSpan object containing the maximum time an operation can take. To override this I think you could do something similar to the following for now:

import PIconnect as PI
from System import TimeSpan

timeout = [
    0, #  hours
    5, #  minutes
    0, #  seconds
]

server_manager = PI.PIServer()
server_manager.connection.ConnectionInfo.OperationTimeOut = TimeSpan(*timeout)

with server_manager as server:
    print(server.connection.ConnectionInfo.OperationTimeOut)

To implement this in PIconnect, an extra argument could be added to the PIserver.__init__ method to which sets the property on initialisation. This is necessary because once connected (as inside the context manager) the ConnectionInfo is read only.