FP_WRITE_TO_SLAVE_AREA_OFFS

Write data to slave with offset

Use this instruction to write data from a master to a slave via the communication port using the MEWTOCOL-COM or Modbus RTU protocol, as defined in the system registers of the port used. Make sure the same protocol is set for master and slave. Master and slave must have matching memory areas.

For data transmissions using the Modbus protocol, the compiler generates Modbus commands based on the Modbus reference numbers.

Parameters

Input

Port (INT)

Specifies the communication ports depending on the PLC type:

  • COM port e.g. SYS_COM0_PORT

  • Ethernet port e.g. SYS_ETHERNET_USER_CONNECTION_1

  • MCU/SCU e.g. 16#xx01 (xx = slot number) in COM01

StationNumber (WORD, INT, UINT)

Station number of the slave (MEWTOCOL: 1–99,MODBUS: 1–247)

Set to 1, if a SYS_ETHERNET_USER_CONNECTION_xx is applied to input Port

Source (WORD, INT, UINT)

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

Words_Bits (WORD, INT, UINT)

Number of words (bits) to be transmitted.

Either:

  • Number of words

    for Modbus RTU: 16#001–16#07F

    for MEWTOCOL-COM: 16#001–16#1FD or 16#001–16#1B (FP0, FP-e)

Or:

  • Control word for bit transfer: 16#8T0F with T as "to bit" in the master and F as "from bit" in the slave (does not apply to FP7).

SlaveMemoryArea (WORD, INT, UINT)

Memory area on the slave where to store the data (destination = SlaveMemoryArea + SlaveMemoryOffset).

Flag memory areas

SYS_MEMORY_AREA_R

SYS_MEMORY_AREA_L

SYS_MEMORY_AREA_X

SYS_MEMORY_AREA_Y

Flags

SYS_MEMORY_AREA_WR

Set value timer/counter

SYS_MEMORY_AREA_SV

Elapsed value timer/counter

SYS_MEMORY_AREA_EV

Data registers

SYS_MEMORY_AREA_DT

Link flags

SYS_MEMORY_AREA_WL

Link registers

SYS_MEMORY_AREA_LD

File registers

SYS_MEMORY_AREA_FL

Input registers

SYS_MEMORY_AREA_WX

Output registers

SYS_MEMORY_AREA_WY

SlaveMemoryOffset (WORD, INT, UINT)

Offset of the memory area where to store the data in the slave (destination = SlaveMemoryArea + SlaveMemoryOffset).

Output

Result (WORD, INT, UINT)

For FP7 only: For a description of all error codes, please refer to the table of Modbus/MEWTOCOL communication error codes.

For other PLCs: set to 0

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) Processing of the received response

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • If slave or master data exceed the available address range.
  • If the communication mode is not set to MEWTOCOL-COM Master/Slave or Modbus RTU Master/Slave.
  • If the COM port selected requires a communication cassette that has not been installed.
sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • If slave or master data exceed the available address range.
  • If the communication mode is not set to MEWTOCOL-COM Master/Slave or Modbus RTU Master/Slave.
  • If the COM port selected requires a communication cassette that has not been installed.

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
		bSetParameters: BOOL:=FALSE;
		wWriteToSlaveResult: WORD:=0;
			(*result of write to slave instruction*)
		iSlaveStationNumber: INT:=0;
			(*slave station number*)
		arrParameters: ARRAY [0..15] OF DINT;
			(*Array of parameters to be send to slave station*)
		iSlaveMemoryOffset: INT:=100;
		bBool: BOOL:=FALSE;
	END_VAR
	VAR CONSTANT 
		iSlaveMemoryArea_Bool: INT:=10000;
			(*memory Area in slave station*)
		iSlaveMemoryArea_Word: INT:=5;
			(*memory Area in slave station*)
	END_VAR
	VAR 
	END_VAR

POU body

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 9 ;
        NETWORK_BODY
B(B_VARIN,,SYS_COM1_PORT,18,2,20,4,);
B(B_VARIN,,iSlaveStationNumber,18,3,20,5,);
B(B_VARIN,,arrParameters,11,4,13,6,);
B(B_CONTACT,,bSetParameters,4,1,6,3,);
B(B_VAROUT,,wWriteToSlaveResult,36,2,38,4,);
B(B_F,Size_Of_Var!,,13,5,20,7,,?D?C);
B(B_F,FP_WRITE_TO_SLAVE_AREA_OFFS!,,20,0,36,9,,?DEN?DnPort?DStationNumber?DSource?DWords_Bits?HSlaveMemoryArea?DSlaveMemoryOffset?AENO?CResult);
B(B_VARIN,,SYS_MEMORY_AREA_DT,18,6,20,8,);
B(B_VARIN,,iSlaveMemoryOffset,18,7,20,9,);
L(13,5,13,6);
L(1,2,4,2);
L(13,5,20,5);
L(6,2,20,2);
L(1,0,1,9);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

if (bSetParameters) then
    FP_WRITE_TO_SLAVE_AREA_OFFS(Port := SYS_COM1_PORT, 
                                StationNumber := iSlaveStationNumber, 
                                Source := arrParameters[0], 
                                Words_Bits := Size_Of_Var(arrParameters[0]), 
                                SlaveMemoryArea := SYS_MEMORY_AREA_DT, 
                                SlaveMemoryOffset := iSlaveMemoryOffset, 
                                Result => wWriteToSlaveResult);
end_if;

Modified on: 2024-10-16Feedback on this pagePanasonic hotline