Using PI SDK with Visual Basic 6.0

PI SDK References for a VB Project
PISDK 1.3 Type Library
Main PI SDK dynamic link library (DLL) – primary library for PI SDK content
PI-SDK Dialogs Library
Contains standard PI SDK functions like tag search and connection handling
PISDKCommon 1.0 Type Library
Makes available some shared data structures, like “named values”
PITimeServer 1.1 Type Library
Parses time strings and correctly renders time in several useful forms
PISDKParse 1.1 Type Library
Handles parsing / interpreting of expressions for the PI SDK – including PI PE style filter and calculation expressions
Open a new project in Visual Basic
Add the references to the PI SDK libraries(menu: Project->References)
Save the project in the following folder (C or other disk):
C:\Program Files\Microsoft Visual Studio\VB98\Template\Projects
Close and re-open Visual Basic to open the template project from the introduction window
The PI SDK type library contains the definition of all the PI SDK classes. The assignation of a class to a variable is different than standard VB variable assignations.
A two step process is required to set a class variable. First you first have to declare an object variable of that object’s class:
Dim Variable As Object
Example:
Dim srvPIServer As Server
The second step consists in assigning a variable to an existing item in a collection or create a new instance (new item):
Set Variable = New Object
or
Set Variable = Collection.Item("DesiredItem")
or
Set Variable = Collection("DesiredItem")
(because “Item” is the default property of collections… only supported in VB6)
It is possible to create a new item with a single command
Dim Variable As New Class
Equivalent to :
Dim Variable As Object
Set Variable = New Object
Each class uses memory and system resources.
It is good practice to free class variables after use
Set Variable = Nothing
SDK Login Types
The interactive login type is used for end-user applications, where a user name and a password can be provided interactively. The connection string looks like that:
Where xxx is the PI user name and yyy, its password.
On the other hand, the non-interactive login type is usually used for interfaces and other non-interactive applications; that is, where no user can enter a name and a password. In this case, an entry in the PI Trust table must be added on the targeted server. Trusts will be covered later.
Using the PISDK Dialog
The syntax of the Login method is:
Most users will want to use the higher-level PISDKDlg.Connections.Login method to connect to a server because it displays the PI-Login dialog if the user account is password protected. If you use the lower-level PISDK.Server.Open method instead, it will simply raise an error if the user account is password protected.
This method can also be used to explicitly log in as a particular user by setting Override=True and ForceShow=True.
Assign a value to the variable that identifies the default server
Dim srvPIServer As Server
Set srvPIServer = PISDK.Servers.Item("localhost")
Assign a variable to the PISDKDlg object
Dim dlgConnection As New PISDKDlg.Connections
Execute the login method
dlgConnection.Login srvPIServer,,, TRUE, TRUE
Connecting Using a “ConnectionString”
Open a connection to the server to allow sending and retrieving data. Most useful operations require an open connection and most programs will initially determine the Server or servers of interest and immediately establish a connection with them using the Open method.
The Open method takes a connection string and attempts to open a connection to the server specified by the Server object. The connection string contains the parameters for the desired connection: UID and PWD. An empty string (”") may be used indicating that default connection parameters from the Known Servers Table or the trust relations on the server should be used.
Assign a value to the variable that identifies the default server
Dim srvPIServer As Server
Set srvPIServer = Servers.Item("localhost")
Build your connection string
Dim strConnectionString As String
strConnectionString = "UID=PIADMIN;PWD="
Execute the connection method
srvPIServer.Open strConnectionString
Execute the close method
srvPIServer.close
Close Method
This method closes a connection to a Server. Typically done when no more work will be done on the Server and objects retrieved from the server are no longer referenced.
Closing a server can allow the PI-SDK to free up resources when access to the server is no longer needed. The Close method is also used when a program already connected to a server wishes to connect as a different user. Attempting to open a server that is already open under a different connection string generates an error. Instead the program should call Close before the second open attempt.











Hi gYtHialY,
I came to your website when googling PI-SDK. Your blog is cool and I like it. I am glad to find through your blog that you are a Chinese. I am Chinese too.
Have you used PI-SDK in VB.NET? I am having some problems to transfer VB6 example to VB.NET and may need some help.
John
现在基本上都用C#做的,这样比较简单-_-
VC太麻烦了,人老了,也懒了
VB.NET应该更容易才对的,OSI的demo大多都是VB/VB.NET的啊
谢谢你的回答
我刚开始用PI编程.C#没用过.找到一个VB.NET的DEMO,还没仔细看,似乎跟VB的例子相差很大.
看看PI SDK的帮助文档就可以了
里面好多VB/VB.NET的例子