pyx2cscope

The pyx2cscope Python package communicates with X2Cscope enabled firmwares running on Microchip microcontrollers. This comprehensive package offers developers a powerful toolkit for embedded software development, combining real-time debugging capabilities with advanced data visualization features directly within the Python environment. pyx2cscope makes use of lnet protocol to communicate with the embedded hardware via different communication interfaces like UART, CAN, LIN, USB, TCP/IP, etc.

pyX2Cscope

pyX2Cscope is the Python implementation of the X2Cscope plugin from MPLABX. This will let the user use the functionality of X2Cscope even outside MPLABX environment / Standalone. It allows user to:

  • Automated Unit Tests (TDD) using pytest

  • BDD (behavior driven development), Framework: “Cucumber”

  • Different user interface

  • Data collection for machine learning and training models

  • Run-Time data analysis

  • Use of Real Time AI model

  • HiL (Hardware in the loop) testing and tuning

MCU<->PC

Installation

Create a virtual environment and install pyx2cscope using the following commands (Windows):

python -m venv .venv
.venv\Scripts\activate
pip install pyx2cscope

It is highly recommended to install python libraries underneath a virtual environment.

Nevertheless, to install at system level, we advise to install it on user area. (Global insallation may not work.) Execute the following lines:

pip install --user pyx2cscope
pip install --upgrade pyx2cscope

In case of unexpected issues executing pyx2cscope try to reinstall manually:

pip uninstall pyx2cscope
pip cache purge
pip install --user pyx2cscope

After install you may check the current pyx2cscope version, in a terminal, run the following command:

pyx2cscope --version

For help or additional command line options, type:

pyx2cscope --help

The log level used by pyX2Cscope is ERROR by default, possible values are DEBUG, INFO, WARNING, ERROR, and CRITICAL. To set a different log level start pyX2Cscope with argument -l or –log-level

pyx2cscope --log-level DEBUG

Usage

You may try pyX2Cscope either as an API to read and write values from/to variables in a running Microchip microcontroller, or as a Graphical User Interface (GUI), or both.

The GUI interface

There are currently two implementations, one based on Qt and one Browser based. These GUIs are more examples on how to implement your own custom interfaces than an official user interface.

To execute Qt version, type:

pyx2cscope

To execute the Browser based version type:

pyx2cscope -w

The API interface

The API interface is managed over the X2CScope class. The simplest example of the API is depicted below:

 1"""The simplest usage of the pyX2Cscope library.
 2
 3The script initializes the X2CScope class with a specified serial port and ELF file,
 4retrieves specific variables, reads their values, and writes new values to them.
 5"""
 6
 7from pyx2cscope.x2cscope import X2CScope
 8
 9# initialize the X2CScope class with serial port, by default baud rate is 115200
10x2c_scope = X2CScope(port="COM8", elf_file="Path_To_Elf_File")
11
12# Collect some variables.
13speed_reference = x2c_scope.get_variable("motor.apiData.velocityReference")
14speed_measured = x2c_scope.get_variable("motor.apiData.velocityMeasured")
15
16# Read the value of the "motor.apiData.velocityMeasured" variable from the target
17print(speed_measured.get_value())
18# Write a new value to the "motor.apiData.velocityReference" variable on the target
19speed_reference.set_value(1000)

Following you will find specific information on the API, GUIs, and Firmware implementation. See the section examples to check some of the usages you may get by pyX2Cscope.

Indices and tables