F161_MRCV

Read data from MCU port

Use this instruction to copy the data which the Multi-Communication Unit received from the external device to the CPU's receive buffer. The MCU's communication port is specified at s_Port. The receive buffer is defined by d1_Start and d2_End.

Parameters

Input

s_Port (WORD, INT, UINT)

Specification of slot number (high byte) and port number (low byte) of the MCU to which the data is transmitted.

16#xx01: COM1 on MCU in slot 16#xx

16#xx02: COM2 on MCU in slot 16#xx

d1_Start (WORD, INT, UINT)

Starting address of the receive buffer

d2_End (WORD, INT, UINT)

Ending address of the receive buffer

Remarks

  • Do not execute F161_MRCV unless the end of reception has been verified by evaluating the "reception done" flag. Polling the data using F161_MRCV does not work correctly! The "reception done" flag can be evaluated using the IsReceptionDone and IsReceptionDoneByTimeOut functions or by evaluating the input (X) flags X0 and X2.

  • The number of bytes received is stored in the initial address specified by d1_Start of the receive buffer. If the data received exceeds the ending address specified by b2_End, an operation error is detected. The data which has been received up to d2_End will be stored. F161_MRCV also clears the receive buffer, resets the "reception done flag" and allows further reception of data.

  • F161_MRCV is supported by all PLCs: If suitable functions are used instead of flags, PLC-independent programs can be created which handle communication for CPU communication ports as well as for MCU ports. PLCs not using MCU ports simply do not translate the F161_MRCV instruction. It is recommended to use the functions ReadData or ReadCharacters for a program that is easier to read.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if the area specified using the index modifier exceeds the limit.

  • if the MCU unit does not exist in the specified slot or zero bytes should be sent.

  • if the specified communication port does not exist

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if the area specified using the index modifier exceeds the limit.

  • if the MCU unit does not exist in the specified slot or zero bytes should be sent.

  • if the specified communication port does not exist

Example

POU header

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
		ReadReceivedData: BOOL:=FALSE;
		ReceiveBuffer: ARRAY [0..10] OF INT:=[11(0)];
	END_VAR

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 8 ;
        NETWORK_BODY
B(B_F,F161_MRCV!,,17,2,24,8,,?DEN?Ds_Port?Dd1_Start?Dd2_End?AENO);
B(B_VARIN,,ReadReceivedData,15,3,17,5,);
B(B_VARIN,,16#0201,15,4,17,6,);
B(B_VARIN,,ReceiveBuffer[0],15,5,17,7,);
B(B_VARIN,,ReceiveBuffer[10],15,6,17,8,);
B(B_COMMENT,,The received data of port 1 of the MCU in slot 2 are read:,2,1,32,2,);
L(1,0,1,8);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 6 ;
        NETWORK_BODY
B(B_F,F161_MRCV!,,17,0,24,6,,?DEN?Ds_Port?Dd1_Start?Dd2_End?AENO);
B(B_VARIN,,ReadReceivedData,15,1,17,3,);
B(B_VARIN,,16#0301,15,2,17,4,);
B(B_VARIN,,ReceiveBuffer,6,4,8,6,);
B(B_F,Adr_Of_Var_I!,,10,3,17,5,,?D?C);
B(B_F,AdrLast_Of_Var_I!,,8,4,17,6,,?D?C);
L(1,0,1,6);
L(8,4,8,5);
L(8,4,10,4);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

Modified on: 2022-01-14Feedback on this pagePanasonic hotline