pisn_getsnapshots
This function retrieves the most recent values sent to the pi System for an array of points. The snapshot values in engineering units, status codes, times, dates, and errors are returned in the passed parallel arrays. If the point type is not real, the value is returned in istat and the rval argument is returned as 0.C formatint32 pisn_getsnapshots( 
int32 PIPTR * pt
float PIPTR * rval, 
int32 PIPTR * istat,
int32 PIPTR * timedate, 
int32 PIPTR * error,
int32 count );
Returns
>0
 System error
0
 Success 
-1
 Point not found
 
Arguments
pt (passed)
Array of point numbers
rval (returned)
Array of values in engineering units, undefined for integer and digital points
istat (returned)
Array of statuses for type real points and values for integer and digital points
timedate (returned)
array of time stamps
error (returned)
Array of error codes
count(passed)
Size of the arrays
pi Toolkit Reference
GetSnapshot以下是VB的定义
Declare Function pisn_getsnapshots Lib "piapi32.dll" (pt&, rval!, istat&, timedate&, piapierror&, ByVal count&) As Long我是这样定义的
function pisn_getsnapshots(pt:array of Integer;rval:array of single;istat:array of Integer; timedate:array of Integer; error:array of Integer; count: Integer):Integer;stdcall;external 'piapi32.dll';
调用的时候
var
pt:array[0..20] of Integer;
rval:array[0..20] of single;
istat:array[0..20] of Integer; 
timedatePt:array[0..20] of Integer; 
errorPt:array[0..20] of Integer; 
countPt: Integeri:=getsnapshots(pt[0],rval[0],istat[0],timedatePt[0],errorPt[0],countPt);i的值为0表示调用成功,但是rval[0]。。rval[20],的值都不正常,我把上面的句函数调用注释掉,rval[0]..ravl[20]的值仍不变,证明rval的数值在函数中没有被赋值,请高手帮忙看一下,是不是我的定义有问题,还是调用方法有问题

解决方案 »

  1.   

    又见“ array of Integer ”Delphi里array of xxxx参数叫变体数组,信息包括了上下标信息。C里的数组只能从0开始,这是就差别,数据类型都不一样。
    大概会是这样:
    type PSignle = ^Signle;function pisn_getsnapshots(pt: PInteger;rval: PSingle;istat:PInteger; timedate:PInteger; error:PInteger; count: Integer):Integer;stdcall;external 'piapi32.dll';var pt: array[0..9] of Integer;
    var rval: array[0..9] of Single;
    var istat: array[0..9] of Integer;
    var timedate: array[0..9] of Integer;
    var error: array[0..9] of Integer;begin
      pisn_getsnapshots(@pt[0], @rval[0], @istat[0], @timedate[0], @error[0], 10);
    end;