PRVREC (FB)
FUNCTION_BLOCK PRVREC
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 ProvideData
VAR
prvData : CommFB.PRVREC;
data : ARRAY[0..3] OF BYTE := [0,1,2,3]; // some dummy data
END_VAR
// Variant 1: receive data for a specific slot:
prvData.EN := 1;
prvData.F_ID := CommFB.SUBSLOT_ID(EN := TRUE, PN_Device.DeviceID, 2, 1); // get ID of Slot 2 of the specified device
prvData(MODE := CommFB.PRVREC_MODE.RECEIVE_BY_SLOT); // get request
IF prvData.NEW THEN // process record
IF(prvData.SLOT = 1 AND prvData.INDEX = 2) THEN
prvData(MODE := 3, LEN:=4, RECORD := ADR(data)); // pos. response with data
END_IF
END_IF
// Variant 2: check for request, then decide to process it (receive + pos./neg. response)
prvData(MODE := CommFB.PRVREC_MODE.CHECK, F_ID := PN_Device.DeviceID); // get request
IF(prvData.NEW) THEN
// Reject everything else.
// If a request from the host is not confimed by the aplication, the stack may send a neg. response after a timeout.
prvData(MODE := 4, CODE1 := 16#B2);
END_IF
- InOut:
Scope
Name
Type
Comment
Input
ENBOOLEnable
MODEUINTFunction specifier, see PRVREC_MODE
F_IDDWORDSlot / subslot to filter the data records to receive
CODE1BYTEReason for negative response. (see ErrorCode1_RW)
CODE2BYTEReason for negative response. (0 or user specific)
LENUINTLength of a data record to provide
RECORDPOINTER TO BYTE
Provided data record
Output
ENOBOOLFunction enabled
NEWBOOLNew data record requested
STATUSDWORDField Device interface status
SLOTUINTSlot the record is requested for
SUBSLOTUINTSubslot the record is requested for
INDEXUINTIndex of the requested data record
RLENUINTLength of the requested data record