Communication functions example
(Original Document)
At a Glance
It is possible to access SDOs using the communication functions READ_VAR and WRITE_VAR
There are 3 possible representations:
FBD representation
The FBD representations of the communication functions are the following:
Ladder representation
The Ladder representations of the communication functions are the following:
IL representation
The communication function syntax is as follows:
ADDM(
IN :=' 0.0.2.2'
)
ST %MW2100:8
LD 50
ST %MW2182 (* timeout 5 secondes *)
LD 2
ST %MW2183 (* Length *)
(* Read the "Vendor ID" object, slave @2, CANopen Network *)
READ_VAR (
ADR := %MW2100:8,
OBJ := 'SDO',
NUM := 16#00011018,
NB := 0,
GEST := %MW2120:4,
RECP := %MW2110:4
)
(* Write the value 16#FFFF, slave @2 ouputs, CANopen Network *)
LD 16#ffff
ST %MW2200
WRITE_VAR (
ADR := %MW2100:8
OBJ := 'SDO',
NUM := 16#00016300,
NB := 0,
EMIS := %MW2200:1,
GEST := %MW2180:4
)
NOTE: The offset parameter must be set to 0.
NOTE: The subindex : index parameter is encoded in a simple word (subindex is the higher byte).
Parameter Description of the WRITE_VAR Function
The following table outlines the various parameters of the WRITE_VAR function:
Parameter
Description
ADDM('r.m.c.node')
Address of the destination entity of the exchange:
  • r: the processor rack number,
  • m: processor slot in the rack (0)
  • c: channel (only use the channel 2 for CANopen),
  • node: identifier of the transmitting device on the CANopen bus.
'SDO'
SDO object type.
subindex:index
Double word or immediate value identifying the CANopen SDO index or subindex:
The most significant word making up the double word contains the sub-index and the least significant word contains the index.
Example: if you use the double word subindex:index:
  • the 16 most significant bits contain the subindex,
  • the 16 least significant bits contain the index.
EMIS
Table of words containing the SDO datum to send (%MW200:2).
The recept buffer of the WRITE_VAR function must be greater than the SDO. The length of a SDO is indicated in device documentation.
GEST
Table of words with 4 inputs (%MW210:4).
Parameter Description of the READ_VAR Function
The following table outlines the various parameters for the READ_VAR function:
Parameter
Description
ADDM('r.m.c.node')
Address of the destination entity of the exchange:
  • r: the processor rack number,
  • m: processor slot in the rack (0)
  • c: channel (only use the channel 2 for CANopen),
  • node: identifier of the destination device on the bus.
'SDO'
SDO object type.
subindex:index
Double word or immediate value identifying the CANopen SDO index or subindex:
The most significant word making up the double word contains the sub-index and the least significant word contains the index.
Example: if you use the double word subindex:index:
  • the 16 most significant bits contain the subindex,
  • the 16 least significant bits contain the index.
GEST
Table of words with 4 inputs (%MW210:4).
RECP
Table of words with at least one input to receive the SDO datum received (%MW200:16).
The recept buffer of the READ_VAR function must be greater than the SDO. The length of a SDO is indicated in device documentation.
Description of control block words
The following table describes the various words of the control block:
Fields
Word
Type
Description
Control byte
0 (least significant)
BYTE
Bit 0 = activity bit
Bit 1 = cancellation bit
Exchange ID
0 (most significant)
BYTE
Single number, identifier of the exchange.
ComState
1 (least significant)
BYTE
0x00 = Exchange completed
0x01 = Time Out
0x02 = User cancelled
0x03 = Incorrect address format
0x04 = Incorrect destination address
0x06 = Incorrect Com Fb parameters
0x07 = Generic transmission interruption
0x09 = Reception buffer is too small
0x0B = No system resources
0xFF = Network exchange detected error
ExchState
1 (most significant)
BYTE
If ComState = 0x00 :
0x00: request treated
0x01: Cannot be treated
0x02: Incorrect response
If ComState = 0xFF
0x07: Generic exchange detected error
0x0B: The destination device has no more resources.
0x0D: The device cannot be reached.
0x2B: SDO exchange detected error
Timeout
2
WORD
Timeout value (x 100 ms)
Length
3
WORD
Length in bytes
Example in ST language
(* read the node 5 SDO, index 1018, subindex 3 *)
if (%M400) then
subindex_index := 16#00031018 ;
%MW1052 := 50; (* timeout 5 secondes *)
READ_VAR(ADDM('0.0.2.5'),'SDO',subindex_index,0,%MW1050:4,%MW1100:2);
%M400:= 0;
end_if;
(* Write the node 31 SDO, index 203C, subindex 2 *)
if (%M401) then
subindex_index := 16#0002203C;
%MW1152 := 50; (* timeout 5 secondes *)
%MW1153 := 2; (* length 2 bytes *)
%MW1200 := 16#03E8; (* value of object *)
WRITE_VAR(ADDM('0.0.2.31'),'SDO',subindex_index,0, %MW1200:1,%MW1150:4);
%M401:= 0;
end_if;