RCVREC
(FB)
FUNCTION_BLOCK RCVREC
Note
The application program of the Field Device shall acknowledge the received request, otherwise the Host Controller will get a timeout error or the device stack will send a negative response.
Code-Example
PROGRAM ReceiveData
VAR
recvData: CommFB.RCVREC;
data : ARRAY [0..64] OF BYTE;
recvAll: CommFB.RCVREC;
param1 : ARRAY [0..7] OF BYTE;
param2 : ARRAY [0..7] OF BYTE;
END_VAR
// Variant 1: receive data for a specific slot:
recvData.EN := 1;
recvData.F_ID := CommFB.SUBSLOT_ID(EN := TRUE, PN_Device.DeviceID, 2, 1); // get ID of Slot 2 of the specified device
recvData.MLEN := SIZEOF(data);
recvData.RECORD := ADR(data);
recvData (MODE := CommFB.RCVREC_MODE.RECEIVE_BY_SLOT); // receive data and write it to RECORD
IF recvData.NEW THEN
IF(recvData.INDEX = 10) THEN
// ...process and opt. check received data
recvData(MODE := CommFB.RCVREC_MODE.POS_RESPONSE); // send pos. response to host
ELSE
recvData(MODE := CommFB.RCVREC_MODE.NEG_RESPONSE, CODE1 := CommFB.ErrorCode1_RW.Invalid_index); // signal error to host
END_IF
END_IF
// Variant 2: check for any request and then (opt.) receive it in a second step
// MODE := 0 = CommFB.RCVREC_MODE.CHECK
// MODE := 1 = CommFB.RCVREC_MODE.RECEIVE
// MODE := 3 = CommFB.RCVREC_MODE.POS_RESPONSE
// MODE := 4 = CommFB.RCVREC_MODE.NEG_RESPONSE
recvAll(EN := TRUE, MODE := 0); // check for new data
IF(recvAll.NEW) THEN // received data
IF(recvAll.SLOT = 1 AND recvAll.INDEX = 100) THEN
recvAll(MODE := 1, MLEN := SIZEOF(param1), RECORD := ADR(param1)); // get data
recvAll(MODE := 3); // pos. response
ELSIF(recvAll.SLOT = 3 AND recvAll.INDEX = 200) THEN
recvAll(MODE := 1, MLEN := SIZEOF(param2), RECORD := ADR(param2)); // get data
recvAll(MODE := 3); // pos. response
ELSE
recvAll(MODE := 4, CODE1 := CommFB.ErrorCode1_RW.Invalid_slot_or_subslot); // signal error to host
END_IF
END_IF
- InOut:
Scope
Name
Type
Comment
Input
EN
BOOL
The function is invoked by EN=1.
MODE
UINT
Function specifier, see RCVREC_MODE
F_ID
DWORD
Slot / subslot to filter the data records to receive
MLEN
UINT
Maximum length of a data record to receive
CODE1
BYTE
Reason for negative response. (see ErrorCode1_RW)
CODE2
BYTE
Reason for negative response. (0 or user specific)
RECORD
POINTER TO BYTE
Received data record. Shall be at least of MLEN byte
Output
ENO
BOOL
Function enabled
NEW
BOOL
New data record received
STATUS
DWORD
Field Device interface status
SLOT
UINT
Slot the record is received for
SUBSLOT
UINT
Subslot the record is received for
INDEX
UINT
Index of the received data record
LEN
UINT
Length of the received data record