Write to FIFO buffer
This FP instruction writes the data specified by s into the FIFO buffer specified by d_Start.
Input
Data area or equivalent constant for storing data to write in the FIFO buffer
Output
Starting data area of the buffer
The variables s and d_Start have to be of the same data type.
If this instruction is executed when the FIFO buffer is full (number of stored data = n_Words, the size of the FIFO buffer defined by FP_FIFO_DEFINE), an error occurs and writing is not carried out.
If this instruction is executed when the writing pointer is indicating the final address in the FIFO buffer (n_Words defined by FP_FIFO_DEFINE), the writing pointer will be set to 0.
if the size (n_Words) of the buffer specified by d_Start is n_Words = 0, or when n_Words > 4096.
if the number of stored data items of the buffer = 0.
if the number of stored data items of the buffer > buffer size (n_Words).
if the writing pointer > buffer size (n_Words).
if the writing pointer is 4096 (16#1000) or higher after the data has been written.
if the size (n_Words) of the buffer specified by d_Start is n_Words = 0, or when n_Words > 4096.
if the number of stored data items of the buffer = 0.
if the number of stored data items of the buffer > buffer size (n_Words).
if the writing pointer > buffer size (n_Words).
if the writing pointer is 4096 (16#1000) or higher after the data has been written.
Corresponding F instructions: F117_FIFW
All input and output variables used for programming this function have been declared in the POU header.The same POU header is used for all programming languages.
VAR
bDefineBuffer: BOOL:=FALSE;
bWriteToBuffer: BOOL:=FALSE;
iWords: INT:=8;
arrFifo: ARRAY [0..11] OF INT:=[12(0)];
END_VAR
VAR_EXTERNAL
g_arrValuesWORD: ARRAY [0..7] OF WORD:=[16#0000,16#0001,16#7FFF,16#8000,16#FFFF,16#1234,16#89AB,16#ABCD];
END_VAR
VAR
END_VAR
When the variable bWriteToBuffer is set to TRUE, the function is carried out.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_F,FP_FIFO_DEFINE!,,13,1,22,5,,?DEN?Dn_Words?AENO?Cd_Start);
B(B_VARIN,,iWords,11,3,13,5,);
B(B_VAROUT,,arrFifo[0],22,3,24,5,);
B(B_CONTACT,,bDefineBuffer,5,2,7,4,);
L(7,3,13,3);
L(1,3,5,3);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_F,FP_FIFO_WRITE!,,13,1,22,5,,?DEN?D@'s'?AENO?Cd_Start);
B(B_VARIN,,g_arrValuesWORD[0],11,3,13,5,);
B(B_VAROUT,,arrFifo[0],22,3,24,5,);
B(B_CONTACT,,bWriteToBuffer,5,2,7,4,);
L(7,3,13,3);
L(1,3,5,3);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
END_BODY
if (bWriteToBuffer) then
FP_FIFO_WRITE(s := g_arrValuesWORD[0],
d_Start => arrFifo[0]);
end_if;