FP_MC_PROTOCOL_WRITE

Write data to 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 write 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

Source (ANY)

Word area or register on the master unit for the data to be written to the slave.

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 Source.

Memory area specified in Source

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.

DestMemoryArea (WORD, INT, UINT)

Memory area on the slave to which the data is written.

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
DestMemoryOffset (DWORD, DINT, UDINT)

Offset of the memory area on the slave to which the data is written.

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

Output

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 Source 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 Source 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
		bEnable: BOOL:=FALSE;
		awValues: ARRAY [0..2] OF WORD:=[3(0)];
		diMemoryOffset: DINT:=0;
		iResult: INT:=0;
		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 := 8 ;
        NETWORK_BODY
B(B_VARIN,,iPort,26,2,28,4,);
B(B_VARIN,,abValues,18,3,20,5,);
B(B_VARIN,,SYS_MC_PROTOCOL_MEMORY_AREA_INPUT_X,26,5,28,7,);
B(B_VARIN,,diMemoryOffset,26,6,28,8,);
B(B_VAROUT,,iResult,41,2,43,4,);
B(B_CONTACT,,bEnable,5,1,7,3,);
B(B_F,FP_MC_PROTOCOL_WRITE!,,28,0,41,8,,?DEN?DPort?DSource?DWords_Bits?HDestMemoryArea?DDestMemoryOffset?AENO?CResult);
B(B_F,Size_Of_Var!,,21,4,28,6,,?D?C);
L(1,2,5,2);
L(7,2,28,2);
L(20,4,28,4);
L(21,4,21,5);
L(1,0,1,8);
        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 := 8 ;
        NETWORK_BODY
B(B_VARIN,,iPort,26,2,28,4,);
B(B_VARIN,,awValues,18,3,20,5,);
B(B_VARIN,,SYS_MC_PROTOCOL_MEMORY_AREA_DATA_REGISTER_D,26,5,28,7,);
B(B_VARIN,,diMemoryOffset,26,6,28,8,);
B(B_VAROUT,,iResult,41,2,43,4,);
B(B_CONTACT,,bEnable,5,1,7,3,);
B(B_F,FP_MC_PROTOCOL_WRITE!,,28,0,41,8,,?DEN?DPort?DSource?DWords_Bits?HDestMemoryArea?DDestMemoryOffset?AENO?CResult);
B(B_F,Size_Of_Var!,,21,4,28,6,,?D?C);
L(1,2,5,2);
L(7,2,28,2);
L(20,4,28,4);
L(21,4,21,5);
L(1,0,1,8);
        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_WRITE(Port := iPort,
                         Source := abValues,
                         Words_Bits := Size_Of_Var(abValues), 
                         DestMemoryArea := SYS_MC_PROTOCOL_MEMORY_AREA_INPUT_X,
                         DestMemoryOffset := diMemoryOffset,
                         Result => iResult);
End_if;
(*Word transfer*)
If (bEnable) then
    FP_MC_PROTOCOL_WRITE(Port := iPort,
                         Source := awValues,
                         Words_Bits := Size_Of_Var(awValues), 
                         DestMemoryArea := SYS_MC_PROTOCOL_MEMORY_AREA_DATA_REGISTER_D,
                         DestMemoryOffset := diMemoryOffset,
                         Result => iResult);
End_if;

Modified on: 2022-06-28Feedback on this pagePanasonic hotline