Introduction

Use the DATA_EXCH function block to send a Modbus TCP explicit message to a remote device at a specific IP address to read a single word located in the remote device.

The Management_Param, the Data_to_Send, and the Received_Data parameters define the operation.

EN and ENO can be configured as additional parameters.

Implementing the DATA_EXCH Function Block

To implement the DATA_EXCH function block, create and assign variables for the for following:

Configuring the Address Variable

The Address variable identifies the explicit message originating device and the target device. Note that the Address variable does not include the Xway address elements {Network.Station} because you are not bridging through another PAC station. Use the ADDM function to convert the following character string to an address:

ADDM(‘0.1.0{192.168.1.7}TCP.MBS’), where:

  • rack = 0

  • module (slot number) = 1

  • channel = 0

  • remote device IP address = 192.168.1.7

  • message type = TCP

  • protocol = Modbus

Configuring the ActionType Variable

The ActionType variable identifies the function type for the DATA_EXCH function block:

Variable

Description

Value (hex)

ActionType

Transmission followed by wait for response

16#01

Configuring the DataToSend Variable

The DataToSend variable contains the target register address and the number of registers to read:

Variable

Description

Value (hex)

DataToSend[0]

  • High byte = Most significant byte (MSB) of register address 16#15 (21 decimal)

  • Low byte = function code: 16#03 (03 decimal)

16#1503

DataToSend[1]

  • High byte = Most significant byte (MSB) of the number of registers to read: 16#00 (0 decimal)

  • Low byte = Least significant byte (LSB) of register address: 16#0F (15 decimal)

16#000F

DataToSend[2]

CIP request instance information:

  • High byte = not used: 16#00 (0 decimal)

  • Low byte = Least significant byte (LSB) of the number of registers to read: 16#01 (1 decimal)

16#0001

NOTE: For detailed information about M580 network topologies, refer to the Modicon M580 Standalone System Planning Guide for Frequently Used Architectures and Modicon M580 System Planning Guide for Complex Topologies.

Viewing the Response

Use a Control Expert Animation table to display the ReceivedData variable array. Note that the ReceivedData variable array consists of the entire data buffer.

To display the Modbus TCP response, follow these steps:

Step

Action

1

In Control Expert, select Tools > Project Browser.

2

In the Project Browser, select the Animation Tables folder, and click the right mouse button.

Result: A pop-up menu appears.

3

Select New Animation Table in the pop-up menu.

Result: A new animation table and its properties dialog open.

4

In the Properties dialog, edit the following values:

Name

Type in a table name. For this example: ReceivedData.

Functional module

Accept the default <None>.

Comment

(Optional) Type your comment here.

Number of animated characters

Type in 100, representing the size of the data buffer in words.

5

Click OK to close the dialog.

6

In the animation table’s Name column, type in the name of the variable assigned to the databuffer: ReceivedData and press Enter.

Result: The animation table displays the ReceivedData variable.

7

Expand the ReceivedData variable to display its word array, where you can view the CIP response contained in the ReceivedData variable.

NOTE: Each array entry presents 2 bytes of data in little endian format. For example, ‘03’ in word[0] is the low byte, and ‘02’ is the high byte.