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
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 |
---|---|---|
|
ARRAY [0.. 5] OF ARRAY [0..7] OF |
Address of the destination entity
of the exchange. If the For Premium CPU:
For Modicon M340 CPU:
For Modicon M580 CPU:
|
|
|
Type of action to perform. For Premium CPU, the possible values are:
For Modicon M340 and M580 CPU, the possible value is:
|
|
ARRAY [n..m] OF |
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 |
---|---|---|
|
ARRAY [0..3] OF |
Exchange management table consisting of the following words:
For detailed information, refer to section Structure of the Management Parameters. |
The following table describes the output parameters:
Parameter |
Type |
Comment |
---|---|---|
|
ARRAY [n..m] OF |
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:
|
|
---|---|
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.
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:
- Module server
- Modbus protocol
- 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 *)
END_IF;
The ROL instruction can be used:
Value_read := ROL(Received_Data[1], 8); (* CONVERT BIG/LITTLE ENDIAN *)