PI实时数据库API,SDK接口调用说明

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

调用API步骤VB6:

VB6代码示例:其中pilog为返回值,各个含义可以查找PIAPI帮助,举例如下:

>0 System Error

0 Success

-1 Attempt to reconnect within 60 seconds or

socket_open has failed

-994 Incompatible PINET protocol version

-1001 Default host not found

VB6函数声明:

'Use this function to establish a connection to the default pi home node server if calling from a pi client node.

Private Declare Function piut_connect Lib "piapi32.dll" (ByVal servername$) As Long

'This function logs the user into a PI Server. A login is required to gain access to protected PI data.

Private Declare Function piut_login Lib "piapi32.dll" (ByVal username$, ByVal password$, valid&) As Long

'This function parses the passed time string and returns the pi local time.

Private Declare Function pitm_parsetime Lib "piapi32.dll" (ByVal timestr$, ByVal reltime&, timedate&) As Long

'This function adds a new value to the Archive, or it replaces a value if one exists at the same time stamp.

Private Declare Function piar_putvalue Lib "piapi32.dll" (ByVal pt&, ByVal rval!, ByVal iStat&, ByVal timedate&, ByVal wait&) As Long

'This function returns the point number for the given tagname.

Private Declare Function pipt_findpoint Lib "piapi32.dll" (ByVal TagName$, pt&) As Long

'This function returns a single value and status for a specified time stamp.

Private Declare Function piar_value Lib "piapi32.dll" (ByVal pt&, timedate&, ByVal Mode&, rval!, iStat&) As Long

'This function sends a value to the Snapshot and Archive.

Private Declare Function pisn_putsnapshot Lib "piapi32.dll" (ByVal pt&, ByVal rval!, ByVal iStat&, ByVal timedate&) As Long

'This function retrieves the most recent value sent to the pi System for a particular point.

Private Declare Function pisn_getsnapshot Lib "piapi32.dll" (ByVal pt&, rval!, iStat&, timedate&) As Long

编程步骤:用其他语言编写接口可参考下面的步骤来实施,具体语法及API函数声明根据所用的语言来编写。某些语言的声明可在API帮助里找到。

1.连接服务器

pilog = piut_connect(Text1.Text)

2.登陆

pilog = piut_login(Text2.Text, Text3.Text, valid)

3.读取PI位号值

3.1 查找PI位号PT号,PT号就是该位号在PI里面的point ID

pilog = pipt_findpoint(Text4.Text, pt)

3.2 获取PI时间

pilog = pitm_parsetime("*", 0, timedate)

3.3 读取该PI时间,该位号的值

pilog = pisn_getsnapshot(pt, flo, 0, timedate)

Text5.Text = flo ‘(flo变量就是PI的值)

4.写入PI位号值

4.1 查找PI位号PT号

pilog = pipt_findpoint(Text4.Text, pt)

4.2 获取PI时间

pilog = pitm_parsetime("*", 0, timedate)

4.3 写入该位号在该PI时间的值

pilog = pisn_putsnapshot(pt, flo, 0, timedate)

PI API提供一个公共的编程接口,用C/C++或VB、甚至连PI-PROCESSBOOK中内嵌的VBA 都可以对PI数据库进行数据读写。

用API开发PI的接口一般有两种方法。

一是用接口程序去控制一切与PI数据库有关的操作,这些操作包括建点和属性配置工作、数据读写工作等等,这样要用到PI-API和PI-SDK,对数据读写可以利用PI-API,建点和属性配置工作可以利用PI-SDK。这种方法用起来比较复杂,对编程要求很高,同时由于绕开了数据库管理员对数据的管理,对数据库的安全性也构成了影响。所以只有在特殊场合才用到这种方法。

二是借鉴OPC方式,接口程序只负责数据的读写,建点和属性配置工作放到PI服务器端由数据库管理员人工完成。这种方式下在配置PI的点及相关属性时,比OPC方式下的配置工作要简单得多:TAGNAME与INSTRUMENTTAG可取相同名,数据类型、量程、工程单位和死区范围等可按常识配置,其它属性都可用默认值。以下用VB为例说明PI API的大致用法。

在编程之前,先要安装OSI提供的PI-API,安装后会生成\\PIPC\LIBRARY\PIAPI32.DLL和\\PIPC\INCLUDE\PIAPI32.BAS两个文件。

相关文档
最新文档