Python Library for ECU-P hardware

Getting Started

This guide will help you setup Python to control memetis ECU-P hardware.

Install VCP driver

The ECU-P hardware uses chip from SiliconLabs for the communication over USB. Unfortunatly this requires installation of a driver package from the chip vendor.

  • Visit SiLabs Download page and switch to Downloads tab. Download the current version for macOS.

  • Unzip the downloaded file, mount SiLabsUSBDriverDisk.dmg by double-clicking it and run Install CP210x VCP Driver.app.

  • Follow the installation instructions. You will be prompted to enter your password twice. After a short while you will be informed that a system extension was blocked.

  • Open the Security & Privacy pane in macOS Settings.

  • Allow making changes by clicking the small lock symbol in the bottom right-hand corner. Then allow the CP210xVCPDriver.app.

  • The installation will finish automatically.

_images/macOS_systemextension_blocked.png _images/macOS_systemextension_allow.png

Check USB connection

Before continuing you can use the steps below to check if the driver was successfully installed and the ECU-P hardware is found by your computer.

  • Connect the ECU-P hardware with a USB micro cable to your computer.

  • Open the Terminal application.

  • Run ls -l /dev/cu.* in the terminal.

  • You should see at least two devices. /dev/cu.SLAB_USBtoUART & /dev/cu.usbserial-110 in addition to devices already present on your system.

_images/macOS_ecup_connected.png

Note

If you cannot see the ECU-P hardware /dev/cu.SLAB_USBtoUART try updating the VCP driver from the previous step. Make sure you allowed the system extension under Security & Privacy.

You can also try with a different USB cable.

Install and check Python

The ECU-P library requires Python 3.7 or higher.

macOS comes with Python 3 pre-installed. Its available with the python3 and pip3 commands.

Check that the version is at least 3.7 and that pip is working. Run the following two commands in Terminal:

python3 --version
pip3 --version

These commands should not generate any error messages and display the version number of Python 3 and the package manager pip.

_images/macOS_python_working.png

Install ECU-P Python library

Install the ECU-P library by running

pip3 install https://gitlab.com/memetis/ecu-p/python/-/archive/master/python-master.zip

in the terminal / Command Prompt. This will automatically download and install the latest version of the library. You can use the same command to update any old version to the latest one.

Connect to ECU-P hardware with Python

Create a new Python program with the following content:

import logging
from ecu import ECUManager

logging.getLogger().setLevel(logging.WARNING)
logging.warning('Connection example started!')

manager = ECUManager()
for ecu in manager.get_all():
    print(ecu)

Run this Python program with ECU-P hardware conencted to your computer with a USB micro cable.

It will test all available serial ports on your computer for ECU-P hardware automatically. It then prints out information (product name, firmware version, serial port and UUID) of all found ECU-P devices.

_images/ecu_found.png

Note

If no device was found make sure you followd all the above steps. Make espacially sure that your computer recognises the ECU-P hardware as a serial port.

Enable output for 5 seconds

Create a second Python program with the following content:

import logging
import time
from ecu import ECUManager

logging.getLogger().setLevel(logging.INFO)
logging.info('Connection example started!')

manager = ECUManager()
ecu = manager.get_all()[0]
print(ecu)

ecu.enable(1)
time.sleep(5)
ecu.disable(1)

Run this Python program with ECU-P hardware conencted to your computer with a USB micro cable.

It will search all serial ports for ECU-P hardware. It then prints out information about the first found device. Then it enables CH1 output. After waiting 5 seconds it disables the output again.

_images/ecu_outputenabled.png

You should see the LED on the front panel turn on. Depending on the configuration of you device, this LED will turn off automatically after 300 milliseconds (for bistable valves, this can be overwritten by enabling manual_mode) or 5 seconds (for NC valves).