Technical data

Linkage with PLC
158 VIPA GmbH CP486 00/14
6.4.3.2 Read a Single Element from the PC
FUNCTION CP_read_AG(size, typ, bst : BYTE; adr : longint; bit : BYTE) : INTEGER;
size: data size of single elements (see Tab. 1)
typ: data type for single elements (see Tab. 2)
bst: module number
adr: address in the 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).
VAR a_nr, (* job number for read job *)
stat : INTEGER; (* momentaneous job status *)
wert : BYTE; (* value read from the PC *)
BEGIN
(* start job *)
a_nr := CP_read_AG(LBYTE_ELM, DB_SNG, 10, 1, 0);
IF a_nr < 0 (* error occurred *)
THEN WriteLn('job finished with error: ', a_nr);
ELSE BEGIN (* a_nr contains job number *)
REPEAT
stat := CP_stat_AG(a_nr, Addr(value)); (* job status/fetch data *)
UNTIL stat <> REQ_WRKN; (* as long as job is ready with or without errors *)
CASE stat OF
REQ_NO_ERR: WriteLn('date: ', value, ' has been read');
REQ_UNDEF: WriteLn('job status nondefined,date: ',value, ' read');
ELSE WriteLn('job is ready with error: ', stat);
END;
END;