Skip to content

Unable to send periodic messages with IXXAT interface as of 4.0.0. #1285

Open

Description

@thshan

Description:

While attempting to set up a periodic task to synchronously write/read PDOs using an IXXAT USB-to-CAN and the canopen package, an AttributeError is generated due to the IXXATBus object missing _periodic_tasks (see: traceback below).

Update: After digging around with pdb, it looks like there's some additional wrapping applied to the IXXATBus object - storing the actual bus object in its own attribute (self.bus) rather than returning the bus object itself to the caller of interface.Bus.__new__. If the bus object held by the canopen library's network object is replaced with the bus object inside the bus object returned from interface.Bus.__new__, then there is no issue as the _periodic_tasks array is initialised correctly in that inner bus object:

e.g.

import canopen
net = canopen.Network()
net.bus = net.bus.bus
print(len(net.bus._periodic_tasks))

Runs without error. But, there should be no need to unwrap the inner bus object in this way.

Expected behavior

On v3.3.4, it is possible to use node.rpdo[pdo].start or network.sync.start from the canopen package (on its latest 2.0.0 release) without any errors being generated. Calling the constructor does not resolve the issue on V4.0.0, however, manually setting bus._periodic_tasks = [] functions as a workaround.

The bus object returned by interface.Bus.__new__ on V3.3.4 contains an empty _periodic_tasks array. On V4.0.0, the user must access bus.bus in order to access it.

Additional context

OS and version: Windows 10 Professional (10.0.19044 Build 19044)
Python version: Python 3.9.10, also confirmed with Python 3.10.3
python-can version: 4.0.0
python-can interface/s (if applicable): IXXAT.

Traceback and logs

Traceback (most recent call last):
 line 78, in <module>
    main()
  line 54, in main
    network.start_nodes(net, 0.5)
  start_nodes
    node.rpdo[pdo].start(sync_time)
 line 449, in start
    self._task = self.pdo_node.network.send_periodic(
  "...\canopen\network.py", line 220, in send_periodic
    return PeriodicMessageTask(can_id, data, period, self.bus, remote)
 "...\canopen\network.py", line 294, in __init__
    self._start()
 "...\canopen\network.py", line 297, in _start
    self._task = self.bus.send_periodic(self.msg, self.period)
  "...\python_can\can\bus.py", line 239, in send_periodic
    periodic_tasks = self._periodic_tasks
AttributeError: 'IXXATBus' object has no attribute '_periodic_tasks'

Bus attributes on 4.0.0:
['RECV_LOGGING_LEVEL', 'abstractmethods', 'class', 'delattr', 'dict', 'dir', 'doc', 'enter', 'eq', 'exit', 'format', 'ge', 'getattribute', 'gt', 'hash', 'init', 'init_subclass', 'iter', 'le', 'lt', 'module', 'ne', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'sizeof', 'str', 'subclasshook', 'weakref', '_abc_impl', '_apply_filters', '_detect_available_configs', '_matches_filters', '_recv_internal', '_send_periodic_internal', 'bus', 'channel_info', 'fileno', 'filters', 'flush_tx_buffer', 'recv', 'send', 'send_periodic', 'set_filters', 'shutdown', 'state', 'stop_all_periodic_tasks']

Bus attributes on 3.3.4:
['CHANNEL_BITRATES', 'RECV_LOGGING_LEVEL', '_IXXATBus__set_filters_has_been_called', 'class', 'delattr', 'dict', 'dir', 'doc', 'enter', 'eq', 'exit', 'format', 'ge', 'getattribute', 'gt', 'hash', 'init', 'init_subclass', 'iter', 'le', 'lt', 'metaclass', 'module', 'ne', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'sizeof', 'str', 'subclasshook', 'weakref', '_apply_filters', '_channel_capabilities', '_channel_handle', '_control_handle', '_detect_available_configs', '_device_handle', '_device_info', '_inWaiting', '_matches_filters', '_message', '_payload', '_periodic_tasks', '_receive_own_messages', '_recv_internal', '_scheduler', '_scheduler_resolution', '_send_periodic_internal', '_tick_resolution', 'channel', 'channel_info', 'filters', 'flush_tx_buffer', 'recv', 'send', 'send_periodic', 'set_filters', 'shutdown', 'state', 'stop_all_periodic_tasks']

Activity

  1. zariiii9003 commented on Mar 18, 2022

    @zariiii9003
    Collaborator
  2. thshan commented on Mar 18, 2022

    @thshan
    Author

    Could you try this branch? https://github.com/zariiii9003/python-can/tree/fix_1285

    Hi zariiii9003. No change on that branch. I have, however, added some updated details in the OP after a bit of investigation.

  3. zariiii9003 commented on Mar 18, 2022

    @zariiii9003
    Collaborator

    Can you show your traceback with my branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions