python implementation of X2Cscope
Project description
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(behaviour driven development), Framework: "Cucumber"
- Different user interface
- Data collection for machine learning and training models
- Run-Time data analysis
- Use of a 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/
Install
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
In case you already have installed pyx2cscope, you only need to update the package to the new version typing:
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
Start GUI
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
Getting Started with Scripting
- 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 x2cscope 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)
Scope Functionality
- 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 eight 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)
-
Trigger Parameters:
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)
Example
x2cScope.set_scope_trigger(variable3, trigger_level=500, trigger_mode=1, trigger_delay=50, trigger_edge=1)
-
clear_trigger(): Clears and disable trigger
x2cscope.clear_trigger()
-
set_sample_time(sample_time: int): This parameter defines a pre-scaler when the scope is in the sampling mode. This can be used to extend total sampling time at cost of resolution. 0 = every sample, 1 = every second sample, 2 = every third sample …
x2cScope.set_sample_time(2)
-
is_scope_data_ready(self) → bool: Returns Scope sampling state. Returns: true if sampling has completed, false if it’s yet in progress.
while not x2cScope.is_scope_data_ready():
time.sleep(0.1)
-
get_scope_channel_data(valid_data=False) → Dict[str, List[Number]]: Once sampling is completed, this function could be used to get the sampled data.
data = x2cScope.get_scope_channel_data()
-
This data now could be used according to the preference.
Getting Started with pyX2Cscope reference GUI
Tab: WatchPlot
- pyX2Cscope-GUI is based on Serial interface.
- The Firmware of the microcontroller should have the X2Cscope library/Peripheral enabled.
- in Tab WatchPlot, five channels values can be viewed, modified and can be plotted in the plot window.
- In COM Port, either select Auto Connect or select the appropriate 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 500 ms.
- Press on Connect
- Once the connection between pyX2Cscope and Microcontroller takes place, the buttons will be enabled.
- Information related to the microcontroller will be displayed in the top-left corner.
Tab: ScopeView
- ScopeView supports up to 8 PWM resolution channels for precise signal control.
- You can configure all trigger settings directly within the window. To enable the trigger for a variable, check the corresponding trigger checkbox.
- To apply modifications during sampling, first stop the sampling, make the necessary changes, then click Sample again to update and apply the modifications.
- From the plot window, User can export the plot in various formats, including CSV, image files, Matplotlib Window, and Scalable Vector Graphics (SVG).
- To zoom in on the plot, left-click and drag on the desired area. To return to the original view, right-click and select View All.
Tab: WatchView
- WatchView lets users add or remove variables as needed. To remove a variable, click the Remove button next to it.
- Users can visualize variables in live mode with an update rate of 500 milliseconds. This rate is the default setting and cannot be changed.
- Users can select, view, and modify all global variables during runtime, providing real-time control and adjustments.
Save and Load Config.
- The Save and Load buttons, found at the bottom of the GUI, allow users to save or load the entire configuration, including the COM Port, Baud Rate, ELF file path, and all other selected variables across different tabs. This ensures a consistent setup, regardless of which tab is active.
- When a pre-saved configuration file is loaded, the system will automatically attempt to load the ELF file and establish a connection. If the ELF file is missing or unavailable at the specified path, user will need to manually select the correct ELF file path.
Contribute
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!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyx2cscope-0.3.3.tar.gz
.
File metadata
- Download URL: pyx2cscope-0.3.3.tar.gz
- Upload date:
- Size: 877.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.15 Linux/6.8.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d8b1b51c8a581ba4b327fc135a99b8354bdcdaf1ac37a42fa006e4746c9001a |
|
MD5 | abbe30c7183506158689c6fa38bd16b5 |
|
BLAKE2b-256 | e3897d55cc37291186803415acf30597b230ab00b86513f6f2ec9f5a4054e696 |
File details
Details for the file pyx2cscope-0.3.3-py3-none-any.whl
.
File metadata
- Download URL: pyx2cscope-0.3.3-py3-none-any.whl
- Upload date:
- Size: 895.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.15 Linux/6.8.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6348b1463757af4b3b697b9358d290a637616625320d5c060b777df69597094a |
|
MD5 | 8232943e32d638b45b4a7cb3c003d305 |
|
BLAKE2b-256 | 55518065bf73ba9477716331d8f2265813d7c26fd291c3a04d8e7cbfa5af7d32 |