Object Dictionary

CANopen devices must have an object dictionary, which is used for configuration and communication with the device. An entry in the object dictionary is defined by:

  • Index, the 16-bit address of the object in the dictionary
  • Object type, such as an array, record, or simple variable
  • Name, a string describing the entry
  • Type, gives the datatype of the variable (or the datatype of all variables of an array)
  • Attribute, which gives information on the access rights for this entry, this can be read/write (rw), read-only (ro) or write-only (wo)

The basic datatypes for object dictionary values such as booleans, integers and floats are defined in the standard, as well as composite datatypes such as strings, arrays and records. The composite datatypes can be subindexed with an 8-bit index; the value in subindex 0 of an array or record indicates the number of elements in the data structure, and is of type UNSIGNED8.

Supported formats

The currently supported file formats for specifying a node’s object dictionary are:

  • EDS (standardized INI-file like format)
  • DCF (same as EDS with bitrate and node ID specified)
  • EPF (proprietary XML-format used by Inmotion Technologies)

Examples

The object dictionary file is normally provided when creating a node. Here is an example where the entire object dictionary gets printed out:

node = network.add_node(6, 'od.eds')
for obj in node.object_dictionary.values():
    print('0x%X: %s' % (obj.index, obj.name))
    if isinstance(obj, canopen.objectdictionary.Record):
        for subobj in obj.values():
            print('  %d: %s' % (subobj.subindex, subobj.name))

You can access the objects using either index/subindex or names:

device_name_obj = node.object_dictionary['ManufacturerDeviceName']
vendor_id_obj = node.object_dictionary[0x1018][1]

API

class canopen.ObjectDictionary[source]

Representation of the object dictionary as a Python dictionary.

od[index]

Return the object for the specified index (as int) or name (as string).

iter(od)

Return an iterator over the indexes from the object dictionary.

index in od

Return True if the index (as int) or name (as string) exists in the object dictionary.

len(od)

Return the number of objects in the object dictionary.

values()

Return a list of objects (records, arrays and variables).

add_object(obj)[source]

Add object to the object dictionary.

Parameters:obj – Should be either one of Variable, Record, or Array.
bitrate = None

Default bitrate if specified by file

get_variable(index, subindex=0)[source]

Get the variable object at specified index (and subindex if applicable).

Returns:Variable if found, else None
Return type:canopen.objectdictionary.Variable
node_id = None

Node ID if specified by file

class canopen.objectdictionary.Variable(name, index, subindex=0)[source]

Simple variable.

len(var)

Return the length of the variable data type in number of bits.

var == other

Return True if the variables have the same index and subindex.

access_type = None

Access type, should be “rw”, “ro”, “wo”, or “const”

add_bit_definition(name, bits)[source]

Associate bit(s) with a string description.

Parameters:
  • name (str) – Name of bit(s)
  • bits (list) – List of bits as integers
add_value_description(value, descr)[source]

Associate a value with a string description.

Parameters:
  • value (int) – Value to describe
  • desc (str) – Description of value
bit_definitions = None

Dictionary of bitfield definitions

data_type = None

Data type according to the standard as an int

default = None

Default value at start-up

description = None

Description of variable

factor = None

Factor between physical unit and integer value

index = None

16-bit address of the object in the dictionary

max = None

Maximum allowed value

min = None

Minimum allowed value

name = None

String representation of the variable

parent = None

The ObjectDictionary, Record or Array owning the variable

storage_location = None

Storage location of index

subindex = None

8-bit sub-index of the object in the dictionary

unit = None

Physical unit

value = None

The value of this variable stored in the object dictionary

value_descriptions = None

Dictionary of value descriptions

class canopen.objectdictionary.Record(name, index)[source]

Groups multiple Variable objects using subindices.

record[subindex]

Return the Variable for the specified subindex (as int) or name (as string).

iter(record)

Return an iterator over the subindexes from the record.

subindex in record

Return True if the subindex (as int) or name (as string) exists in the record.

len(record)

Return the number of subindexes in the record.

record == other

Return True if the records have the same index.

values()

Return a list of Variable in the record.

add_member(variable)[source]

Adds a Variable to the record.

description = ''

Description for the whole record

index = None

16-bit address of the record

name = None

Name of record

parent = None

The ObjectDictionary owning the record.

storage_location = None

Storage location of index

class canopen.objectdictionary.Array(name, index)[source]

An array of Variable objects using subindices.

Actual length of array must be read from the node using SDO.

array[subindex]

Return the Variable for the specified subindex (as int) or name (as string). This will work for all subindexes between 1 and 255. If the requested subindex has not been specified in the object dictionary, it will be created dynamically from the first subindex and suffixing the name with an underscore + the subindex in hex format.

add_member(variable)[source]

Adds a Variable to the record.

description = ''

Description for the whole array

index = None

16-bit address of the array

name = None

Name of array

parent = None

The ObjectDictionary owning the record.

storage_location = None

Storage location of index

exception canopen.ObjectDictionaryError[source]

Unsupported operation with the current Object Dictionary.

Constants

canopen.objectdictionary.UNSIGNED8
canopen.objectdictionary.UNSIGNED16
canopen.objectdictionary.UNSIGNED32
canopen.objectdictionary.UNSIGNED64
canopen.objectdictionary.INTEGER8
canopen.objectdictionary.INTEGER16
canopen.objectdictionary.INTEGER32
canopen.objectdictionary.INTEGER64
canopen.objectdictionary.BOOLEAN
canopen.objectdictionary.REAL32
canopen.objectdictionary.REAL64
canopen.objectdictionary.VISIBLE_STRING
canopen.objectdictionary.OCTET_STRING
canopen.objectdictionary.UNICODE_STRING
canopen.objectdictionary.DOMAIN
canopen.objectdictionary.SIGNED_TYPES
canopen.objectdictionary.UNSIGNED_TYPES
canopen.objectdictionary.INTEGER_TYPES
canopen.objectdictionary.FLOAT_TYPES
canopen.objectdictionary.NUMBER_TYPES
canopen.objectdictionary.DATA_TYPES