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

Get serial monitor working with micro:bit and CPX #242

Merged
merged 3 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Then, if you are on Windows, you will also need to install the Python Pywin32 pa
#### 5. Use the Serial Monitor for your Adafruit CPX device (available on Windows and Mac only)

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

Expand All @@ -135,10 +135,10 @@ Device Simulator Express provides several commands in the Command Palette (F1 or
- `Device Simulator Express: [Circuit Playground Express] Open Simulator`: Opens the simulator in the webView
- `Device Simulator Express: [Circuit Playground Express] Run on Simulator`: Runs python code on the simulator
- `Device Simulator Express: [Circuit Playground Express] Deploy to Device`: Copies & Pastes the current file to CIRCUITPY drive if detected a CPX is plugged in
- `Device Simulator Express: [Circuit Playground Express] Open Serial Monitor`: Opens the serial monitor in the integrated output window.
- `Device Simulator Express: [Circuit Playground Express] Close Serial Monitor`: Stops the serial monitor and releases the serial port.
- `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.
- `Device Simulator Express: [Circuit Playground Express] Select Serial Port`: Changes the current serial port.
- `Device Simulator Express: Open Serial Monitor`: Opens the serial monitor in the integrated output window.
- `Device Simulator Express: Close Serial Monitor`: Stops the serial monitor and releases the serial port.
- `Device Simulator Express: Change Baud Rate`: Changes the baud rate of the selected serial port. For Adafruit CPX and the BBC micro:bit, the default baud rate is 115200.
- `Device Simulator Express: Select Serial Port`: Changes the current serial port.

### Keybindings

Expand All @@ -159,7 +159,8 @@ In Device Simulator Express, you can use keyboard to interact with the device:
- IntelliSense and syntax highlighting for micro:bit code
- Template file generation
- Integrated Python Debugging for the Simulator
- Deploy MicroPython code to the physical device.
- Deploy MicroPython code to the physical device
- Serial monitor (available on Windows and Mac only)
- Simulation of the micro:bit device, including:
- 25 LEDs
- Light sensor
Expand Down
6 changes: 3 additions & 3 deletions docs/how-to-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Commands are accessible through :
- **Run Simulator** : runs the code you have opened in the simulator (make sure you've clicked on a valid code file).
_(**Note :** will open the simulator webview if it's not open yet)_.

- **Deploy to Device** : saves the code to a Circuit Playground Express.
_(**Note :** the board needs to be correctly formatted to a `CIRCUITPY` drive first. If that's not the case check [Installing CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython) to correctly format it)_.
- **Deploy to Device** : saves the code to the connected device.
_(**Note :** For the Circuit Playground Express, the board needs to be correctly formatted to a `CIRCUITPY` drive first. If that's not the case check [Installing CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython) to correctly format it)_.

* **Select Serial Port** : selects the serial port of the board you want the serial monitor to interact with. (2)
_(**Note :** USB detection must be enabled in the extension settings.)_
Expand Down Expand Up @@ -82,7 +82,7 @@ Here are the settings you can change in the Device Simulator Express configurati
- The first time you install the extension, you'll need to execute the `run` command at least once in order to access auto-completion.
- 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.
- To open the output panel again after closing it go to VS Code menu : `View->Output`.
- 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`.
- For the Circuit Playground Express, 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`.
- If you can't get the Simulator communication working while debugging, try to open you `Settings` and check the port used under `'Device Simulator Express: Debugger Server Port'`. You can either change it (usually ports above 5000 could work) or try to free it, then start debugging again.

### Notes
Expand Down
8 changes: 4 additions & 4 deletions locales/en/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"deviceSimulatorExpressExtension.commands.common.installDependencies": "Install Extension Dependencies",
"deviceSimulatorExpressExtension.commands.common.label": "Device Simulator Express",
"deviceSimulatorExpressExtension.commands.common.runSimulator": "Run Simulator",
"deviceSimulatorExpressExtension.commands.cpx.changeBaudRate": "[Circuit Playground Express] Change Baud Rate",
"deviceSimulatorExpressExtension.commands.cpx.closeSerialMonitor": "[Circuit Playground Express] Close Serial Monitor",
"deviceSimulatorExpressExtension.commands.cpx.openSerialMonitor": "[Circuit Playground Express] Open Serial Monitor",
"deviceSimulatorExpressExtension.commands.common.changeBaudRate": "Change Baud Rate",
"deviceSimulatorExpressExtension.commands.common.closeSerialMonitor": "Close Serial Monitor",
"deviceSimulatorExpressExtension.commands.common.openSerialMonitor": "Open Serial Monitor",
"deviceSimulatorExpressExtension.commands.common.selectSerialPort": "Select Serial Port",
"deviceSimulatorExpressExtension.commands.cpx.openSimulator": "[Circuit Playground Express] Open Simulator",
"deviceSimulatorExpressExtension.commands.cpx.newFile": "[Circuit Playground Express] New File",
"deviceSimulatorExpressExtension.commands.cpx.deployToDevice": "[Circuit Playground Express] Deploy to Device",
"deviceSimulatorExpressExtension.commands.cpx.selectSerialPort": "[Circuit Playground Express] Select Serial Port",
"deviceSimulatorExpressExtension.commands.microbit.deployToDevice": "[micro:bit] Deploy to Device",
"deviceSimulatorExpressExtension.commands.microbit.openSimulator": "[micro:bit] Open Simulator",
"deviceSimulatorExpressExtension.commands.microbit.newFile": "[micro:bit] New File",
Expand Down
37 changes: 19 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
],
"activationEvents": [
"onCommand:deviceSimulatorExpress.common.installDependencies",
"onCommand:deviceSimulatorExpress.common.openSerialMonitor",
"onCommand:deviceSimulatorExpress.common.runSimulator",
"onCommand:deviceSimulatorExpress.common.selectSerialPort",
"onCommand:deviceSimulatorExpress.cpx.deployToDevice",
"onCommand:deviceSimulatorExpress.cpx.newFile",
"onCommand:deviceSimulatorExpress.cpx.openSerialMonitor",
"onCommand:deviceSimulatorExpress.cpx.openSimulator",
"onCommand:deviceSimulatorExpress.cpx.selectSerialPort",
"onCommand:deviceSimulatorExpress.microbit.deployToDevice",
"onCommand:deviceSimulatorExpress.microbit.newFile",
"onCommand:deviceSimulatorExpress.microbit.openSimulator",
Expand All @@ -51,43 +51,44 @@
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.common.runSimulator",
"title": "%deviceSimulatorExpressExtension.commands.common.runSimulator%",
"command": "deviceSimulatorExpress.common.changeBaudRate",
"title": "%deviceSimulatorExpressExtension.commands.common.changeBaudRate%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.cpx.changeBaudRate",
"title": "%deviceSimulatorExpressExtension.commands.cpx.changeBaudRate%",
"command": "deviceSimulatorExpress.common.closeSerialMonitor",
"title": "%deviceSimulatorExpressExtension.commands.common.closeSerialMonitor%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.cpx.closeSerialMonitor",
"title": "%deviceSimulatorExpressExtension.commands.cpx.closeSerialMonitor%",

"command": "deviceSimulatorExpress.common.openSerialMonitor",
"title": "%deviceSimulatorExpressExtension.commands.common.openSerialMonitor%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.cpx.deployToDevice",
"title": "%deviceSimulatorExpressExtension.commands.cpx.deployToDevice%",
"command": "deviceSimulatorExpress.common.selectSerialPort",
"title": "%deviceSimulatorExpressExtension.commands.common.selectSerialPort%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.cpx.newFile",
"title": "%deviceSimulatorExpressExtension.commands.cpx.newFile%",
"command": "deviceSimulatorExpress.common.runSimulator",
"title": "%deviceSimulatorExpressExtension.commands.common.runSimulator%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.cpx.openSerialMonitor",
"title": "%deviceSimulatorExpressExtension.commands.cpx.openSerialMonitor%",
"command": "deviceSimulatorExpress.cpx.deployToDevice",
"title": "%deviceSimulatorExpressExtension.commands.cpx.deployToDevice%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.cpx.openSimulator",
"title": "%deviceSimulatorExpressExtension.commands.cpx.openSimulator%",
"command": "deviceSimulatorExpress.cpx.newFile",
"title": "%deviceSimulatorExpressExtension.commands.cpx.newFile%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.cpx.selectSerialPort",
"title": "%deviceSimulatorExpressExtension.commands.cpx.selectSerialPort%",
"command": "deviceSimulatorExpress.cpx.openSimulator",
"title": "%deviceSimulatorExpressExtension.commands.cpx.openSimulator%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
Expand Down
8 changes: 4 additions & 4 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"deviceSimulatorExpressExtension.commands.common.installDependencies": "Install Extension Dependencies",
"deviceSimulatorExpressExtension.commands.common.label": "Device Simulator Express",
"deviceSimulatorExpressExtension.commands.common.runSimulator": "Run Simulator",
"deviceSimulatorExpressExtension.commands.cpx.changeBaudRate": "[Circuit Playground Express] Change Baud Rate",
"deviceSimulatorExpressExtension.commands.cpx.closeSerialMonitor": "[Circuit Playground Express] Close Serial Monitor",
"deviceSimulatorExpressExtension.commands.cpx.openSerialMonitor": "[Circuit Playground Express] Open Serial Monitor",
"deviceSimulatorExpressExtension.commands.common.changeBaudRate": "Change Baud Rate",
"deviceSimulatorExpressExtension.commands.common.closeSerialMonitor": "Close Serial Monitor",
"deviceSimulatorExpressExtension.commands.common.openSerialMonitor": "Open Serial Monitor",
"deviceSimulatorExpressExtension.commands.common.selectSerialPort": "Select Serial Port",
"deviceSimulatorExpressExtension.commands.cpx.openSimulator": "[Circuit Playground Express] Open Simulator",
"deviceSimulatorExpressExtension.commands.cpx.newFile": "[Circuit Playground Express] New File",
"deviceSimulatorExpressExtension.commands.cpx.deployToDevice": "[Circuit Playground Express] Deploy to Device",
"deviceSimulatorExpressExtension.commands.cpx.selectSerialPort": "[Circuit Playground Express] Select Serial Port",
"deviceSimulatorExpressExtension.commands.microbit.deployToDevice": "[micro:bit] Deploy to Device",
"deviceSimulatorExpressExtension.commands.microbit.openSimulator": "[micro:bit] Open Simulator",
"deviceSimulatorExpressExtension.commands.microbit.newFile": "[micro:bit] New File",
Expand Down
8 changes: 4 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,14 @@ export enum TelemetryEventName {
COMMAND_RUN_SIMULATOR_BUTTON = "COMMAND.RUN.SIMULATOR_BUTTON",
COMMAND_RUN_PALETTE = "COMMAND.RUN.PALETTE",
COMMAND_INSTALL_EXTENSION_DEPENDENCIES = "COMMAND.INSTALL.EXTENSION.DEPENDENCIES",
COMMAND_SERIAL_MONITOR_CHOOSE_PORT = "COMMAND.SERIAL_MONITOR.CHOOSE_PORT",
COMMAND_SERIAL_MONITOR_OPEN = "COMMAND.SERIAL_MONITOR.OPEN",
COMMAND_SERIAL_MONITOR_BAUD_RATE = "COMMAND.SERIAL_MONITOR.BAUD_RATE",
COMMAND_SERIAL_MONITOR_CLOSE = "COMMAND.SERIAL_MONITOR.CLOSE",

CPX_COMMAND_DEPLOY_DEVICE = "CPX.COMMAND.DEPLOY.DEVICE",
CPX_COMMAND_NEW_FILE = "CPX.COMMAND.NEW.FILE.CPX",
CPX_COMMAND_OPEN_SIMULATOR = "CPX.COMMAND.OPEN.SIMULATOR",
CPX_COMMAND_SERIAL_MONITOR_CHOOSE_PORT = "CPX.COMMAND.SERIAL_MONITOR.CHOOSE_PORT",
CPX_COMMAND_SERIAL_MONITOR_OPEN = "CPX.COMMAND.SERIAL_MONITOR.OPEN",
CPX_COMMAND_SERIAL_MONITOR_BAUD_RATE = "CPX.COMMAND.SERIAL_MONITOR.BAUD_RATE",
CPX_COMMAND_SERIAL_MONITOR_CLOSE = "CPX.COMMAND.SERIAL_MONITOR.CLOSE",

MICROBIT_COMMAND_DEPLOY_DEVICE = "MICROBIT.COMMAND.DEPLOY.DEVICE",
MICROBIT_COMMAND_NEW_FILE = "MICROBIT.COMMAND.NEW.FILE",
Expand Down
32 changes: 16 additions & 16 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,13 +860,13 @@ export async function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(serialMonitor);
}

const cpxSelectSerialPort: vscode.Disposable = vscode.commands.registerCommand(
"deviceSimulatorExpress.cpx.selectSerialPort",
const selectSerialPort: vscode.Disposable = vscode.commands.registerCommand(
"deviceSimulatorExpress.common.selectSerialPort",
() => {
if (serialMonitor) {
telemetryAI.runWithLatencyMeasure(() => {
serialMonitor.selectSerialPort(null, null);
}, TelemetryEventName.CPX_COMMAND_SERIAL_MONITOR_CHOOSE_PORT);
}, TelemetryEventName.COMMAND_SERIAL_MONITOR_CHOOSE_PORT);
} else {
vscode.window.showErrorMessage(
CONSTANTS.ERROR.NO_FOLDER_OPENED
Expand All @@ -876,13 +876,13 @@ export async function activate(context: vscode.ExtensionContext) {
}
);

const cpxOpenSerialMonitor: vscode.Disposable = vscode.commands.registerCommand(
"deviceSimulatorExpress.cpx.openSerialMonitor",
const openSerialMonitor: vscode.Disposable = vscode.commands.registerCommand(
"deviceSimulatorExpress.common.openSerialMonitor",
() => {
if (serialMonitor) {
telemetryAI.runWithLatencyMeasure(
serialMonitor.openSerialMonitor.bind(serialMonitor),
TelemetryEventName.CPX_COMMAND_SERIAL_MONITOR_OPEN
TelemetryEventName.COMMAND_SERIAL_MONITOR_OPEN
);
} else {
vscode.window.showErrorMessage(
Expand All @@ -893,13 +893,13 @@ export async function activate(context: vscode.ExtensionContext) {
}
);

const cpxChangeBaudRate: vscode.Disposable = vscode.commands.registerCommand(
"deviceSimulatorExpress.cpx.changeBaudRate",
const changeBaudRate: vscode.Disposable = vscode.commands.registerCommand(
"deviceSimulatorExpress.common.changeBaudRate",
() => {
if (serialMonitor) {
telemetryAI.runWithLatencyMeasure(
serialMonitor.changeBaudRate.bind(serialMonitor),
TelemetryEventName.CPX_COMMAND_SERIAL_MONITOR_BAUD_RATE
TelemetryEventName.COMMAND_SERIAL_MONITOR_BAUD_RATE
);
} else {
vscode.window.showErrorMessage(
Expand All @@ -910,13 +910,13 @@ export async function activate(context: vscode.ExtensionContext) {
}
);

const cpxCloseSerialMonitor: vscode.Disposable = vscode.commands.registerCommand(
"deviceSimulatorExpress.cpx.closeSerialMonitor",
const closeSerialMonitor: vscode.Disposable = vscode.commands.registerCommand(
"deviceSimulatorExpress.common.closeSerialMonitor",
(port, showWarning = true) => {
if (serialMonitor) {
telemetryAI.runWithLatencyMeasure(() => {
serialMonitor.closeSerialMonitor(port, showWarning);
}, TelemetryEventName.CPX_COMMAND_SERIAL_MONITOR_CLOSE);
}, TelemetryEventName.COMMAND_SERIAL_MONITOR_CLOSE);
} else {
vscode.window.showErrorMessage(
CONSTANTS.ERROR.NO_FOLDER_OPENED
Expand Down Expand Up @@ -1036,13 +1036,13 @@ export async function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
installDependencies,
runSimulator,
cpxChangeBaudRate,
cpxCloseSerialMonitor,
changeBaudRate,
closeSerialMonitor,
cpxDeployToDevice,
cpxNewFile,
cpxOpenSerialMonitor,
openSerialMonitor,
cpxOpenSimulator,
cpxSelectSerialPort,
selectSerialPort,
microbitOpenSimulator,
microbitNewFile,
microbitDeployToDevice,
Expand Down
10 changes: 5 additions & 5 deletions src/serialMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class SerialMonitor implements vscode.Disposable {
STATUS_BAR_PRIORITY.PORT
);
this._portsStatusBar.command =
"deviceSimulatorExpress.cpx.selectSerialPort";
"deviceSimulatorExpress.common.selectSerialPort";
this._portsStatusBar.tooltip = "Select Serial Port";
this._portsStatusBar.show();

Expand All @@ -86,7 +86,7 @@ export class SerialMonitor implements vscode.Disposable {
STATUS_BAR_PRIORITY.OPEN_PORT
);
this._openPortStatusBar.command =
"deviceSimulatorExpress.cpx.openSerialMonitor";
"deviceSimulatorExpress.common.openSerialMonitor";
this._openPortStatusBar.text = `$(plug)`;
this._openPortStatusBar.tooltip = "Open Serial Monitor";
this._openPortStatusBar.show();
Expand All @@ -96,7 +96,7 @@ export class SerialMonitor implements vscode.Disposable {
STATUS_BAR_PRIORITY.BAUD_RATE
);
this._baudRateStatusBar.command =
"deviceSimulatorExpress.cpx.changeBaudRate";
"deviceSimulatorExpress.common.changeBaudRate";
this._baudRateStatusBar.tooltip = "Baud Rate";
this._baudRateStatusBar.text = defaultBaudRate.toString();
this.updatePortListStatus(null);
Expand Down Expand Up @@ -281,13 +281,13 @@ export class SerialMonitor implements vscode.Disposable {
private updatePortStatus(isOpened: boolean) {
if (isOpened) {
this._openPortStatusBar.command =
"deviceSimulatorExpress.cpx.closeSerialMonitor";
"deviceSimulatorExpress.common.closeSerialMonitor";
this._openPortStatusBar.text = `$(x)`;
this._openPortStatusBar.tooltip = "Close Serial Monitor";
this._baudRateStatusBar.show();
} else {
this._openPortStatusBar.command =
"deviceSimulatorExpress.cpx.openSerialMonitor";
"deviceSimulatorExpress.common.openSerialMonitor";
this._openPortStatusBar.text = `$(plug)`;
this._openPortStatusBar.tooltip = "Open Serial Monitor";
this._baudRateStatusBar.hide();
Expand Down