Function Description

The DATA_EXCH function is used to perform data transfers from one device to another with M340, M580 and Premium CPU:

  • data transmission

  • data reception

  • data transmission then reception

NOTE:

The type of request that can be sent is dependent on the type of CPU:

  • On Modicon M340 and M580 CPU, this function can be used to send Modbus requests to another device. Modbus Application Protocol, is described in the http://www.modbus.org web site.

  • On Premium CPU, this function can be used to send UNI-TE requests to another device. For this, it is necessary to make sure the data sent constitutes the entire frame required by the protocol being used.

The additional parameters EN and ENO can be configured.

FBD Representation

Representation:

LD Representation

Representation:

IL Representation

Representation:

LD Address
DATA_EXCH Action, Data_to_Send, Management_Param,
Received_Data

ST Representation

Representation:

DATA_EXCH(Address, Action, Data_to_Send, Management_Param,
Received_Data);

Parameter Description

The following table describes the input parameters:

Parameter

Type

Comment

ADR

ARRAY [0.. 5] OF INT for Premium

ARRAY [0..7] OF INT for Modicon M340 and M580

Address of the destination entity of the exchange. If the Action parameter is send/receive type, broadcast addresses are prohibited.

For Premium CPU:

  • Use the ADDR function.

For Modicon M340 CPU:

  • Use the ADDM function.

  • The destination entity of the exchange is an array of 8 words: %MWx:8.

    %MWx:8: Initialized by the ADDM conversion block.

    %MW0:8:=ADDM(‘0.3.0.0’)

For Modicon M580 CPU:

  • Address of the destination entity of the exchange operation, result of ADDMX function.

TYP

INT

Type of action to perform.

For Premium CPU, the possible values are:

  • 1: transmission followed by await reception (this action is not possible in slave Uni-Telway)

  • 2: transmission only

  • 3: receive mode

For Modicon M340 and M580 CPU, the possible value is:

  • 1: transmission followed by await reception

EMIS

ARRAY [n..m] OF INT

Integer table to be sent to the destination device of the request.

NOTE: Verify that a minimum length of 1 element exists, even if there is no data to send (code 3 for action, for example).
NOTE: Verify that the length of the data to be sent (in bytes) is assigned to the fourth word of the management table before launching the function, in order for this to be correctly executed.

The following table describes the input/output parameters:

Parameter

Type

Comment

GEST

ARRAY [0..3] OF INT

Exchange management table consisting of the following words:

  • Rank 1 word: a word managed by the system and consisting of two bytes:

    • Most significant byte: exchange number

    • Least significant byte: activity bit (rank 0) and cancel bit (rank 1)

      NOTE: The cancel bit is only available for Modicon M340 and M580 PLCs. This is another way to cancel the communication function than using the CANCEL EF.
  • Rank 2 word: a word managed by the system and consisting of two bytes:

    • Most significant byte: operation report

    • Least significant byte: communication report

  • Rank 3 word: a word managed by the user which defines the maximum response time using a time base of 100 ms.

  • Rank 4 word: a word managed by the system which defines the length of the exchange.

For detailed information, refer to section Structure of the Management Parameters.

The following table describes the output parameters:

Parameter

Type

Comment

RECP

ARRAY [n..m] OF INT

Integer table containing the data received during receive mode or a send/receive action. The size of the data received (in bytes) is written automatically by the system in the fourth word of the management table

NOTE: Even if the action is a transmission only, verify that a RECP table exists with a minimum size of 1.

Modicon M340 Services

On Modicon M340 PLCs, the user can encode a private and free protocol in order to send any Modbus request. It offers the possibility on Modbus media to send or receive a free byte string.

The DATA_EXCH EF is useable over all communication ports except for the CANopen port. The limitations for the SendBuffer length are given by the characteristics of the destination port:

The following table describes the length for all communication ports:

Port

Length

Ethernet (NOE or Embedded port)

1 Kb

Modbus

256 bytes

The length of the message to be sent or received is indicated in the fourth word of the management table.

The ADDM conversion block is used to indicate the destination of the request.

See the ADDM function.

NOTE: Specfify TCP.MBS keyword when the DATA_EXCH EF is used for Modbus commands over Ethernet.

All other Ethernet entities are not supported. The DATA_EXCH EF does not manage directly a connection over TCP.

For open user protocol over Modbus, the following syntax is accepted:

  • rack.module - Module server

  • rack.module.channel.device.MBS - Modbus protocol

  • rack.module.channel.device - User protocol

Modicon M340 Service Example

Objective: Write to a single register %MW100, Length := 5

(* REQUEST WRITE SINGLE REGISTER %MW100 Length := 5 *)

(* Data_to_send = Modbus request encoding *)

(* Byte 1 = Register Address Hi = 0 ; Byte 0 = Function code = 06 *)

Data_to_Send[0] := 6;

(* Byte 3 = Register Value Hi ; Byte 2 = Register Address Lo = 100 *)

Data_to_Send[1] := (RegisterValue & 16#FF00) + 100;

(* Byte 5 = unused; Byte 4 = Register Value Lo)

Data_to_Send[2] := RegisterValue & 16#FF;

IF ((Management_Param[ACTIVITY] & 1) = 0 ) THEN

Management_Param[LENGTH] := 5; (* LENGTH RQ WRITE *)

DATA_EXCH (ADDM('0.0.0.1'), 1, Data_To_Send, Management_Param, Received_Data);

END_IF;

NOTE: The MODBUS bus is BIG-ENDIAN and P-UNIT words are LITTLE-ENDIAN. For some queries, perform a conversion.

The ROL instruction can be used:

Value_read := ROL(Received_Data[1], 8); (* CONVERT BIG/LITTLE ENDIAN *)