Search code examples
pythoncan-buscanopen

Canopen SdoCommunicationError when trying to read RPDO config


I have a peak CAN adapter connected to a device communicating on the CAN with Canopen. I use canopen library 2.1.0 with python 3.10.0 to create a network, add a node with an eds file and connect. I'm trying to log all the messages from the bus. I'm able to see the messages from the device but not the ones I send. I've tried to use the option receive_own_messages=True in the connect method, but that doesn't change anything. My CAN adapter supports it.

import canopen
import can

nw = canopen.Network()
node = nw.add_node(1, r"C:\path\to\eds")
nw.listeners += [can.Printer()]
nw.connect(interface='pcan', bitrate=125000, channel='PCAN_USBBUS1', receive_own_messages=True)
node.rpdo.read()

CAN trace: enter image description here

As you can see, the messages coming from the device are there (0x701, 0x581) but not the ones I send (I expect 0x601 as this is the COB-ID used for SDO request).

Any idea how can I make this work?


Solution

  • You are using the PCAN-Basic API (under Windows?) for connectivity:

    https://python-can.readthedocs.io/en/stable/interfaces/pcan.html

    This low-level API doesn't offer the self-receive feature so the parameter receive_own_messages=True is ineffective. If you have a Linux development platform (e.g. Raspberry Pi, Linux virtual machine with USB pass-through support) you could switch to PCAN under SocketCAN which supports it:

    https://python-can.readthedocs.io/en/stable/interfaces/socketcan.html#socketcan-pcan