FP_MC_PROTOCOL_READ

Read data from external devices via MC protocol

The PLC has the transmission right in the master communication. The communication is performed by sending commands to devices which support MC protocol and receiving responses. By specifying a memory address and executing a read instruction in a user program, the PLC generates a message according to the protocol automatically.

Parameters

Input

Port (WORD, INT, UINT)

Ethernet port e.g. SYS_ETHERNET_USER_CONNECTION_1

SourceMemoryArea (WORD, INT, UINT)

Memory area on the slave from where to request the data.

Unit

Memory area type

System variable

Bit

Input

X

Hexadecimal

SYS_MC_PROTOCOL_MEMORY_AREA_INPUT_X

Output

Y

Hexadecimal

SYS_MC_PROTOCOL_MEMORY_AREA_OUTPUT_Y

Link relay

B

Hexadecimal

SYS_MC_PROTOCOL_MEMORY_AREA_LINK_RELAY_B

Internal relay

M

Decimal

SYS_MC_PROTOCOL_MEMORY_AREA_INTERNAL_RELAY_M

Latch relay

L

Decimal

SYS_MC_PROTOCOL_MEMORY_AREA_LATCH_RELAY_L

Word

Data register

D

Decimal

SYS_MC_PROTOCOL_MEMORY_AREA_DATA_REGISTER_D

File register

R

Decimal

SYS_MC_PROTOCOL_MEMORY_AREA_FILE_REGISTER_R

ZR

Hexadecimal

SYS_MC_PROTOCOL_MEMORY_AREA_FILE_REGISTER_ZR

Link register

W

Hexadecimal

SYS_MC_PROTOCOL_MEMORY_AREA_LINK_REGISTER_W

SourceMemoryOffset (DWORD, DINT, UDINT)

Offset of the memory area on the slave from where to request the data.

Range: 16#016#F7FFFF (0–16252927)

Words_Bits (WORD, INT, UINT)
  • Specify the number of received data. The number of received data is in word unit for the word transmission and in bit unit for the bit transmission (depending on the data type applied to the input Words_Bits)

  • The transfer method and the number of sent data specified by Words_Bits vary according to the data type of Destination.

Memory area specified in Destination

Transfer method

No. of sent data Words_Bits

Remarks

16-bit memory area

WX, WY, WR, WL, DT, LD

Word transmission

1–960 words

1-bit memory area

X,Y,R,L,DT,n,LD,n

Bit transmission

1–7168 bits

When the number of sent data is odd, 4-bit dummy code 16#0 is added.

Output

Destination (ANY)

Word area or register on the master unit to which the requested data is written.

Result (WORD, INT, UINT)

Specify the memory area of the master unit storing the execution result code (1 word in the area WX, WY, XR, WL, DT, LD)

  • 0: Normal completion

  • 1: Communication port is used for master communication

  • 2: Communication port is used for slave communication

  • 3: No. of master communication instructions that can be used at the same time is exceeded

  • 4: Sending timeout

  • 5: Response reception timeout

  • 6: Received data error

Time chart

  1.  (1) Master communication clear-to-send flag,e.g. sys_bIsEthernetUserConnection1MasterCommunication
  2.  (2) Check that the master communication clear-to-send flag is TRUE and check that the master communication sending flag is FALSE
  3.  (3) Master communication sending flag, e.g. sys_bIsEthernetUserConnection1MasterCommunicationActive

    While sending: Master communication sending flag is TRUE

    Sending done: Master communication sending flag is FALSE

  4.  (4) Execute this instruction
  5.  (5) Master communication sending done flag, e.g. sys_bIsEthernetUserConnection1CommunicationError

    Normal completion: FALSE

    Abnormal completion: TRUE

  6.  (6) Send data
  7.  (7) Response reception processing

Error flags

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

  • if a value specified for a parameter is outside the permissible range.

  • if Ethernet port is incorrect or Ethernet port is closed.

  • if the number of sent data specified by Words_Bits is incorrect.

  • if the word area or register on the master unit specified by Destination is incorrect or outside the permissible range.

  • if the memory area in which the execution result code is stored is incorrect.

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

  • if a value specified for a parameter is outside the permissible range.

  • if Ethernet port is incorrect or Ethernet port is closed.

  • if the number of sent data specified by Words_Bits is incorrect.

  • if the word area or register on the master unit specified by Destination is incorrect or outside the permissible range.

  • if the memory area in which the execution result code is stored is incorrect.

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
		diMemoryOffset: DINT:=0;
		awValues: ARRAY [0..2] OF WORD:=[3(0)];
		iResult: INT:=0;
		bEnable: BOOL:=FALSE;
		abValues: ARRAY [0..2] OF BOOL:=[3(FALSE)];
		iPort: INT:=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 := 6 ;
        NETWORK_BODY
