Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Commit 04fb8ff

Browse files
committed
Merge branch 'users/t-anmah/debugger-socket-fix' of https://github.com/microsoft/vscode-python-devicesimulator into users/t-anmah/debugger-socket-fix
2 parents 9e10e08 + b8d46b8 commit 04fb8ff

29 files changed

+1148
-477
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ out/
88
!locales/**/out/
99
package.nls.*.json
1010

11+
# virtual environment
12+
venv/
13+
1114
# testing
1215
.vscode-test
1316

README.md

Lines changed: 70 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
<a href="https://microsoftgarage.visualstudio.com/002806e2-ebaa-4672-9d2e-5fe5d29154ef/_boards/board/t/227906bb-31ac-4b07-8626-3d757754a616/Microsoft.RequirementCategory/"><img src="https://microsoftgarage.visualstudio.com/002806e2-ebaa-4672-9d2e-5fe5d29154ef/227906bb-31ac-4b07-8626-3d757754a616/_apis/work/boardbadge/73f82653-3da1-4a6f-bb79-c91c9eecec28" alt="Azure DevOps Board Badge" /></a>
66

7-
Make without limit! Device Simulator Express, a Microsoft Garage project, allows you to code in CircuitPython for your awesome
8-
Circuit Playground Express (CPX) projects! Test and debug your code on the device simulator and see the same
7+
Make without limit! Device Simulator Express, a Microsoft Garage project, allows you to code microcontrollers without the hardware on hand! You can program your Circuit Playground Express (CPX) or your BBC micro:bit! Test and debug your code on the device simulator and see the same
98
result when you plug in your actual microcontroller. Curious about the output of the device, the serial
109
monitor allows you to observe the device output.
1110

