Technical data

Linkage with PLC
172 VIPA GmbH CP486 00/14
6.4.4.3 Read a Block from the PC
int CP_readn_AG(byte size, byte typ, byte bst, unsigned long adr, word len);
size: data size of block elements (see Tab.4)
typ: data type block elements (see Tab. 3)
bst: module number
adr: address in module or absolute address
len: number of data in words
Return: job number 0 or negative number if there is an error
This function calls the driver function "read a block from the PC". The registers are preset according
to the transferred parameters when calling up. Meaning of the parameters is described in the section
of driver function. If the driver has detected an error during the execution, then the respective error
message (negative number) is returned as function value. If the function can be executed without
errors, the job number 0 is returned as function value.
Recommended calling method
To process correctly driver functions, the following scheme should be adhered when executing
functions. Otherwise the bank, for example, can be blocked (cf. sections about driver functions).
int a_nr; /* job number for read job*/
int stat; /* momentaneous job status */
int time_count=4000; /* timeout counter (4 seconds) */
int buff[100] ; /* value read from the PC */
/* start job */
a_nr = CP_readn_AG(W_BLOCK, DB_BLK, 5, 10, 100);
if(a_nr < 0) /* error occurred */
printf("job finished with error: %d\n", a_nr);
else { /* a_nr contains job number */
do {
stat = CP_stat_AG(a_nr, &buff); /* job status/fetch data */
} while((time_count > 0)&&(stat == REQ_WRKN));
/* as long as job is ready with or without errors */
switch(stat) {
case REQ_NO_ERR: printf("Data have been readed\n", value);
break;
case REQ_UNDEF: printf("job status nondefined\n");
break;
default: printf("job is ready with error: %d\n", stat);
}
}