- pyX2Cscope is the Python implementation of the X2Cscope plugin from MPLABX.
- This will let the user use the functionality of X2Cscope even outside mplabx enviroment / Standalone.
- It allows user to:
- Automated Unit Tests (TDD) using pytest
- BDD(behaviour 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
Dor detailed documentation is hosted at github.io: https://x2cscope.github.io/pyx2cscope/
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, execute the following lines:
pip install pyx2cscope
pip install PyQt5 --user --ignore-installed
In case you already have installed pyx2cscope, you only need to update the package to the new version typing:
pip install --upgrade pyx2cscope
- Go to the Examples directory in the pyX2Cscope project to check out the available examples or create a new .py file according to your requirements.
- start with importing pyX2Cscope:
import pyx2cscope
- Choose the communication interface from the interfaces' module. Currently, Only Serial is supported: CAN and LIN coming in near future:
from xc2scope import X2CScope
- Initiate the X2CScope and provide the desired COM port, by default baud rate is set to 115200. . If there's a need to change the baud rate, include the baud_rate parameter with your preferred baud rate, In the same way other setting could be made:
x2cScope = X2CScope(port="COM16", elf_file=elf_file)
- Replace the elf_file with the path to the ELF file of your project.
- Create a Variable object for the variable you want to monitor:
variable = x2cScope.get_variable('Variable_name')
- Replace 'Variable_name' with the name of the variable you want to monitor. You can create multiple variable objects as required.
- Once you have gone through these steps, you can use the get_value() function to retrieve the value of the variable:
variable.get_value()
- To set the value for the respective variable set_value():
variable.set_value(value)
- To use the scope functionality, add channel to the scope: add_scope_channel(variable: Variable) :
x2cScope.add_scope_channel(variable1)
x2cScope.add_scope_channel(variable2)
- To remove channel: remove_scope_channel(variable: Variable):
x2cScope.remove_scope_channel(variable2)
- Up to 8 channels can be added.
- To Set up Trigger, any available variable can be selected, by default works on no trigger configuration.
x2cscope.set_scope_trigger(variable: Variable, trigger_level: int, trigger_mode: int, trigger_delay: int, trigger_edge: int)
srcChannel: TriggerChannel (variable)
Level: trigger_level
Trigger_mode: 1 for triggered, 0 for Auto (No trigger)
Trigger_delay = Value > 0 Pre-trigger, Value < 0 Post trigger
Trigger_Edge: Rising (1) or Falling (0)
x2cScope.set_scope_trigger(variable3, trigger_level=500, trigger_mode=1, trigger_delay=50, trigger_edge=1)
x2cscope.clear_trigger()
x2cScope.set_sample_time(2)
while not x2cScope.is_scope_data_ready():
time.sleep(0.1)
data = x2cScope.get_scope_channel_data()
-
pyX2Cscope-GUI is based on Serial interface.
-
The Firmware of the microcontroller should have the X2Cscope library/Peripheral enabled.
-
Select the COM Port, Baud Rate from the drop-down menus and the ELF file of the project, the microcontroller programmed with.
-
Sample time can be changed during run time as well, by default its set to 500ms.
-
Press on Connect
-
Once the connection between pyX2Cscope and Microcontroller takes place, the buttons will be enabled.
If you discover a bug or have an idea for an improvement, we encourage you to contribute! You can do so by following these steps:
- Fork the pyX2Cscope repository.
- Create a new branch for your changes.
- Make the necessary changes and commit them.
- Push your changes to your forked repository.
- Open a pull request on the main pyX2Cscope repository, describing your changes.
We appreciate your contribution!