CANopen Demo For The CM Module
CANopen Demo For The CM Module
CM CANopen
Description of the CANopen demo
HMS Technology Center Ravensburg GmbH
Helmut-Vetter-Straße 2
88213 Ravensburg
Germany
Support
In case of unsolvable problems with this product or other HMS products
please contact HMS in written form:
Copyright
Duplication (copying, printing, microfilm or other forms) and the electronic
distribution of this document is only allowed with explicit permission of HMS
Technology Center Ravensburg GmbH. HMS Technology Center
Ravensburg GmbH reserves the right to change technical data without
prior announcement. The general business conditions and the regulations
of the license agreement do apply. All rights are reserved.
Registered trademarks
All trademarks mentioned in this document and where applicable third
party registered are absolutely subject to the conditions of each valid label
right and the rights of particular registered proprietor. The absence of
identification of a trademark does not automatically mean that it is not
protected by trademark law.
1 Introduction .................................................................................... 7
1.1 Restrictions ............................................................................. 8
1.2 Related Documents ................................................................ 8
2 Hardware identifier of the CM module .......................................... 9
2.1 TIA Portal V11 / V12 ................................................................ 9
2.2 TIA Portal V13........................................................................ 10
2.3 TIA Portal V14........................................................................ 12
2.4 TIA Portal V15........................................................................ 14
3 Overview of the CANopen demo ................................................. 15
4 Exchange of process image data ............................................... 16
4.1 General hints ......................................................................... 16
4.2 Get Process Data In .............................................................. 18
4.2.1 Layout of the Process Image ................................................. 19
4.2.2 Hardware Configuration of the CM module in TIA Portal ....... 22
4.2.3 Description of the used structure ........................................... 22
4.2.4 Upload and update of the process image input data ............. 23
4.2.4.1 ProcessImageData [DB14] ....................................... 23
4.2.4.2 GetProcessDataIn [FC1] .......................................... 24
4.2.4.3 UpdatePIInData_PLC [FC2] ..................................... 25
4.2.5 Adaption of the demo to the user`s application...................... 25
4.3 Set Process Data Out ........................................................... 26
4.3.1 Layout of the Process Image ................................................. 27
4.3.2 Hardware Configuration of the CM module in TIA Portal ....... 29
4.3.3 Description of the used structure ........................................... 30
4.3.4 Download of the process image output data .......................... 30
4.3.4.1 ProcessImageData [DB14] ....................................... 31
4.3.4.2 SetProcessDataOut [FC3] ........................................ 31
4.3.4.3 UpdatePIOutData_CM [FC4] ................................... 33
4.3.5 Adaption of the demo to the user`s application...................... 33
5 SDO commands ........................................................................... 34
5.1 General hint ........................................................................... 34
5.1.1 Processing of a SDO command ............................................. 34
5.1.2 Data format ............................................................................ 35
5.1.3 Parallel processed SDO commands ...................................... 38
5.1.4 Application note “CANopen manager” mode ......................... 39
Copyright HMS Technology Center 3 CM CANopen, CANopen Application, V1.0
Ravensburg GmbH
Content
1 Introduction
The demo explains how to communicate with one CM CANopen running in
CANopen mode to exchange process image data, to process SDO Read / Write
and to process Get Node & Network Status.
The demo must be enhanced if the PLC shall communicate with several CM
CANopen modules running in CANopen mode.
1.1 Restrictions
The CM CANopen supports CAN 2.0A (11 bit CAN identifier) but it does not
support CAN 2.0B (29 bit CAN identifier).
Hint:
The CM CANopen may lose CAN frames received from the CAN bus if the used
CAN baudrate is higher than 250kBaud.
Alternatively:
TIA Portal V14 also provides a system constant that is provided by:
hardware configuration of the CM CANopen module / System constants
Alternatively:
TIA Portal V14 also provides a system constant that is provided by:
PLC tags / Show all tags / System constants
Device configuration:
Description of OB 1:
Network 1:
processing of a “Get Node & Network Status” command
Network 2:
upload of process image input data
Network 3:
download of process image output data
Network 4 - 6:
processing of a SDO Read command
Network 7 - 9:
processing of a SDO Write command
Exchange of process image data between the PLC and the CM CANopen:
The process image data are not exchanged via the process image area
of the PLC.
The process image of the CM CANopen is organized as a byte array
which is read by RDREC / written by WRREC.
WRREC / RDREC request the transmission of an asynchronous
telegram:
the transmission of the asynchronous telegram is not deterministic
it must be avoided that the read / written data will be corrupted
it is recommended to differentiate between the data that are
exchanged with the CM CANopen and the data that are used by
the application to control the process
Data format of the exchanged data between the PLC and the CM CANopen:
The data format is little endian (CANopen format)
least significant byte at low address
most significant byte at high address
whereas the data format of the PLC is big endian
most significant byte at low address
least significant byte at high address
16 bit values / 32 bit values must be swapped
hint: REAL
REAL variables requires an individual conversion
SWAP(real value) does not return the correct value sometimes
suggested method:
1. convert read data to DWORD
2. swap DWORD value
3. convert DWORD value to REAL
Performance:
The best performance is reached
process image input
CANopen input data size = MLEN = actual size
CANopen input data size:
=> hardware configuration of the CM module in TIA Portal
=> Module parameters
=> CANopen input data size
MLEN:
=> MLEN input of RDREC which is used to upload the
process image input
actual size:
=> byte size of the process image input that covers all
mapped data
see CM CANopen Configuration Studio:
“Process Image”: Direction: IN
more details are provided by:
chapter 4.2.1
Program group "Get Process Data In" provides all functionality to process the
upload of the process image input from the CM CANopen and to update the
data for the PLC.
The process image input data are handled by:
“CANopenProcessImage“.Input.CM_Data
the read data are copied to this area by RDREC
its data format is little endian
“CANopenProcessImage“.Input.PLC_Data
this area provides the read and converted data for the application
its data format is big endian
the user constant "cByteSize_PIInput_Struct"
byte size of “CANopenProcessImage“.Input.CM_Data
Hint:
it is recommended to differentiate between the uploaded data and the
data of the application to avoid inconsistencies caused by the
asynchronous upload of the process image
Hint: Implementation
The implementation of “Get Process Data In” by the CANopen demo is
based on the layout of the “Process Image” of the demo project of the
CM CANopen Configuration Studio.
Copyright HMS Technology Center 18 CM CANopen, CANopen Application, V1.0
Ravensburg GmbH
Exchange of process image data
13
14
15
16 00000010 2 6404 1 4 N2_AnalogInFloat_1
17
18
19
20
… free space of the process image input that does not carry data
255
(max)
The process image input of the CM module is a byte array whose application
specific use is defined by the layout of the “Process Image: Direction: IN” in the
Configuration Studio.
Notation:
Byte Array: Offset
description of the process image input as a byte array
Address, Node-ID, Index und Sub-Index
correspond to the same-named columns of the process image in
the CM CANopen Configuration Studio
Byte Size: byte size of the mapped object Size (bit) / 8
Nx Node-ID x
Structure used by the PLC
description of the process image input as a structure
minimum size of the process image input that covers all data
rule:
minimum size = highest “Address“ of Direction: IN
+ byte size of the object at this address
consequences
minimum size <= “CANopen input data size“
minimum size <= MLEN input of RDREC which is used to
read the process image
best performance:
minimum size = MLEN input = “CANopen input data size“
The demo uses the structure ”PIInput” that is defined in “PLC Data Types”:
GetProcessDataIn [FC1]
uploads the process image input data from the CM CANopen
updates the process image input data used by the PLC program to
control the process
"RDREC_GetProcessDataIn"(REQ:=TRUE,
ID:=#HW_ID,
INDEX:=16#90,
MLEN:= "cByteSize_PIInput_Struct",
VALID=>#fValid,
BUSY=>#fBusy,
ERROR=>#fError,
STATUS=>#dwStatus,
LEN=>#uiLen,
RECORD:="CANopenProcessImage".Input.CM_Data.Data);
UpdatePIInData_PLC [FC2]
is called by GetProcessDataIn [FC1] when the data have been uploaded
updates the process image input data that are used by the PLC program
to control the process
the updated data are converted to the data format of the PLC
The update of the process image input data of the application uses the
variables:
the uploaded “CANopen” data are provided by
“CANopenProcessImage“.Input.CM_Data
the updated “PLC” data are provided by:
“CANopenProcessImage“.Input.PLC_Data
Program group "Set Process Data Out" provides all functionality to process the
download of the process image output to the CM CANopen.
The process image input data are handled by:
"CANopenProcessImage".Output.PLC_Data
this area provides the process image output data of the
application
its data format is big endian
“CANopenProcessImage“.Output.CM_Data
this area provides converted data that are written to the CM
module
its data format is little endian
the user constant "cByteSize_PIOutput_Struct"
byte size of "CANopenProcessImage".Output.CM_Data
Hint:
it is recommended to differentiate between the downloaded data and the
data of the application to avoid inconsistencies caused by the
asynchronous download of the process image
Hint: Implementation
The implementation of “Set Process Data Out” by the CANopen demo is
based on the layout of the “Process Image” of the demo project of the
CM CANopen Configuration Studio.
13
14
15
16
… free space of the process image output that does not carry data
255
(max)
The process image output of the CM module is a byte array whose application
specific use is defined by the layout of the “Process Image: Direction: OUT” in
the Configuration Studio.
Notation:
Byte Array: Offset
description of the process image input as a byte array
Address, Node-ID, Index und Sub-Index
correspond to the same-named columns of the process image in
the CM CANopen Configuration Studio
Byte Size: byte size of the mapped object Size (bit) / 8
Nx Node-ID x
Structure used by the PLC
description of the process image input as a structure
minimum size of the process image output that covers all data
rule:
minimum size = highest “Address“ of Direction: OUT
+ byte size of the object at this address
consequences
minimum size <= “CANopen output data size“
minimum size <= LEN input of WRREC which is used to
write the process image
best performance:
minimum size = LEN input = “CANopen output data size“
The demo uses the structure ”PIOutput” that is defined in “PLC Data Types”:
clears the request that indicates the download has been processed
see: line 126
SetProcessDataOut [FC3] must not be coded by the customer.
hint:
set flag shall not be reset by the
application
REQ is automatically set to FALSE by the
function when the command has been
processed
The download of the “CANopen” process image output uses the variables:
data record
"CANopenProcessImage".Output.CM_Data
see input RECORD of "WRREC_SetProcessDataOut"()
"WRREC_SetProcessDataOut"():
instance of WRREC that is used by SetProcessDataOut [FC3] to
download the process image to the CM CANopen
The update of the “CANopen” process image output data that are written
to the CM CANopen uses the variables:
the “PLC” data are provided by:
"CANopenProcessImage".Output.PLC_Data
the updated “CANopen” data are transferred by
"CANopenProcessImage".Output.CM_Data
5 SDO commands
5.1 General hint
5.1.1 Processing of a SDO command
The execution of a SDO command needs time
especially if another device than the CM module is accessed
especially if a high amount of data is transferred
due to the use of Siemens SFBs WRREC and RDREC
Note: SLOT
SLOT must not be confused with the physical slot of the module
The CM module internally uses SDO channels
These SDO channels are not visible in the hardware configuration in TIA
portal
SLOT defines the SDO channel to be used for the requested SDO
command
example:
the data to be written are provided by "SDO_Data_DB".WrData
data type of WrData: “SDO_WriteData”
general:
1. transmitted data byte
"SDO_Data_DB".WrData.SDO_WriteData [1]
…
n. transmitted data byte
"SDO_Data_DB".WrData.SDO_WriteData [n]
8 bit value:
value to be written: 16#12
=> "SDO_Data_DB".WrData.SDO_WriteData[1] := 16#12;
16 bit value:
value to be written: 16#1234
=> "SDO_Data_DB".WrData.SDO_WriteData [1] := 16#34; // LSB
"SDO_Data_DB".WrData.SDO_WriteData [2] := 16#12; // MSB
32 bit value:
value to be written: 16#12345678
=> "SDO_Data_DB".WrData.SDO_WriteData [1] := 16#78; // LSB
"SDO_Data_DB".WrData.SDO_WriteData [2] := 16#56;
"SDO_Data_DB".WrData.SDO_WriteData [3] := 16#34;
"SDO_Data_DB".WrData.SDO_WriteData [4] := 16#12; // MSB
example:
the read data are copied to „SDO_Data_DB“.RdData
data type of RdData: “SDO_ReadData”
general:
1. transmitted / received data byte
„SDO_Data_DB“.RdData.SDO_ReadData [1]
…
n. transmitted / received data byte
„SDO_Data_DB“.RdData.SDO_ReadData [n]
8 bit value:
„SDO_Data_DB“.RdData.SDO_ReadData[1] = 16#12
=> read value: 16#12
16 bit value:
„SDO_Data_DB“.RdData.SDO_ReadData [1] = 16#34; // LSB
„SDO_Data_DB“.RdData.SDO_ReadData [2] = 16#12; // MSB
=> read value: 16#1234
32 bit value:
„SDO_Data_DB“.RdData.SDO_ReadData [1] = 16#78; // LSB
„SDO_Data_DB“.RdData.SDO_ReadData [2] = 16#56;
„SDO_Data_DB“.RdData.SDO_ReadData [3] = 16#34;
„SDO_Data_DB“.RdData.SDO_ReadData [4] = 16#12; // MSB
=> read value: 16#12345678
SDO command that accesses a slave device should not be performed before
the slave has been successfully booted / configured because:
the configuration of the slave is only consistent when it has been booted
successfully
consequences if the slave has not been booted successfully:
SDO read command:
read data may be erroneous because they are based on a
configuration which is only provided by a successfully booted
slave
SDO write command:
its data will be most probably overwritten or reset to default by
the later processed boot slave process
"Get Node & Network Status" or the diagnostic objects 5002h ( Configured
slaves bit list ) and 5004h ( Operational slaves bit list ) of the CM module
provide the status information - booted / configured / operational – of the
slaves.
Note:
only a successfully booted slave can be set to operational.
allowed action:
index: 1F82h
subindex: CANopen node-id of the CM
module
value: 4 set stopped
6 reset node
7 reset communication
127 set preoperational
allowed action:
index: 1F82h
subindex: CANopen node-id of the CM
module
value: 5 set operational
allowed action:
index: 1F82h
subindex: 80h
value: 5 set operational
The CANopen demo must be enhanced to run several parallel SDO read /
several parallel SDO write commands.
3. analyze the result of the processed SDO Read command and interpret
the data
Input Parameters:
Valid values: 0 – 7
Note:
This slot defines a SDO channel and must not be
confused with the physical slot of the module
NODE Int Node-ID of the CANopen module where SDO read
is to be performed.
Note:
Node-ID 0 always addresses the CM module even
when the CM module has another Node-ID
INDEX Word index of the object to be read
SUB Byte subindex of the object to be read
MAX_SIZE DInt Byte size of the destination area where the read
data are saved
limit of data bytes that can be read and saved
Output Parameters:
Note:
REQ = FALSE in idle state:
=> BUSY = FALSE
=> RET =0
=> SIZE =0
RET UInt Error code
see description of RET in chapter 8.1.3 SDO
Read/Write
note:
"SDO_ReadData" must be a byte array
The customer can only vary n to adjust the byte size to its
application
Note:
the purpose of this function is to explain how to initialize the inputs of
ReadSDO [FB104] to run a SDO read command
line 109:
initialization of the hardware identifier of the accessed CM module
line 133:
demo uses SLOT 0 for read SDO command
demo example reads the error register of the CANopen device with the
of the CANopen node id 1
line 138 : accessed CANopen device
line 143 : index of the object to be read
line 148 : subindex of the object to be read
line 159:
demo indicates that read SDO command shall be processed
Function
checks if the requested command has been processed successfully:
an error has been detected:
lines 54 – 59:
analysis and reaction must be coded by the customer
Input Parameters:
Valid values: 0 – 7
Note:
This slot defines a SDO channel and must
not be confused with the physical slot of the
module
NODE Int Node-ID of the CANopen module where
SDO write is to be performed.
Note:
Node-ID 0 always addresses the CM
module even when the CM module has
another Node-ID
INDEX Word index of the object to be written
SUB Byte subindex of the object to be written
DATA "SDO_WriteData" Data area where to get the data to be
written
DATASIZE UInt Number of bytes to be written.
Output Parameters:
Note:
REQ = FALSE in idle state:
=> BUSY = FALSE
=> RET =0
=> SIZE =0
RET UInt Error code
see description of RET in chapter 8.1.3 SDO
Read/Write
note:
"SDO_WriteData" must be a byte array
The customer can only vary n to adjust the byte size to its
application
The project must be compiled when the size of
“SDO_WriteData" has been changed
Note:
the purpose of this function is to explain how to initialize the inputs of
WriteSDO [FB105] to run a SDO write command
line 182:
initialization of the hardware identifier of the accessed CM module
line 208:
demo uses SLOT 1 for write SDO command
demo example clears the pre-defined error field of the CANopen device
with the of the CANopen node id 2
line 213 : accessed CANopen device
line 218 : index of the object to be written
line 223 : subindex of the object to be written
line 235
demo enters the data that shall be written in
"Ctrl_CM_CANopen".WriteSDO.Data.SDO_WriteData[]
order of transmission:
first transmitted data byte (LSB):
"Ctrl_CM_CANopen".WriteSDO.Data.SDO_WriteData[1]
…
last transmitted data byte (MSB):
"Ctrl_CM_CANopen".WriteSDO.Data.SDO_WriteData[number bytes]
line 240
demo updates the number of data bytes to be written
line 246
demo requests the processing of the initialized SDO write
command
Function
checks if the requested command has been processed successfully
the command has been processed successfully
line: 26 - 27
an error has been detected:
lines 29 – 34:
analysis and reaction must be coded by the customer
Program group "Get Node & Network Status" provides all functionality to
process a Get Node & Network Status command.
The processing of a “Get Node & Network Status” command is controlled by
the structure:
"Ctrl_CM_CANopen".GetNNStatus
hint:
do not change the data type of abData
it covers all data
GetNodeNetworkStatus [FC18]
is based on this definition:
see local Constant:
#cByteSizeRecord
AnalyseNodeNetworkStatus [FC14]
is based on this definition
hint:
set flag shall not be reset by the application
note:
each slave device is marked in the diagnostic object 5001h
unexpected device:
device has not been entered as a CANopen slave in the Project
Explorer of the CM CANopen Configuration Studio
Bit 0 of its NMT Slave configuration is not set
note:
unexpected devices are not marked in the diagnostic object 5001h
a present unexpected device is marked in the diagnostic object
5003h
An identity object is checked if it has been selected and its value is not
equal to 0 (don`t care).
Device Type, Vendor-ID, Product Code and Serial Number:
must match exactly
Revision Number:
major Revision Number (bits 16 - 31) must match exactly
read minor revision number (bits 0 - 15) must be greater than or
equal to the expected on
index 500Ah: identity error bit list
lists the slaves that identity do not match
these errors are caused by an EDS file that does not describe the
real device correctly and completely
action:
- ask the manufacturer for the correct EDS
action:
- ask the manufacturer for a FW update
realistic solution:
manufacturer does not provide a revised EDS / FW update
the EDS has to be revised by the customer:
analyse the CAN bus traffic and adjust the EDS step by step
condition:
slave must be entered in the consumer heartbeat list with a
consumer heartbeat time > 0
lifetime timeout
slave is guarded and has not responded within its lifetime
condition:
slave must be guarded by the CM module
Guard Time · Retry Factor > 0
note:
the CM module automatically retries to recover form bus off
action:
check the above mentioned possible errors
note:
the status of the CM module is also displayed
action:
power off / on the PLC
fatal error log can be read by SDO: index 5500h, subindex 1
inform HMS and provide the read fatal error log
action:
"CANopen Node status" CANopen NMT status of the CM
module:
"Ctrl_CM_CANopen".GetNNStatus.abData[4]
check bit 1: node error control event of Error flags (network)
analyse the status of each CANopen node id: 1 - 127
node id 1 "Ctrl_CM_CANopen".GetNNStatus.abData[5]
…
node id 127 "Ctrl_CM_CANopen".GetNNStatus.abData[131]
action:
- "CANopen Node status" CANopen NMT status of the CM
module:
"Ctrl_CM_CANopen".GetNNStatus.abData[4]
- additional diagnostic information is provided by the objects
- 5000h: subindex 1 / 2
- 50003h
- 50004h - 5006h
note:
only devices that has been entered in the consumer
heartbeat list of the CM module with a consumer
heartbeat time > 0 are displayed in these lists
action:
analyse the status of each CANopen node id: 1 - 127
node id 1 "Ctrl_CM_CANopen".GetNNStatus.abData[5]
…
node id 127 "Ctrl_CM_CANopen".GetNNStatus.abData[131]
note:
the status of the CM module is also displayed
action:
additional diagnostic information is provided by the objects
- object 5003h
- object 5000h, subindex 1: bit 13
the slave device is present but its boot slave process fails
note:
failed boot slave process is repeated when
Bit 2 of the slave`s NMT Slave configuration
is set
and the NMT status of the CM module is not stopped
note:
only a slave that has been booted successfully can be set to
operational
hint:
missing can be also caused by a reset node command that is
written to the slave due to
- heartbeat timeout / guarding timeout
- heartbeat / guarding response has reported another
CANopen NMT state than the expected one
- the configuration of the slave has failed
and the slave has not finished its CANopen initialization before
the CM module has started to boot the slave
the slave device should be detected as present after some retries
of the boot slave process
Hint: Process Image Size (OUT) (byte), Process Image Size (IN) (byte)
CM CANopen configuration Studio will use the values entered here to
check if the byte size of the selected application objects exceeds the
entered range
the actual maximum byte size of the process image input / output is set
in the hardware configuration of the CM CANopen in TIA Portal
Process Image Size (OUT) (byte) sets the limit for: Allocated process
Image Size IN
Process Image Size (IN) (byte) sets the limit for: Allocated process
Image Size OUT
8 Status LEDs
This chapter describes the single LED patterns to avoid misinterpretation.