B(B_COMMENT,,Bit transfer,2,0,10,1,);
B(B_COMMENT,,Memory Areas:	SYS_MC_PROTOCOL_MEMORY_AREA_INPUT_X ^SYS_MC_PROTOCOL_MEMORY_AREA_OUTPUT_Y ^SYS_MC_PROTOCOL_MEMORY_AREA_LINK_RELAY_B ^SYS_MC_PROTOCOL_MEMORY_AREA_INTERNAL_RELAY_M ^SYS_MC_PROTOCOL_MEMORY_AREA_LATCH_RELAY_L,13,0,39,6,);
L(1,0,1,6);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 7 ;
        NETWORK_BODY
B(B_VARIN,,iPort,26,2,28,4,);
B(B_VAROUT,,abValues,41,2,43,4,);
B(B_VARIN,,SYS_MC_PROTOCOL_MEMORY_AREA_INPUT_X,26,3,28,5,);
B(B_VARIN,,diMemoryOffset,26,4,28,6,);
B(B_VAROUT,,iResult,41,3,43,5,);
B(B_CONTACT,,bEnable,5,1,7,3,);
B(B_F,FP_MC_PROTOCOL_READ!,,28,0,41,7,,?DEN?DPort?HSourceMemoryArea?DSourceMemoryOffset?DWords_Bits?AENO?CDestination?CResult);
B(B_F,Size_Of_Var!,,21,5,28,7,,?D?C);
B(B_VARIN,,abValues,19,5,21,7,);
L(7,2,28,2);
L(1,2,5,2);
L(1,0,1,7);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_COMMENT,,Memory Areas:	 ^SYS_MC_PROTOCOL_MEMORY_AREA_DATA_REGISTER_D ^SYS_MC_PROTOCOL_MEMORY_AREA_FILE_REGISTER_R ^SYS_MC_PROTOCOL_MEMORY_AREA_FILE_REGISTER_ZR ^SYS_MC_PROTOCOL_MEMORY_AREA_LINK_REGISTER_W,13,0,39,5,);
B(B_COMMENT,,Word Transfer,2,0,10,1,);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 7 ;
        NETWORK_BODY
B(B_VARIN,,iPort,26,2,28,4,);
B(B_VAROUT,,awValues,41,2,43,4,);
B(B_VARIN,,SYS_MC_PROTOCOL_MEMORY_AREA_DATA_REGISTER_D,26,3,28,5,);
B(B_VARIN,,diMemoryOffset,26,4,28,6,);
B(B_VAROUT,,iResult,41,3,43,5,);
B(B_CONTACT,,bEnable,5,1,7,3,);
B(B_F,FP_MC_PROTOCOL_READ!,,28,0,41,7,,?DEN?DPort?HSourceMemoryArea?DSourceMemoryOffset?DWords_Bits?AENO?CDestination?CResult);
B(B_F,Size_Of_Var!,,21,5,28,7,,?D?C);
B(B_VARIN,,awValues,19,5,21,7,);
L(1,2,5,2);
L(7,2,28,2);
L(1,0,1,7);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_COMMENT,,only valid for ethernet ports! ^--> Valid Ports:	SYS_ETHERNET_USER_CONNECTION_1 - SYS_ETHERNET_USER_CONNECTION_216,3,1,52,4,);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

(*Bit transfer*)
If (bEnable) then
    FP_MC_PROTOCOL_READ(Port := iPort,
                        SourceMemoryArea := SYS_MC_PROTOCOL_MEMORY_AREA_INPUT_X,
                        SourceMemoryOffset := diMemoryOffset, 
                        Words_Bits := Size_Of_Var(abValues),
                        Destination => abValues, Result => iResult);
End_if;
(*Word transfer*)
If (bEnable) then
    FP_MC_PROTOCOL_READ(Port := iPort,
                        SourceMemoryArea := SYS_MC_PROTOCOL_MEMORY_AREA_DATA_REGISTER_D,
                        SourceMemoryOffset := diMemoryOffset, 
                        Words_Bits := Size_Of_Var(awValues),
                        Destination => awValues, Result => iResult);
End_if;

Modified on: 2022-03-02Feedback on this pagePanasonic hotline