Technical data

Linkage with PLC
CP 486 00/14 VIPA GmbH 173
6.4.4.4 Write a Single Element into the PC
int CP_write_AG(byte size, byte type, byte bst, unsigned long adr, byte bit,
void far *p);
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
p: pointer to the date to be written in the AT-memory
for data type bit, semaphore or byte pointer to a byte
for data type word pointer to a word
for data type doubleword pointer to a doubleword
Return job number or negative number is there is an error
This function calls the driver function "write a single element 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 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 = 0x5A; /* value read from the PC */
/* start job */
a_nr = CP_write_AG(LBYTE_ELM, DB_SNG, 10, 1, 0, &wert);
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((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 written\n", value);
break;
case REQ_UNDEF: printf("job status nondefined\n");
break;
default: printf("job is ready with error: %d\n", stat);
}
}