AnsweredAssumed Answered

PHP: How do you retrieve archive values and summary values using simple PHP code?

Question asked by snavekram on Jan 20, 2017
Latest reply on Feb 1, 2017 by pthivierge

Hello PI Squared Community,

 

I am writing an in-house application to show PI data on a web-page. I have managed to retrieve current snapshot values but I cannot work out how to retrieve archive values (e.g. the value 1 hour ago) nor can I get summary values (e.g. the average).

 

This is a very simple application and because it is on the control system side we don't want to have to install extras so I need a solution to work with standard php.

 

Any ideas on how to do this? I have tried searching and also converting vba type code to what I think is php code but I get an undefined method error.

 

For reference here is my code for retrieving the snapshot;

<?php

 

 

/**

* The PI data request class

*

* This class performs the interface function between webserver pages and the PCN PI server.

*

* It contains several methods for getting data from PI.

*/

 

 

class PIDataRequestClass

{

  // Set up the class properties.

 

  protected $PIserverName = "xxxxx";

  protected $comObjPi;

  protected $PIserver;

  protected $PIpoint;

 

  public $PIdata;

 

 

 

 

  /**

  * Makes the connection to the PI ready for querying / updating by the website.

  *

  * @return void

  */

 

  public function __construct()

  {

       $this->comObjPi = new COM('PISDK.PISDK');

         $this->PIserver = $this->comObjPi->Servers->Item($this->PIserverName);

         $this->PIserver->Open();

  }

 

 

 

 

 

 

  /**

  * Disconnects the connection to the PI server.

  *

  * @return void

  */

  public function __destruct()

  {

         $this->PIserver->Close();

  }

 

 

 

 

 

 

  /**

  * Returns a simply formatted value back to the caller.

  *

  * @ return numeric

  */

  public function getPIValueSimple($PItag)

  {

 

 

 

       $this->PIpoint = $this->PIserver->PIPoints($PItag);

       $this->PIpoint->Data->SnapShot()->Value."\n";

 

       $this->PIdata = $this->PIpoint->Data->SnapShot()->Value."\n";

       $this->PIdata= number_format($this->PIdata, 1, '.', '');

    

 

 

       return $this->PIdata;

 

  }

 

 

}

 

 

?>

 

Thanks,

Mark

Outcomes