Browse FAQs

Using the DATA_EXCH block to issue a function code 15 (Write multuiple coils) from a M340 Ethernet interface.

Published date: 31 July 2019

Goals and Symptoms

To use the DATA_EXCH FB in Unity Pro to issue a modbus function code 15 from a Ethernet interface in a M340 PLC system.

Facts and Changes

A minimum version of Unity Pro v4.0 and a M340 CPU or NOE v2.0 must be used for the DATA_EXCH to work properly.

Causes and Fixes

First open the Project Settings form the tools menu in Unity Pro.

Under the Language Extensions tab check off directly represent array variables, Allow dynamic arrays, and disable array size compatibility check.
Then press OK.

Next open the variable editor and create the variables for the DATA_EXCH block

In this example 4 registers will be read from starting input register %IW1 (30001) of slave device connected via MB TCP/IP. This information is shown above in the bytes of the EMIS_PARA variable.

Explanation of the EMIS_PARA variable

To understand the setup of this array you must take each byte of each word separately.
In the first word (16#000F) the 2 bytes are 00 (high byte) and 0F (low byte). The low byte (0F) is the MB function code 15. The high byte (00) is the first part of the starting address in the slave device.
In the second word (16#0001) the low byte (01) is the rest of the starting address in the slave and the high byte (00) is the start of the number of coils to write.
The next word has the low byte of the number of coils to write (04) is used and next is the Number of bytes to send and the appropriate data.

If you look at the 7 bytes (in Hex) individually you get: 0F 00 01 00 04 01 0A

0F = MB function code 15
00001 = 1 decimal (%M1 or 00001)
0004 = Number of coils to write
01 - one byte to write
0A - 0000 1010 (Data to write)

The last thing to mention here is that the forth word of the management parameter (Manage_PARA) is equal to the size in bytes of the transmitted data. In this case 7.

Now create a new FBD section in Unity Pro and press OK.

Add a ADDM and DATA_EXCH block and link the parameters as follows.

Note: In a M340 the TYP parameter is always a 1
The string input for the ADDM block must be chosen to meet the requirements of your network. An explanation of the syntax of this input can be found in the Unity help files.
In this example %M0 is used to trigger the function code 6 and the slave device is located at

Build and download to the M340.

Open a animation table and trigger %M0. You should see the RECP parameter (RECIEVE_DATA) values. The first register contains the function code used in request in the low byte (04) and in the high byte the number of bytes returned in the responce (08). Then the following four registers contain the data.
Also the first word of the Management parameter should also be changing while the block is enabled. This indicates successful transmissions.


Was this helpful?

What can we do to improve the information ?

Can't find what you are looking for?

Reach out to our customer care team to receive information on technical support, assistance for complaints and more.