Repository navigation
Serial communication from the CPX to the extension - #97
Conversation
|
Jonathan Wang (@jonathanwangg) there are conflicts here |
| BOARD: 60, | ||
| ENDING: 70, | ||
| SKETCH: 80, | ||
| PROGRAMMER: 90, |
There was a problem hiding this comment.
PROGRAMMER is not used anywhere. Is there a reason?
There was a problem hiding this comment.
Good catch, they were relevant for the Arduino, but not for us. I've removed this and the other constants.
| BAUD_RATE: 40, | ||
| BOARD: 60, | ||
| ENDING: 70, | ||
| SKETCH: 80, |
There was a problem hiding this comment.
SKETCH is not used anywhere.
| PORT: 20, | ||
| OPEN_PORT: 30, | ||
| BAUD_RATE: 40, | ||
| BOARD: 60, |
| this._currentSerialPort.on("open", () => { | ||
| this._currentSerialPort.write("msft", "Both NL & CR", (err: any) => { | ||
| if (err && !(err.message.indexOf("Writing to COM port (GetOverlappedResult): Unknown error code 121") >= 0)) { | ||
| this._outputChannel.appendLine(`[Error] Failed to open the serial port - ${this._currentPort}`); |
There was a problem hiding this comment.
Should'nt localized constants be used for the error and the info here since it is going in the output channel?
There was a problem hiding this comment.
Converted all of them into constants.
| this._port = cpxConfigJson.port; | ||
| this._onDidChange.fire(); | ||
| } else { | ||
| // Logger.notifyUserError("arduinoFileError", new Error(constants.messages.ARDUINO_FILE_ERROR)); |
There was a problem hiding this comment.
Commented code here. Should we conole.error or something ?
There was a problem hiding this comment.
Yes, thanks for all the forgotten code. Will be changing to console.error.
| return this; | ||
| }, (reason) => { | ||
| // Workaround for change in API. | ||
| // vscode.workspace.findFiles() for some reason now throws an error ehn path does not exist |
There was a problem hiding this comment.
typo in the comment -> ... error WHEN path ...
There was a problem hiding this comment.
Fixed.
| // vscode.window.showErrorMessage(reason.toString()); | ||
| // Logger.notifyUserError("arduinoFileUnhandleError", new Error(reason.toString())); | ||
|
|
||
| // Workaround for change in API, populate required props for arduino.json |
There was a problem hiding this comment.
arduino comments, should update
There was a problem hiding this comment.
Will delete irrelevant comments & code.
| // Workaround for change in API. | ||
| // vscode.workspace.findFiles() for some reason now throws an error ehn path does not exist | ||
| // vscode.window.showErrorMessage(reason.toString()); | ||
| // Logger.notifyUserError("arduinoFileUnhandleError", new Error(reason.toString())); |
There was a problem hiding this comment.
should we replace or get rid of this?
There was a problem hiding this comment.
I'll get rid of it, it's also commented out in their code.
| telemetryAI = new TelemetryAI(context); | ||
| let currentPanel: vscode.WebviewPanel | undefined; | ||
| let outChannel: vscode.OutputChannel | undefined; | ||
| // let outChannel: vscode.OutputChannel | undefined; |
There was a problem hiding this comment.
don't need this do we
There was a problem hiding this comment.
True.
| if (this._currentPort !== this._serialPortControl.currentPort) { | ||
| await this._serialPortControl.changePort(this._currentPort); | ||
| } else if (this._serialPortControl.isActive) { | ||
| vscode.window.showWarningMessage(`Serial Monitor is already opened for ${this._currentPort}`); |
There was a problem hiding this comment.
Constant here maybe?
There was a problem hiding this comment.
Yes, will do.
| this._portsStatusBar.text = "<Select Serial Port>"; | ||
| } | ||
| } | ||
| } No newline at end of file |
| } | ||
|
|
||
| public open(): Promise<any> { | ||
| this._outputChannel.appendLine(`[Starting] Opening the serial port - ${this._currentPort}`); |
There was a problem hiding this comment.
There a reason we don't wanna use the utils method for outputting to the channel here?
There was a problem hiding this comment.
Using appendLine instead of append because the logToOutputChannel function uses append rather than appendLine. I'll also make the string a constant!
| "rootDir": "src", | ||
| "jsx": "react", | ||
| "strict": true /* enable all strict type-checking options */ | ||
| // "strict": true, |
There was a problem hiding this comment.
if we need to change this we can probably just remove it instead of commenting
There was a problem hiding this comment.
Removed.
| const workspaceConfig = vscode.workspace.getConfiguration(); | ||
| const enableUSBDetection = workspaceConfig.get(CONFIG_KEYS.ENABLE_USB_DETECTION); | ||
|
|
||
| if (os.platform() === "linux" || !enableUSBDetection) { |
There was a problem hiding this comment.
we can't detect usbs on linux hey? we should probably list that lack of functionality somewhere
There was a problem hiding this comment.
Yeah, this is something that their library doesn't seem to support yet. We'll have to note this down in a "Known Limitations" section of our README.md.
FMounz
left a comment
There was a problem hiding this comment.
Seems like some changes are needed
| @@ -362,7 +368,7 @@ export async function activate(context: vscode.ExtensionContext) { | |||
| childProcess.stderr.on("data", data => { | |||
There was a problem hiding this comment.
This needs to be prefixed with utils sir - https://github.com/microsoft/vscode-python-embedded/pull/97/files#diff-45327f86d4438556066de133327f4ca2R347
| } | ||
|
|
||
| export const CPX_CONFIG_FILE = path.join(".vscode", "cpx.json"); | ||
| export const SERIAL_MONITOR_NAME = "CPX Serial Monitor"; |
There was a problem hiding this comment.
I would name this Pacifica rather than CPX because the serial monitor is specific to our app not the board
There was a problem hiding this comment.
Also localize it pls
Luke Slevinsky (LukeSlev)
left a comment
There was a problem hiding this comment.
seems to work for me now so after these updates good to go
|
|
||
| public async openSerialMonitor() { | ||
| if (!this._currentPort) { | ||
| const ans = await vscode.window.showInformationMessage("No serial port was selected, please select a serial port first", "Yes", "No"); |
There was a problem hiding this comment.
make yes and no constants pls and localize the message
There was a problem hiding this comment.
Yes
| this.updatePortListStatus(foundPort.comName); | ||
| } | ||
| } else { | ||
| const chosen = await vscode.window.showQuickPick(<vscode.QuickPickItem[]>lists.map((port: ISerialPortDetail): vscode.QuickPickItem => { |
There was a problem hiding this comment.
use as to cast instead of <> pls
| "https://learn.adafruit.com/circuitpython-made-easy-on-circuit-playground-express/circuit-playground-express-library" | ||
| }, | ||
| MISC: { | ||
| NO: localize( |
There was a problem hiding this comment.
maybe move to dialog responses as a message item? that's what we've been doing for our other dialog responses 🤷♂️
There was a problem hiding this comment.
Will do.
|
Jonathan Wang (@jonathanwangg) conflicts |

Description:
### IMPORTANT NOTE: A lot of the changes are probably from the
vendor/node-usb-nativefolder. It is from thevscode-arduinoextension and I have not modified it in any way. We probably don't have to review that portion since I'm treating it as third party library code. You will also need a physical CPX to be able to test this PR.In this PR, we're including a serial monitor to our extension. What this means is that any
printstatements in the user's code will be printed to anOutputChannelunder the Output panel in VS Code. I am mostly reusing code from Microsoft'svscode-arduinoextension (https://github.com/Microsoft/vscode-arduino) and removing code that is specific to the Arduino that we won't need.Aside from the Command Palette commands, we also have StatusBarItems that can be used instead of the Command Palette commands:
Select Serial PortOpen Serial MonitorChange Baud RateThe core files that I have taken code from are:
src/serialmonitor/serialMonitor.tssrc/serialmonitor/serialportctrl.tsOutputChannel.src/serialmonitor/usbDetector.tsnode-usb-nativelibrary to listen for changes and initialize theSerialMonitorsrc/deviceContext.tscpx.jsonwhich is a JSON object that describes the configuration of the CPX using a FileSystemWatcher .src/extension.tsSelect Serial PortOpen Serial MonitorChange Baud RateClose Serial Monitorvendor/node-usb-nativeType of change
Limitations:
vscode-arduinoextension is in Preview mode and since we're relying on their code, there might be some bugs they missed that will also be in our code.vscode-arduinoextensinon)tsconfig.json, I've changedstrict: truetoalwaysStrict: trueinstead. I am not sure if this is recommended or if I should go back to usingstrict: trueand find another way to solve type issues.Testing:
I ran the extension with my CPX plugged in. I use the the "Open Serial Monitor" command to select the serial port and open the serial monitor. I had code on the CPX with print statements. The print statements showed in the serial monitor OutputChannel.
Checklist: