Question

I am trying to connect to OSI Pi database and keeping getting the errors below. I have all the permissions set correctly because I can run VB code. It does read the server version correctly.

Here is my PHP:

 <?php
 echo "I will connect to PI Server, read pisdk version and read server time";
 echo "<br>";
 $pisdkComObject = new COM("PISDK.PISDK") or die("Unable to instantiate PISDK object");
 echo "PI server version {$pisdkComObject->PISDKVersion}";
 $myServer = $pisdkComObject->Servers->Item("XXXX_SERVERNAME_XXXX");
 $myServer->Open();
 echo "<br>";
 echo "PI server time is {$myServer->ServerTime}";
 ?>

Here is my output:

PI server version 1.3.6 Fatal error: Uncaught exception 'com_exception' with message 'Source: pisdk.dll Description: Unable to open a session on a server. [-10728] PINET: Send Error.' in E:\XXXX.php:12 Stack trace: #0 E:XXXX.php(12): variant->Open() #1 {main} thrown in E:XXXX.php on line 12

Was it helpful?

Solution

Here is an alternate approach: A pre-requisite is to install PI OLEDB Provider.

Then go to http://adodb.org/dokuwiki/doku.php and install the ADODB library for php as directed. There is some introductory information about the library there as well.

My next step was to generate a UDL (save a blank text file with the extension of '.udl'), then double click it to open the Data Link Properties dialog box. Under the Provider tab choose "PI OLE DB Provider". Under the Connection tab type in the name of your pi server in the Data Source text box. You will need to configure log on information unique for your server there as well. For this development connection I used "piarchive" as my 'initial catalog to use'. After your [Test Connection] is successful you can click [OK].

Then right click on your UDL and open with notepad or any text editor. Select and copy the connection string (i.e. "Provider=PIOLEDB.1;. . . etc.).

Next is a bit of code I have used to generate a small table of values for the CDT158 tag, and a corresponding array. In my development version I placed this code between the body tags.

<?php
    include("adodb/adodb.inc.php");
    $connection = new COM("ADODB.Connection") or die("Cannot start ADO"); 

    // PI OLEDB (UDL) connection string.
    $connection->Open("Provider=PIOLEDB.1;Initial Catalog=piarchive;
        Data Source=yourPIServerNameHere;Persist Security Info=False");

    $result_set = $connection->Execute("
                SELECT tag, TIME, value 
                FROM picomp 
                WHERE TIME >= '*-90m' AND tag = 'cdt158'
                ");
    $result_count = 0;
    $labels = array();
    while (!$result_set->EOF) 
    {   print $result_set->fields[0].' | '.$result_set->fields[1].' | '.$result_set->fields[2].'<br />';
        array_push($labels, "{$result_set->fields[1]}");
        $result_count = $result_count +1;
        $result_set->MoveNext();
    }

    echo "<br />The number of records retrieved is: ".$result_count."<br /><br />";

    echo "<pre>";
        print_r($labels); // this displays the array generated.
    echo "</pre>";

    $result_set->Close(); // optional
    $connection->Close(); // optional
?>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top