Interfacing To Inverter using Python and Peak CAN Interface
Emsiso Inverters primarily use the CANOpen protocol to communicate with outside tools. It is possible to use public libraries to communicate with the inverter using Python to automate production or assembly processes.
In this article, we will show how to connect to an Emsiso inverter using a PEAK CAN Interface and set/get a parameter value using an SDO Read/Write operations.
The article is intended for programmers with working knowledge of Python.
We will be using the publicly available Python CANOpen Library: canopen ยท PyPI
Exhaustive documentation for canopen is available on the official docu website:
canopen 0.1.dev52+ge840449 documentation
Minimum Requirements:
- Python 3.8 or up (except for Python 3.12.0 due to an unresolved issue with the canopen library)
- PEAK CAN Interface Drivers
- Any Emsiso Inverter
Initial Setup:
First we need to install dependencies. In our case, the canopen library already installs the can-interface. It is strongly recommended to also install the uptime library in order to correctly show the frame times.
- pip install canopen
- pip install uptime
Step 1: Verify Connection:
In order to verify that the setup has been performed correctly, we can scan the nodes on the bus.
Take care to define proper channel and bitrate. The example below contains the values:
- PCAN_USBBUS1: Windows machine with 1 CAN interface connected
- 500000: 500 kbps bit rate
Further information on connecting HW interfaces (esp. PEAK) is available here:
PCAN Basic API - python-can 4.5.0 documentation
import canopen
import time
network = canopen.Network()
# We connect to the interface here. In our case it's the PCAN interface on bus 1.
network.connect(interface='pcan', channel='PCAN_USBBUS1', bitrate=500000)
time.sleep(0.05)
for node_id in network.scanner.nodes:
# We expect to find 1 node if the inverter connection is successful
print(f"Found node {node_id}!")
network.disconnect()
If the inverter is properly connected, is the only device on the bus, and all dependencies are correctly installed, you can expect the following output:
- Found node 1!
Step 2: SDO Read/Write
After the connection is verified, we can proceed to perform an SDO write and read.
We will read from the [1018:1] - Vendor ID. The expected Vendor ID for Emsiso devices is: 966.