Technical data

Linkage with PLC
174 VIPA GmbH CP486 00/14
6.4.4.5 Write a Block into the PC
int CP_writen_AG(byte size, byte typ, byte bst, unsigned long adr, word len,
void far *p);
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
p: pointer to the data block to be written in the AT-memory
Return: job number $80 or negative number if there is an error
This function calls the driver function "write a block into a 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 $80 (hex) 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 i;
byte buff[100]; /* data to be written */
for(i = 0; i< 100; i++)
buff[i] = (byte)i; /* preset data buffer */
/* start job */
a_nr = CP_writen_AG(B_BLOCK, DB_BLK, 5, 10, 100, &buff);
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, NULL); /* read job status */
} while(stat == REQ_WRKN); /* as long as job is ready with or without errors */
switch(stat) {
case REQ_NO_ERR: printf("data have been written\n", value);
break;
case REQ_UNDEF: printf("job status nondefined\n");
break;
default: printf("job is ready with error: %d\n", stat);
}
}