CANopen protocol communication between two nodes using python canopen package

1.7k views Asked by At

I have two USB to CAN devices (can0 and can1), they both are connected to a Linux machine which has socketcan installed in it. I have read the basics of CANopen protocol, i have not seen any example that can establish communication between two CANopen devices using Python CANopen library.

I read in the documentation that each devices must have a .eds file, so I took a sample .eds file from the Python CANopen library from christiansandberg github and trying to establish communication and make them talk to each other using PDO's, but I could not able to do that.

We have a battery and wanted to communicate with it, the battery works on can-open protocol and they have provided the .eds file for the battery. I guess a usb2can device with the CANopen Python library can do the work. But I just don't know how to establish communication between the usb2can device and the battery. It would be helpful with any insights in framing the packets.

1

There are 1 answers

0
Lundin On

This is what you need to do:

  • Get the necessary tools for CAN bus development. This means some manner of CAN listener in addition to your own application. It also means cables + terminating resistors. The easiest is to use DB9 dsub connectors. An oscilloscope is also highly recommended.
  • Read the documentation about the device to figure out how to set node id and baudrate, or at least which default settings it uses.
  • Find out which Device Profile the device uses, if any. The most common one is CiA 401 "generic I/O module". In which case the default settings will be node id 1, baudrate 125kbps.
  • Your application will need to act as NMT Master - network managing master - on this bus. That is, the node responsible for keeping track of all other nodes.
  • If the device is CANopen compliant and you've established which baudrate and node id it uses, you'll get a "NMT bootup" message at power up. Likely from node 1 unless you've changed the node id of the device.
  • You'll need to send a "NMT start remote node" message to the device to bring it from pre-operational to operational.
  • Depending on what Device Profile the device uses, it may now respond with sending out all its enabled PDO data once, typically with everything set to zero.
  • Now check the documentation of the device to find out which data that resides in which PDO. You'll need to match TPDO from the device with RPDO in your application and vice versa. They need to have the same COBID - CAN identifiers, but also the same size etc.
  • COBID is set in PDO communication settings in the Object Dictionary. If you need to change settings of the device, it needs to be done with SDO access of the device Object Dictionary.
  • More advanced options involve PDO mapping, where you can decide which parts of the data you are interested in that goes into which PDO. Not all devices support dynamic PDO mapping - it might use static PDO mapping in which case you can't change where the data comes out.
  • Other misc useful stuff is the SAVE/LOAD features of CANopen in case the device supports them. Then you can store your configuration permanently so that your application doesn't need to send SDOs at start-up for configuration every time the system is used.
  • Heartbeat might be useful to enable to ensure that the device is up and running on regular basis. Your application will then act as Heartbeat consumer.