Function description

On a rising edge at the REQ input, this function block writes a register area from a register area of a device connected via Modbus Plus, TCP/IP Ethernet or SY/MAX-Ethernet, with the content of a register area of the PLC.

EN and ENO can be configured as additional parameters.

CREAD_REG, CWRITE_REG, READ_REG, WRITE_REG, and MBP_MSTR function blocks use one data transaction path and require multiple cycles to complete an operation. The number of transaction paths available by module and by MAST cycle depends on the communication port used:

  • Modbus Plus embedded port or NOM modules support up to 4 blocks at the same time.

  • TCP/IP Ethernet embedded port support up to 4 blocks at the same time.

  • TCP/IP Ethernet NOE, NOC, and 140 CRP 312 00 modules support up to 16 blocks at the same time.

More communication function blocks may be programmed on the same communication port. However, a communication block exceeding the maximum number on that port is not serviced until one of the transaction paths is available. Then, the next block on the same port becomes active and begins using an available path.

NOTE: When programming a WRITE_REG function, you must be familiar with the routing procedures used by your network. Modbus Plus routing path structures are described in detail in the communication architectures manual and the Modbus Plus Network Planning and Installation Guide (Reference 31003525). If TCP/IP or SY/MAX Ethernet routing is implemented, standard Ethernet IP router products must be used.
NOTE: Several copies of this function block can be used in the program. However, multiple instancing of these copies is not possible.

Representation in FBD

Representation:

Representation in LD

Representation:

Representation in IL

Representation:

CAL WRITE_REG_Instance (REQ:=StartWriteOnce,
    SLAVEREG:=OffsetAddress, NO_REG:=NumberOfRegisters,
    REG_WRIT:=SourceDataArea,
    ADDRFLD:=DataStructureForTransfer,
    DONE=>SetAfterWritingData, ERROR=>SetInCaseOfError,
    STATUS=>ErrorCode)

Representation in ST

Representation:

WRITE_REG_Instance (REQ:=StartWriteOnce,
    SLAVEREG:=OffsetAddress, NO_REG:=NumberOfRegisters,
    REG_WRIT:=SourceDataArea,
    ADDRFLD:=DataStructureForTransfer,
    DONE=>SetAfterWritingData, ERROR=>SetInCaseOfError,
    STATUS=>ErrorCode) ;

Parameter description

Description of input parameters:

Parameter

Data type

Meaning

REQ

BOOL

On a rising edge at the REQ input, this function block writes a register area of a device connected via Modbus Plus, TCP/IP Ethernet or SY/MAX-Ethernet, with the content of a register area of the PLC.

SLAVEREG

DINT

Offset address of the first %MW register in the slave to be written to.

NO_REG

INT

Number of addresses to be written from slave

REG_WRIT

ANY

Source data field

(A data structure must be declared as a located variable for the source file.)

ADDRFLD

WordArr5

Data structure transferring the Modbus Plus-address, TCP/IP address or SY/MAX-IP address.

Description of output parameters:

Parameter

Data type

Meaning

DONE

BOOL

Set to 1 for one cycle after writing data.

ERROR

BOOL

Set to 1 for one cycle if an error occurs.

STATUS

WORD

If an error occurs while the function is being executed, an error code remains at this output for one cycle.

Runtime error

For a list of all block error codes and values, see the table of error codes.