FP_WRITE_TO_SLAVE

Write data to slave

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. If the slave data is not available in the user area of the master, use FP_WRITE_TO_SLAVE_AREA_OFFS or FP_MODBUS_MASTER.

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

Parameters

Input

Port (WORD, INT, UINT)

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-255)

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.

Output

SlaveAddress(ANY)

Destination address on the slave to which the requested data is written.

Result(ANY)
  • For FP7 only:
    • 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

  • 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) Response reception processing

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

Global variables

In the global variable list you define variables that can be accessed by all POUs in the project.

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
	VAR 
		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*)
		bSetParameters: BOOL:=FALSE;
	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_F,FP_WRITE_TO_SLAVE!,,19,0,30,6,,?DEN?DnPort?DStationNumber?DSource?AENO?CSlaveAddress?CResult);
B(B_VARIN,,SYS_COM2_PORT,17,2,19,4,);
B(B_VARIN,,iSlaveStationNumber,17,3,19,5,);
B(B_VARIN,,arrParameters,17,4,19,6,);
B(B_VAROUT,,g_Peripherie_SlaveParameter_Address,30,2,32,4,);
B(B_VAROUT,,wWriteToSlaveResult,30,3,32,5,);
B(B_CONTACT,,bSetParameters,4,1,6,3,);
L(1,2,4,2);
L(6,2,19,2);
L(1,0,1,6);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

if bSetParameters then
    FP_WRITE_TO_SLAVE(Port := SYS_COM2_PORT, 
                   StationNumber := iSlaveStationNumber, 
                   Source := arrParameters, 
                   SlaveAddress => g_Peripherie_SlaveParameter_Address, 
                   Result => wWriteToSlaveResult);
end_if;

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