GETFIRST/GETNEXT Model

The function piar_getarcvaluesx uses a GETFIRST/GETNEXT model. This means that the function is always called first with a function code labeled GETFIRST, which returns the first result from the PI Data Archive.

If no errors are observed, the function is recalled in a program loop with the function code GETNEXT, which will return the next data value. As with all PI-API functions, piar_getarcvaluesx will return zero if no error has occurred and data has been returned. This function is called successively until the function returns a special error code PI_NOMOREVALUES.

Programmers should note that all results are retrieved from the PI Data Archive when piar_getarcvaluesx is called with the GETFIRST function code and are returned to the client node. Subsequent calls using the GETNEXT function code do not generate additional network messages.

The sequence of calls is approximately this:

char buff[255];

uint32 bsize = sizeof(buff);

error = piar_getarcvaluesx(ptnum, ARCflag_comp, &count, &drval, &ival, buff, &bsize, &istat, 0, &t, &t1, GETFIRST);

if (!error) {

do {
 

/* handle results */
/* reset ‘bsize’ for the next call */
bsize = sizeof(buff);
 

} while ((error = piar_getarcvaluesx(ptnum, ARCflag_comp, &count, &drval, &ival, buff, &bsize, &istat, 0, &t, &t1, GETNEXT))== 0); 

if (error != PI_NOMOREVALUES) { 

printf("Error %ld", error); 

 

} /* end if piar_getarcvalues error */

Enabling Operational Intelligence