Technical data

Linkage with PLC
CP 486 00/14 VIPA GmbH 171
6.4.4.2 Read a Single Element from the PC
int CP_read_AG(byte size, byte typ, byte bst, unsigned long adr, byte bit);
size: data size (see Tab. 1)
typ: data type single elements (see Tab. 2)
bst: module number
adr: address in module or absolute address
bit: bit number
Return: job number or negative number if there is an error
This function calls the driver function "read a single element 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 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) */
byte wert ; /* value read from the PC */
/* start job */
a_nr = CP_read_AG(LBYTE_ELM, DB_SNG, 10, 1, 0);
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, &wert); /* 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("date: %d was read\n", wert);
break;
case REQ_UNDEF: printf("job status nondefined, date: %d read\n", wert);
break;
default: printf("job is ready with error: %d\n", stat);
}
}