can-buscanopen

Send a simple CANopen TPDO


I have some experience with CAN, but completely new to CANopen.

I have instructions to send a TPDO to a specific COB-ID (0x0050). I have the index (0x4602) and sub-index (13) to send the data (16 bits). I'm able to send CAN messages using can-utils of course, as in:

cansend can0 050#00.00.00.00.00.00.00.00

The device responds to this, and I can see it sending messages with candump, so I know the CAN bus is working properly and the COB-ID is correct.

But I am not sure how to send a CANopen command to the index/subindex with this information. I've tried using the python canopen library, but I haven't figured out how to send such a simple TPDO with the information that I have. Is there an easy way to send a CANopen TPDO either on command line, python, or c++? I am using a Peak CAN-usb from a Linux PC to communicate with the network.


Solution

  • For PDOs you can usually get away with ignoring most of CANOpen and just send CAN frames as you already do. So you don't need a special library.

    You "only" need to figure out the size and content of the payload for COB-ID (=can_id) 0x050. (And the send interval.) Usually you find the CAN frames directly documented somewhere too, but your index/subindex refers to an object dictionary file that you presumably have. You can open it with a library, but IIRC you can also just extract what you need manually. It's basically a mapping of data values into different offsets in different PDOs (=CAN frames).

    The one ingredient that some CANOpen devices need to function is a NMT operational command sent periodically on the bus. (I think it's actually mandatory, but some devices will just transmit/receive all PDOs all the time anyway.) This frame is easy to send, you can just hardcode everything.

    This is true for PDOs. In contrast, if you need SDO communication, you will not be able to keep things so simple.