Here’s what more than 2,500 business decision-makers around the world say.Download the report
...with the Facility Hero app in hand! Discover how you can optimize your maintenance efforts today.Learn more
Access tailored services, 24/7 self-service and expert help. Anywhere, anytime, any project.Discover now
Everything you need to know about our IoT technology backbone.Learn more
Explore our global offerings or select your country from one of our five regions.Global
Découvrez nos offres globales ou sélectionnez votre pays dans l’une de nos cinq régions.
Goals and Symptoms
To use the DATA_EXCH FB in Unity Pro to issue a modbus function code 4 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#0004) the 2 bytes are 00 (high byte) and 04 (low byte). The low byte (04) is the MB function code. 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 input registers to read.
The last word only the low byte( 04) is used and this is the rest of the of the number of input registers to read in the slave.
If you look at the 5 bytes (in Hex) individually you get: 04 00 01 00 04
04 = MB function code 4
00001 = 1 decimal (%IW1 or 30001)
04 = Number of Input registers to read
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 5.
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 192.168.40.45.
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.