@@ -20,9 +19,21 @@ monitor allows you to observe the device output.
2019
| master | [![Build Status](https://microsoftgarage.visualstudio.com/Intern%20GitHub/_apis/build/status/Adafruit/Pacifica-CI?branchName=master)](https://microsoftgarage.visualstudio.com/Intern%20GitHub/_build/latest?definitionId=304&branchName=master) |
2120

2221

23-
## Features
22+
## Prerequisites
23+
24+
The following dependencies are required to install before launching Device Simulator Express.
25+
You will be prompted to install the Python dependencies during the first use.
26+
27+
- _**[Visual Studio Code](https://code.visualstudio.com/)**_
28+
- _**[Node](https://nodejs.org/en/download/)**_
29+
- _**[Python 3.7+](https://www.python.org/downloads/)**_: Make sure you've added python and pip to your PATH in your environment variables. (1)
30+
- _**[Python VS Code extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python)**_: This will be installed automatically from the marketplace when you install Device Simulator Express.
31+
32+
## Circuit Playground Express (CPX) Simulator
2433

25-
- IntelliSense and syntax highlighting for CircuitPython code (only supports CPX Express library)
34+
### Features
35+
36+
- IntelliSense and syntax highlighting for CircuitPython code
2637
- Template file generation
2738
- Integrated Python Debugging for the Simulator
2839
- Serial monitor (available on Windows and Mac only)
@@ -46,27 +57,10 @@ The simulator supports most of the sensors on CPX except **IR transmitter & Rece
4657
The code related to these sensors can still run on the actual CPX board and be deployed using Device Simulator Express.
4758
As we only support CPX library now, other libraries (i.e. simpleio) can’t run on the simulator. But they will work on the actual device!
4859

49-
## Prerequisites
50-
51-
The following dependencies are required to install before launching Device Simulator Express.
52-
You will be prompted to install the Python dependencies during the first use.
53-
54-
- _**[Visual Studio Code](https://code.visualstudio.com/)**_
55-
- _**[Node](https://nodejs.org/en/download/)**_
56-
- _**[Python 3.7.4](https://www.python.org/downloads/)**_: Make sure you've added python and pip to your PATH in your environment variables. (1)
57-
- _**[Python VS Code extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python)**_: This will be installed automatically from the marketplace when you install Device Simulator Express.
5860

59-
- Python Modules for Simulation
60-
- **Note:** On extension activation, you will be prompted with a popup message asking if you want the modules to be automatically installed for you. The following Python modules should be downloaded when you select "yes" on the prompt message. **If modules are not installed correctly, please use the "pip install" commands listed below.**
61-
- Playsound : `pip install playsound`
62-
- Pywin32 : `pip install pywin32`
63-
- On Windows, you need to use the above command in the console to manually install pywin32.
64-
- Python-Socketio : `pip install python-socketio`
65-
- Requests : `pip install requests`
66-
- Application Insights: `pip install applicationinsights`
6761

6862

69-
## Useful Links
63+
### Useful Links
7064
- Tutorials and Example Code for Adafruit CPX:
7165
- [Adafruit CPX library tutorial](https://learn.adafruit.com/circuitpython-made-easy-on-circuit-playground-express/circuit-playground-express-library)
7266
- [Adafruit CPX Examples on GitHub](https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/master/examples)
@@ -75,35 +69,33 @@ You will be prompted to install the Python dependencies during the first use.
7569
- [Tutorial for formatting Adafruit CPX for CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython)
7670
- [Download Firmware .uf2 file](https://learn.adafruit.com/adafruit-circuit-playground-express/circuitpython-quickstart)
7771
- [Download the latest version of the Adafruit CPX library](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries)
78-
- For developers:
79-
- [Steps to run the extension locally](/docs/developers-setup.md)
8072

81-
## How to use
73+
### How to use
8274

8375
To use Device Simulator Express, install the extension from the marketplace and reload VS Code.
8476

85-
### 1. Start with the "New File" Command.
77+
#### 1. Start with the "Device Simulator Express [Circuit Playground Express]: New File" Command.
8678

87-
1. Type in `"Device Simulator Express: New File"` in the command palette (`CTRL+SHIFT+P` to open the command palette).
79+
1. Type in `"Device Simulator Express: [Circuit Playground Express] New File"` in the command palette (`CTRL+SHIFT+P` to open the command palette).
8880
<img alt='"New File" animation' src=https://raw.githubusercontent.com/microsoft/vscode-python-devicesimulator/dev/assets/readmeFiles/newFile.gif>
8981
2. Name and save your file somewhere, and we’re good to go! (3)
90-
3. Start with some examples: you can find examples files and tutorials inside the comments, as well as in the notification pop up when you run the `"Device Simulator Express: New File"` Command.
82+
3. Start with some examples: you can find examples files and tutorials inside the comments, as well as in the notification pop up when you run the `"Device Simulator Express: [Circuit Playground Express] New File"` Command.
9183

9284
<img alt='How to find example code screenshot' src=https://raw.githubusercontent.com/microsoft/vscode-python-devicesimulator/dev/assets/readmeFiles/findExamples.jpg>
9385

94-
### 2. Start from an existing python file.
86+
#### 2. Start from an existing python file.
9587

9688
1. Open the folder or your .py file in Visual Studio Code.
97-
2. Run `open Simulator` from the command palette or icon in the editor toolbar.
89+
2. Run `Device Simulator Express: [Circuit Playground Express] Open Simulator` from the command palette or icon in the editor toolbar.
9890

99-
### 3. Run your code on the simulator.
91+
#### 3. Run your code on the simulator.
10092

10193
<img alt='How to run the simulator animation' src='https://github.com/microsoft/vscode-python-devicesimulator/blob/dev/assets/readmeFiles/run.gif?raw=true'>
10294

10395
- Run `Run Simulator` from the command palette or icon in the editor toolbar.
10496
- You can use the `Play` or `Refresh` button on the simulator webview.
10597

106-
### 4. Deploy your code to the physical device
98+
#### 4. Deploy your code to the physical device
10799

108100
Before deploying the python code to your CPX device, you need to format your device following these tutorials:
109101

@@ -115,14 +107,14 @@ Then, if you are on Windows, you will also need to install the Python Pywin32 pa
115107

116108
<img alt="Deploy to Device" src=https://raw.githubusercontent.com/microsoft/vscode-python-devicesimulator/dev/assets/readmeFiles/deployToBoard.png>
117109

118-
### 5. Use the Serial Monitor for your Adafruit CPX device (available on Windows and Mac only)
110+
#### 5. Use the Serial Monitor for your Adafruit CPX device (available on Windows and Mac only)
119111

120112
1. Plug in your CPX device (make sure it’s formatted properly already)
121-
2. Run the command `"Device Simulator Express: Open Serial Monitor"`
113+
2. Run the command `"Device Simulator Express: [Circuit Playground Express] Open Serial Monitor"`
122114
3. Select your baud rate for the serial port
123115
4. The print() statements in your code will show in the output console
124116

125-
### 6. Use the sensors in the Device Simulator Express
117+
#### 6. Use the sensors in the Device Simulator Express
126118

127119
Generating input for the sensors can be done by interacting directly with device on the webview
128120
or by using the toolbar.
@@ -131,25 +123,25 @@ or by using the toolbar.
131123
- **Temperature sensor, Light sensor, acceleration:** click on the corresponding button in the toolbar and change the value using the slider or the input box attached to it.
132124
- **Shake detection:** go to the motion sensor section in the toolbar and click on the shake button.
133125

134-
### 7. Debug your project on the simulator
126+
#### 7. Debug your project on the simulator
135127

136128
1. Add breakpoints in your code
137129
2. Press F5 to enter the debugging mode, and you can start debugging line by line!
138130

139-
## Commands
131+
### Commands
140132

141133
Device Simulator Express provides several commands in the Command Palette (F1 or Ctrl + Shift + P/ Cmd + Shift + P for Mac OS) for working with \*.py files:
142134

143-
- `Device Simulator Express: New File`: Opens an unsaved .py file with template code, also opens the simulator.
144-
- `Device Simulator Express: Open Simulator`: Opens the simulator in the webView
145-
- `Device Simulator Express: Run on Simulator`: Runs python code on the simulator
146-
- `Device Simulator Express: Deploy to Device`: Copies & Pastes the code.py or main.py file to CIRCUITPY drive if detected a CPX is plugged in
147-
- `Device Simulator Express: Open Serial Monitor`: Opens the serial monitor in the integrated output window.
148-
- `Device Simulator Express: Close Serial Monitor`: Stops the serial monitor and releases the serial port.
149-
- `Device Simulator Express: Change Baud Rate`: Changes the baud rate of the selected serial port. For Adafruit CPX, the default baud rate is 115200.
150-
- `Device Simulator Express: Select Serial Port`: Changes the current serial port.
135+
- `Device Simulator Express: [Circuit Playground Express] New File`: Opens an unsaved .py file with template code, also opens the simulator.
136+
- `Device Simulator Express: [Circuit Playground Express] Open Simulator`: Opens the simulator in the webView
137+
- `Device Simulator Express: [Circuit Playground Express] Run on Simulator`: Runs python code on the simulator
138+
- `Device Simulator Express: [Circuit Playground Express] Deploy to Device`: Copies & Pastes the code.py or main.py file to CIRCUITPY drive if detected a CPX is plugged in
139+
- `Device Simulator Express: [Circuit Playground Express] Open Serial Monitor`: Opens the serial monitor in the integrated output window.
140+
- `Device Simulator Express: [Circuit Playground Express] Close Serial Monitor`: Stops the serial monitor and releases the serial port.
141+
- `Device Simulator Express: [Circuit Playground Express] Change Baud Rate`: Changes the baud rate of the selected serial port. For Adafruit CPX, the default baud rate is 115200.
142+
- `Device Simulator Express: [Circuit Playground Express] Select Serial Port`: Changes the current serial port.
151143

152-
## Keybindings
144+
### Keybindings
153145

154146
In Device Simulator Express, you can use keyboard to interact with the device:
155147

@@ -158,6 +150,37 @@ In Device Simulator Express, you can use keyboard to interact with the device:
158150
- Slider Switch: `SHIFT + S`
159151
- Refresh the simulator: `SHIFT + R`
160152

153+
154+
## BBC micro:bit Simulator
155+
>**NOTE 1**: this feature is hidden by default. To use it, enable the feature flag in the "deviceSimulatorExpress.previewMode" user setting.
156+
157+
>**NOTE 2**: micro:bit simulation is still in development. Features may not work as intended.
158+
159+
### Features
160+
- IntelliSense and syntax highlighting for micro:bit code
161+
- Template file generation
162+
- Integrated Python Debugging for the Simulator
163+
- Simulation of the micro:bit device, including:
164+
- 25 LEDs
165+
- Light sensor
166+
- Motion sensors
167+
- Acceleration detection
168+
- Temperature sensor
169+
170+
### How to use
171+
Using the simulator for the micro:bit is similar to using the one for the CPX. The only difference is that the commands in the command palette display `Device Simulator Express: [micro:bit] <command>` instead of `Device Simulator Express: [Circuit Playground Express] <command>`. Currently, we support the following commands for micro:bit:
172+
- `Device Simulator Express: [micro:bit] Open Simulator`: Opens an unsaved .py file with template code, also opens the simulator.
173+
- `Device Simulator Express: [micro:bit] New File`: Opens the simulator in the webView
174+
175+
Please review the CPX's ["How to use" guide](#How-to-use) for more info.
176+
177+
### Keybindings
178+
- Push Button `A & B: A B`
179+
- Refresh the simulator: `SHIFT + R`
180+
181+
## Contribute
182+
[See here for steps to run the extension locally.](/docs/developers-setup.md)
183+
161184
## Provide feedback
162185

163186
To report issues, provide feedback or requests, please use this link: [Provide Feedback](https://aka.ms/AA5xpxx).
@@ -196,7 +219,7 @@ A `ThirdPartyNotices.txt` file is provided in the extension's source code listin
196219
- While running a code file, if you get an error saying it can't find the file, make sure you've clicked on a valid Python code file before running it.
197220
- To open the output panel again after closing it go to VS Code menu: `View->Output`.
198221
- If you try to deploy to the device while it's plugged in but you still get an error saying it cannot find the board, make sure your Circuit Playground Express is formatted correctly and that its name matches `CIRCUITPY`.
199-
- If you can't get the Simulator communication working while debugging, try to open your `Settings` and check the port used under `"Device Simulator Express: Debugger Server Port"`. You can either change it (usually ports above 5000 should work) or try to free it, then start debugging again.
222+
- If you can't get the Simulator communication working while debugging, try to open your `Settings` and check the port used under `"Device Simulator Express: [<device_name>] Debugger Server Port"`. You can either change it (usually ports above 5000 should work) or try to free it, then start debugging again.
200223
- When you are using the serial monitor, if you get some unusual error messages, unplug the device and reload the VS Code windows.
201224

202225
## License

locales/en/out/constants.i18n.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"info.deploySimulator": "\n[INFO] Deploying code to the simulator...\n",
2828
"info.deploySuccess": "\n[INFO] Code successfully deployed\n",
2929
"info.extensionActivated": "Congratulations, your extension Adafruit_Simulator is now active!",
30-
"info.firstTimeWebview": "To reopen the simulator click on the \"Open Simulator\" button on the upper right corner of the text editor, or select the command \"Open Simulator\" from command palette.",
30+
"info.firstTimeWebview": "To reopen the simulator select the command \"Open Simulator\" from command palette.",
3131
"info.installPythonDependencies": "Do you want us to try and install this extensions dependencies for you?",
3232
"error.invalidFileExtensionDebug": "The file you tried to run isn\\'t a Python file.",
3333
"info.newFile": "New to Python or the Circuit Playground Express? We are here to help!",
@@ -36,7 +36,7 @@
3636
"info.privacyStatement": "Privacy Statement",
3737
"info.successfulInstall": "Successfully installed Python dependencies.",
3838
"info.thirdPartyWebsite": "By clicking \"Agree and Proceed\" you will be redirected to adafruit.com, a third party website not managed by Microsoft. Please note that your activity on adafruit.com is subject to Adafruit's privacy policy",
39-
"info.welcomeOutputTab": "Welcome to the Adafruit Simulator output tab!\n\n",
39+
"info.welcomeOutputTab": "Welcome to the Device Simulator Express output tab!\n\n",
4040
"label.webviewPanel": "Device Simulator Express",
4141
"name": "Device Simulator Express",
4242

locales/en/package.i18n.json

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
{
2-
"deviceSimulatorExpressExtension.commands.common.installDependencies": "Install Extension Dependencies",
3-
"deviceSimulatorExpressExtension.commands.common.label": "Device Simulator Express",
4-
"deviceSimulatorExpressExtension.commands.common.runSimulator": "Run Simulator",
5-
"deviceSimulatorExpressExtension.commands.cpx.changeBaudRate": "[Circuit Playground Express] Change Baud Rate",
6-
"deviceSimulatorExpressExtension.commands.cpx.closeSerialMonitor": "[Circuit Playground Express] Close Serial Monitor",
7-
"deviceSimulatorExpressExtension.commands.cpx.openSerialMonitor": "[Circuit Playground Express] Open Serial Monitor",
8-
"deviceSimulatorExpressExtension.commands.cpx.openSimulator": "[Circuit Playground Express] Open Simulator",
9-
"deviceSimulatorExpressExtension.commands.cpx.newFile": "[Circuit Playground Express] New File",
10-
"deviceSimulatorExpressExtension.commands.cpx.deployToDevice": "[Circuit Playground Express] Deploy to Device",
11-
"deviceSimulatorExpressExtension.commands.cpx.selectSerialPort": "[Circuit Playground Express] Select Serial Port",
12-
"deviceSimulatorExpressExtension.commands.microbit.openSimulator": "[micro:bit] Open Simulator",
13-
"deviceSimulatorExpressExtension.commands.microbit.newFile": "[micro:bit] New File",
14-
"deviceSimulatorExpressExtension.configuration.title": "Device Simulator Express configuration",
15-
"deviceSimulatorExpressExtension.configuration.properties.debuggerPort": "The port the Server will listen on for communication with the debugger."
16-
}
1+
{
2+
"deviceSimulatorExpressExtension.commands.common.installDependencies": "Install Extension Dependencies",
3+
"deviceSimulatorExpressExtension.commands.common.label": "Device Simulator Express",
4+
"deviceSimulatorExpressExtension.commands.common.runSimulator": "Run Simulator",
5+
"deviceSimulatorExpressExtension.commands.cpx.changeBaudRate": "[Circuit Playground Express] Change Baud Rate",
6+
"deviceSimulatorExpressExtension.commands.cpx.closeSerialMonitor": "[Circuit Playground Express] Close Serial Monitor",
7+
"deviceSimulatorExpressExtension.commands.cpx.openSerialMonitor": "[Circuit Playground Express] Open Serial Monitor",
8+
"deviceSimulatorExpressExtension.commands.cpx.openSimulator": "[Circuit Playground Express] Open Simulator",
9+
"deviceSimulatorExpressExtension.commands.cpx.newFile": "[Circuit Playground Express] New File",
10+
"deviceSimulatorExpressExtension.commands.cpx.deployToDevice": "[Circuit Playground Express] Deploy to Device",
11+
"deviceSimulatorExpressExtension.commands.cpx.selectSerialPort": "[Circuit Playground Express] Select Serial Port",
12+
"deviceSimulatorExpressExtension.commands.microbit.openSimulator": "[micro:bit] Open Simulator",
13+
"deviceSimulatorExpressExtension.commands.microbit.newFile": "[micro:bit] New File",
14+
"deviceSimulatorExpressExtension.configuration.title": "Device Simulator Express configuration",
15+
"deviceSimulatorExpressExtension.configuration.properties.configEnvOnChange": "When you change the Python interpreter, the Device Simulator Express will automatically configure itself for the required dependencies.",
16+
"deviceSimulatorExpressExtension.configuration.properties.debuggerPort": "The port the Server will listen on for communication with the debugger.",
17+
"deviceSimulatorExpressExtension.configuration.properties.dependencyChecker": "Whether or not to ask if we can download dependencies. If unchecked, the extension will default to never download dependencies, except when automatically creating a virtual environment in the extension files."
18+
"deviceSimulatorExpressExtension.configuration.properties.previewMode": "Enable this to test out and play with the new micro:bit simulator!"
19+
}

0 commit comments

Comments
 (0)