Skip to content

Commit a34783a

Browse files
X2CscopeEdras PacolaYash Agarwal
authored
Milestone 0.4 (#78)
* Feat connect without elf (#65) * including DummyParser * DummyParser does not need an elf file, * moved locations of the images. (#67) * update blockdiagram * pyinstaller to requirements * Add build executable github actions and pyinstaller spec * add icon for windows executable * adding requirements.txt for buildexecutables * Feat unified parser (#66) * changed version number * introduced new implementation of dwarfExpr. * adding array functionality to structures. * added demo example * Feat update unit test (#64) * remove xc-16 install from github test * added pyx2cscope package install * including test for non-existing variable on 16 and 32 bits * test array pointer * Bug Fix- Single shot working. * Adding mchplnet local dependency checkout * removed repeated variable info. * Updating package dependecy versions * Add shared lib dependecy and webInterface Bash script * Feat import export variable list (#68) * adding functions to import/export variables * pickle, yaml, and elf file format * adding example program * added test to check for import/export - single variable - multiple variables - all variables - yaml, pickle, and elf file * include test for dspic33ak (#74) * CamelCase to sneak_case and bring examples to same naming convention x2c_scope * Documentation simplification and improvements. * run buildexe action only on manual trigger * Fix web interface thread (#77) * replace constructor elf to import method * web is thread safe with x2cscope * handling invalid watch and scope load files * bug, x2c is not initialized solved Co-authored-by: Edras Pacola <edras.pacola@microchip.com> Co-authored-by: Yash Agarwal <yash.agarwal@microchip.com> Co-authored-by: Mark Wendler <mark.wendler@microchip.com>
1 parent ab9b99a commit a34783a

51 files changed

Lines changed: 1818 additions & 1118 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/buildexe.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Build PyInstaller Executable
2+
3+
on:
4+
workflow_dispatch:
5+
jobs:
6+
buildwindows:
7+
runs-on: windows-latest
8+
9+
steps:
10+
- name: Checkout repository
11+
uses: actions/checkout@v4
12+
with:
13+
submodules: 'recursive'
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: '3.10'
19+
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install -r requirements.txt
24+
pip install -r quality.txt
25+
26+
- name: Build executable
27+
run: |
28+
pyinstaller --noconfirm .\pyx2cscope_win.spec
29+
30+
- name: Create startWebInterface.bat
31+
shell: cmd
32+
run: |
33+
echo pyX2Cscope.exe -w > dist\pyx2cscope\startWebInterface.bat
34+
35+
- name: Upload artifact
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: pyX2Cscope-windows
39+
path: dist/pyX2Cscope
40+
41+
42+
buildlinux:
43+
runs-on: ubuntu-latest
44+
45+
steps:
46+
- name: Checkout repository
47+
uses: actions/checkout@v4
48+
with:
49+
submodules: 'recursive'
50+
51+
- name: Set up Python
52+
uses: actions/setup-python@v5
53+
with:
54+
python-version: '3.10'
55+
56+
- name: Install dependencies
57+
run: |
58+
python -m pip install --upgrade pip
59+
pip install -r requirements.txt
60+
pip install -r quality.txt
61+
sudo apt install libxcb-xinerama0
62+
63+
- name: Build executable
64+
run: |
65+
pyinstaller --noconfirm ./pyx2cscope_linux.spec
66+
67+
- name: Create startWebInterface.sh
68+
run: |
69+
echo '#!/bin/bash' > dist/pyX2Cscope_linux/startWebInterface.sh
70+
echo './pyX2Cscope_linux -w' >> dist/pyX2Cscope_linux/startWebInterface.sh
71+
chmod +x dist/pyX2Cscope_linux/startWebInterface.sh
72+
73+
- name: Upload artifact
74+
uses: actions/upload-artifact@v4
75+
with:
76+
name: pyX2Cscope-linux
77+
path: dist/pyX2Cscope_linux

.github/workflows/documentation.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,16 @@ jobs:
5353
with:
5454
python-version: "3.10"
5555

56-
- name: Set up Microchip XC16 v2.10 compiler
57-
run: |
58-
wget -nv -O /tmp/xc16 https://ww1.microchip.com/downloads/aemDocuments/documents/DEV/ProductDocuments/SoftwareTools/xc16-v2.10-full-install-linux64-installer.run && \
59-
chmod +x /tmp/xc16 && \
60-
sudo /tmp/xc16 --mode unattended --unattendedmodeui none --netservername localhost --LicenseType FreeMode --prefix /opt/microchip/xc16/v2.10 && \
61-
rm /tmp/xc16
62-
echo "/opt/microchip/xc16/v2.10/bin" >> $GITHUB_PATH
56+
# Since we moved to generic parser, we don't need to install the xc-16 compiler anymore,
57+
# because generic parser is based on pyelftools.
58+
#
59+
# - name: Set up Microchip XC16 v2.10 compiler
60+
# run: |
61+
# wget -nv -O /tmp/xc16 https://ww1.microchip.com/downloads/aemDocuments/documents/DEV/ProductDocuments/SoftwareTools/xc16-v2.10-full-install-linux64-installer.run && \
62+
# chmod +x /tmp/xc16 && \
63+
# sudo /tmp/xc16 --mode unattended --unattendedmodeui none --netservername localhost --LicenseType FreeMode --prefix /opt/microchip/xc16/v2.10 && \
64+
# rm /tmp/xc16
65+
# echo "/opt/microchip/xc16/v2.10/bin" >> $GITHUB_PATH
6366

6467
- name: Install dependencies
6568
run: |

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,7 @@ dmypy.json
138138
/doc/_build/
139139
/doc/source/
140140
**/web/upload/
141-
**/config.ini
141+
**/config.ini
142+
143+
#backup files
144+
.bkp

README.md

Lines changed: 26 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33
</p>
44

55
# pyX2Cscope
6-
- pyX2Cscope is the Python implementation of the X2Cscope plugin from MPLABX.
7-
- This will let the user use the functionality of X2Cscope even outside mplabx environment / Standalone.
6+
The pyx2cscope Python package communicates with X2Cscope enabled firmwares running on microcontrollers. Focusing real time control applications like motor control and power conversion.
87
- It allows user to:
9-
- Automated Unit Tests (TDD) using pytest
10-
- BDD(behaviour driven development), Framework: "Cucumber"
11-
- Different user interface
12-
- Data collection for machine learning and training models
13-
- Run-Time data analysis
14-
- Use of a Real Time AI model
15-
- HiL(Hardware in the loop) testing and tuning
16-
17-
Dor detailed documentation is hosted at GitHub.io:
8+
- Read - Write variables to the embedded target in runtime
9+
- Record and Plot fast, continuous signals from the target firmware
10+
- Implement Automated Unit Tests (TDD) and HIL tests for embedded development
11+
- Record data in run-time for AI models
12+
- Implement custom user interface, dashboards for embedded applications (QT, Tkinter, Web)
13+
14+
Detailed documentation is hosted at GitHub.io:
1815
[https://x2cscope.github.io/pyx2cscope/](https://x2cscope.github.io/pyx2cscope/)
1916

2017
## Install
@@ -26,35 +23,8 @@ python -m venv .venv
2623
pip install pyx2cscope
2724
```
2825

29-
It is highly recommended to install python libraries underneath a virtual environment.
30-
31-
Nevertheless, to install at system level, we advise to install it on user area. (Global insallation may not work.)
32-
Execute the following lines:
33-
34-
```
35-
pip install --user pyx2cscope
36-
```
37-
38-
In case you already have installed pyx2cscope, you only need to update the package to the
39-
new version typing:
40-
```
41-
pip install --upgrade pyx2cscope
42-
```
43-
44-
In case of unexpected issues executing pyx2cscope try to reinstall manually:
45-
```
46-
pip uninstall pyx2cscope
47-
pip cache purge
48-
pip install --user pyx2cscope
49-
```
50-
5126
## Start GUI
5227

53-
The GUI interface
54-
55-
There are currently two implementations, one based on Qt and one Browser based. These GUIs are more examples
56-
on how to implement your own custom interfaces than an official user interface.
57-
5828
To execute Qt version, type:
5929
```
6030
pyx2cscope
@@ -65,125 +35,29 @@ To execute the Browser based version type:
6535
pyx2cscope -w
6636
```
6737

68-
## Getting Started with Scripting
38+
## Basic scripting
6939

70-
1. Go to the [Examples](https://github.com/X2Cscope/pyx2cscope/tree/main/pyx2cscope/examples) directory in the pyX2Cscope project to check out the available examples or create a new .py file according to your requirements.
71-
2. start with importing pyX2Cscope: `import pyx2cscope`
72-
3. Choose the communication interface from the interfaces' module. Currently, **Only Serial** is supported: CAN and LIN coming in near future: <br>
73-
```
74-
from x2cscope import X2CScope
75-
```
76-
1. 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:
77-
```
78-
x2cScope = X2CScope(port="COM16", elf_file=elf_file)
79-
```
80-
1. Replace the **elf_file** with the path to the ELF file of your project.
81-
2. Create a Variable object for the variable you want to monitor:
82-
```
83-
variable = x2cScope.get_variable('Variable_name')
84-
```
85-
1. Replace 'Variable_name' with the name of the variable you want to monitor. You can create multiple variable objects as required.
86-
2. Once you have gone through these steps, you can use the **get_value()** function to retrieve the value of the variable:
87-
```
88-
variable.get_value()
89-
```
90-
1. To set the value for the respective variable **set_value()**:
91-
```
92-
variable.set_value(value)
93-
```
94-
# Scope Functionality
95-
1. To use the scope functionality, add channel to the scope: **add_scope_channel(variable: Variable)** :
96-
```
97-
x2cScope.add_scope_channel(variable1)
98-
x2cScope.add_scope_channel(variable2)
99-
```
100-
1. To remove channel: **remove_scope_channel(variable: Variable)**:
101-
```
102-
x2cScope.remove_scope_channel(variable2)
103-
```
104-
1. Up to eight channels can be added.
105-
2. To Set up Trigger, any available variable can be selected, by default works on no trigger configuration.
106-
```
107-
x2cscope.set_scope_trigger(variable: Variable, trigger_level: int, trigger_mode: int, trigger_delay: int, trigger_edge: int)
108-
```
109-
1. ##### Trigger Parameters:
110-
```
111-
srcChannel: TriggerChannel (variable)
112-
Level: trigger_level
113-
Trigger_mode: 1 for triggered, 0 for Auto (No trigger)
114-
Trigger_delay = Value > 0 Pre-trigger, Value < 0 Post trigger
115-
Trigger_Edge: Rising (1) or Falling (0)
116-
```
117-
#### Example
118-
```
119-
x2cScope.set_scope_trigger(variable3, trigger_level=500, trigger_mode=1, trigger_delay=50, trigger_edge=1)
120-
```
121-
122-
1. ##### **clear_trigger()**: Clears and disable trigger
123-
```
124-
x2cscope.clear_trigger()
125-
```
126-
1. #### **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 …
127-
```
128-
x2cScope.set_sample_time(2)
129-
```
130-
1. #### is_scope_data_ready(self) → bool: Returns Scope sampling state. Returns: true if sampling has completed, false if it’s yet in progress.
131-
```
132-
while not x2cScope.is_scope_data_ready():
133-
time.sleep(0.1)
134-
```
135-
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.
136-
```
137-
data = x2cScope.get_scope_channel_data()
138-
```
139-
1. #### This data now could be used according to the preference.
140-
141-
## Getting Started with pyX2Cscope reference GUI
142-
## Tab: WatchPlot
143-
![WatchPlot](https://raw.githubusercontent.com/X2Cscope/pyx2cscope/refs/heads/main/pyx2cscope/gui/img/NewGui.jpg)
144-
1. pyX2Cscope-GUI is based on Serial interface.
145-
2. The Firmware of the microcontroller should have the X2Cscope library/Peripheral enabled.
146-
3. in Tab WatchPlot, five channels values can be viewed, modified and can be plotted in the plot window.
147-
4. 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. <br>
148-
5. Sample time can be changed during run time as well, by default its set to 500 ms.
149-
6. Press on **Connect**
150-
7. Once the connection between pyX2Cscope and Microcontroller takes place, the buttons will be enabled.
151-
8. Information related to the microcontroller will be displayed in the top-left corner.
152-
153-
## Tab: ScopeView
154-
![ScopeView](https://raw.githubusercontent.com/X2Cscope/pyx2cscope/refs/heads/main/pyx2cscope/gui/img/NewGui2.jpg)
155-
156-
1. ScopeView supports up to 8 PWM resolution channels for precise signal control.
157-
2. You can configure all trigger settings directly within the window. To enable the trigger for a variable, check the corresponding trigger checkbox.
158-
3. To apply modifications during sampling, first stop the sampling, make the necessary changes, then click Sample again to update and apply the modifications.
159-
4. From the plot window, User can export the plot in various formats, including CSV, image files, Matplotlib Window, and Scalable Vector Graphics (SVG).
160-
5. 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.
40+
```py
41+
from pyx2cscope.x2cscope import X2CScope
16142

162-
## Tab: WatchView
163-
![WatchView](https://raw.githubusercontent.com/X2Cscope/pyx2cscope/refs/heads/main/pyx2cscope/gui/img/NewGui3.jpg)
164-
165-
1. WatchView lets users add or remove variables as needed. To remove a variable, click the Remove button next to it.
166-
2. Users can visualize variables in live mode with an update rate of 500 milliseconds. This rate is the default setting and cannot be changed.
167-
3. Users can select, view, and modify all global variables during runtime, providing real-time control and adjustments.
168-
169-
## Save and Load Config.
170-
1. 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.
171-
2. 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.
172-
173-
## Contribute
174-
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:
175-
176-
1. Fork the pyX2Cscope repository.
177-
2. Create a new branch for your changes.
178-
3. Make the necessary changes and commit them.
179-
4. Push your changes to your forked repository.
180-
5. Open a pull request on the main pyX2Cscope repository, describing your changes.
181-
182-
We appreciate your contribution!
43+
# initialize the X2CScope class with serial port, by default baud rate is 115200
44+
x2c_scope = X2CScope(port="COM8")
45+
# instead of loading directly the elf file, we can import it after instantiating the X2CScope class
46+
x2c_scope.import_variables(r"..\..\tests\data\qspin_foc_same54.elf")
18347

48+
# Collect some variables.
49+
speed_reference = x2c_scope.get_variable("motor.apiData.velocityReference")
50+
speed_measured = x2c_scope.get_variable("motor.apiData.velocityMeasured")
18451

52+
# Read the value of the "motor.apiData.velocityMeasured" variable from the target
53+
print(speed_measured.get_value())
54+
# Write a new value to the "motor.apiData.velocityReference" variable on the target
55+
speed_reference.set_value(1000)
56+
```
18557

186-
-------------------------------------------------------------------
58+
Further [Examples](https://github.com/X2Cscope/pyx2cscope/tree/main/pyx2cscope/examples) directory in the pyX2Cscope project to check out the available examples or create a new .py file according to your requirements.
18759

60+
## Development
18861

62+
[https://github.com/X2Cscope/pyx2cscope/tree/main/doc/development.md](https://github.com/X2Cscope/pyx2cscope/tree/main/doc/development.md)
18963

doc/.$class_chart.drawio.bkp

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)