Using PI API with Visual Basic 6.0

osi.jpg

The PI API provides a common programmer interface to PI System information.

The API is two files: PIAPI32.DLL & PILOG32.DLL which are the foundation of PI networking and data functionality
PIAPI32.dll – contains all of the “C” language functions necessary for any of the PI clients (including PI ProcessBook & PI DataLink) or any of PI’s high speed interfaces to interact with PI: reading and writing data, buffering system, informational functions, etc.
PILOG32.dll – contains all of the “C” language functions necessary to connect to PI servers, logon with security, and create and interpret data packets.

To Declare a Function
To declare a function in VB, you must use the Declare statement
Declare param1 param2 param3 param4 param5
param1: Function or Sub
param2: Name of the function
param3: Lib
param4: File name and library directory of PI API
param5: List of arguments

Example:

Declare Function piar_putvalue Lib "piapi32.dll" (ByVal pt&, ByVal rval!, _ 
                           ByVal istat&, ByVal Timedate&, ByVal wait&) As Long

Note: The file \PIPC\INCLUDE\PIAPI32.BAS contains all PI API functions, procedures and PI variable types definitions.

API Return of Functions
Most functions return a number to indicate if the function ran correctly

  1. < 0 Parameter error in the function or unavailable information in PI
  2. = 0 Success
  3. > 0 System error (Computer or communication error)

Error Handling

To prevent an application from crashing due to an error occurring, follow these steps:

  1. Trap errors
  2. Display error number and description
  3. Resume execution of the application after quitting the faulty procedure

To trap an error

On Error GoTo ErrH_Procedure_Name

To display the trapped error

MsgBox Err.Number & " - " & Err.Description
Resume Exit_Procedure_Name

To exit the procedure or take corrective action

Exit_Procedure_Name:
    Exit Sub

Example:

Private Sub Sample()
    On Error GoTo ErrH_Sample
 
    'Code
    '.....
    '.....
    'End code
 
    Exit_Sample:
        Exit Sub
 
    ErrH_Sample:
        MsgBox Err.Number & " - " & Err.Description
        Resume Exit_Sample
End Sub

1 comment so far

  1. Ram Komara December 1, 2008 5:04 pm

    I am very interest with PIAPI32.dll
    Now I’m developing application to integrated LIMS application with PI.
    Can you give sample using PI API with PowerBuilder?

    Thanks you very much.

    Ram Komara
    Information Development
    Pertamina Refinery Unit 6
    Balongan, Indramayu
    West Java, Indonesia

Leave a comment

Please be polite and on topic. Your e-mail will never be published.