Technical data

Linkage with PLC
CP 486 00/14 VIPA GmbH 159
6.4.3.3 Read a Block from the PC
FUNCTION CP_readn_AG(size, typ, bst:BYTE; adr:longint; len:WORD):integer;
size: data size of block elements (see Tab.4)
typ: data type of block elements (see Tab. 3)
bst: module number
adr: address in module or absolute address
len: number of data in words
Return: job number 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).
VAR a_nr, (* job number for read job*)
stat : INTEGER; (* momentaneous job status *)
buff : ARRAY[1..50 ] OF INTEGER (* data read from the PC *)
BEGIN
(* start job *)
a_nr := CP_readn_AG(W_BLOCK, DB_BLK, 5, 10, 100);
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(buf)); (* 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(buffer was read');
REQ_UNDEF: WriteLn('job status nondefined, buffer was read');
ELSE WriteLn('job is ready with error: ', stat);
END;
END;