1 Reply Latest reply on Jul 28, 2015 8:44 PM by bshang

    efficient connection pivalues with batches?


      Hi everybody,

      I have the following nested loops:


      For every UNIT (user-defined in input table)

      - Get all batches within the user-defined start/end time window using PIUnitBatchSearch

      - For every BATCH

      --  Get the start/end time of the current batch

      ---  For every TAG (user-defined in input table)

      ---    Get the PIValues for the start/end batch time using PIPoint.Data.RecordedValues

      ----    For every PIValue

      ----    Write every value in a spreadsheet


      This isn't really an optimal design as it is very slow. Is there any way I can pull all the batches along with their data from Pi in one go giving it a unit, tag, start/end date list?

      I was thinking of pulling the batch list for a user-defined time window and the pivalues for that same window separately (two huge PI pulls instead of a lot of small pulls) and then joining them together (is there a specific PI function for this join?)

      I've written this pseudocode in VBA, it would be great if you could include a VBA snippet supporting your answer.


      Thanks in advance!


        • Re: efficient connection pivalues with batches?

          Hi Bart,


          one area for optimization is in the For every TAG part. In PI SDK, it is not possible to make a bulk (multi-tag) RecordedValues call, so several roundtrips must be made. However, PI SDK offers a way to do this asynchronously so these calls are not serialized.


          Here is the method signature taken from the PISDK.chm guide.

          object.RecordedValues StartTime, EndTime, BoundaryType, [FilterExp], [ShowFiltered], [AsyncStatus]


          In AsyncStatus, you can pass in a PIAsyncStatus object, which acts as a handle to the async call. You can declare and initialize as such "Dim asynch As New PIAsynchStatus", and then pass in asynch into the PIPoint.Data.RecordedValues call. There is an example for using this object in the PISDK.chm guide under "PIAsynchStatus Example".


          All of the above is assuming that network roundtrips is the bottleneck. Can you provide more details on where you think the code may be slow? If it is client-side processing that is slow, then other areas will need to be looked at.