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
ENBOOLThe function is invoked by EN=1.
MODEUINTFunction specifier, see RCVREC_MODE
F_IDDWORDSlot / subslot to filter the data records to receive
MLENUINTMaximum length of a data record to receive
CODE1BYTEReason for negative response. (see ErrorCode1_RW)
CODE2BYTEReason for negative response. (0 or user specific)
RECORDPOINTER TO BYTE
Received data record. Shall be at least of MLEN byte
Output
ENOBOOLFunction enabled
NEWBOOLNew data record received
STATUSDWORDField Device interface status
SLOTUINTSlot the record is received for
SUBSLOTUINTSubslot the record is received for
INDEXUINTIndex of the received data record
LENUINTLength of the received data record