Skip to content

Serialport v10 #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ coverage
package-lock.json
/*.tgz
/tmp*
.history
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [1.13.8](https://github.com/metachris/micropython-ctl/compare/v1.13.4...v1.13.8) (2022-02-10)


### Bug Fixes

* add ctrl+x for exit (ctrl+k taken in vscode) ([5b7bc4b](https://github.com/metachris/micropython-ctl/commit/5b7bc4bcf456b450ae8c89e6f7bde99324a8a090))
* bump + fix for serialport ([179cff7](https://github.com/metachris/micropython-ctl/commit/179cff7ab3e465374b1e81cc8c46d3bb89a238a5))
* serialport bad version ([e8a61a4](https://github.com/metachris/micropython-ctl/commit/e8a61a41b8ca8a1514382836a71b3359449ea98e))

1.13.8-beta1 (dev)
------------------

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## Fork of https://github.com/metachris/micropython-ctl with serialport v10 support

# MicroPython-Ctl: TypeScript ❤️ MicroPython

Talk to MicroPython devices from websites/webapps, Node.js programs, Electron applications, VS Code extensions, the terminal, and more.
Expand Down
8 changes: 4 additions & 4 deletions cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ import crypto from 'crypto';
import { execSync } from 'child_process';
import readline from 'readline'
import { Buffer } from 'buffer/'
import SerialPort from 'serialport';
import { SerialPort } from 'serialport';
import { Command } from 'commander';
import { ScriptExecutionError, MicroPythonDevice, WEBSERVER_PORT, FileListEntry } from '../src/main';
import { delayMillis } from '../src/utils';
import { humanFileSize } from './utils';
import { getTmpFilename, globToRegExp } from '../src/utils-node';
import { mount as mountWithFuse } from './mount-device'
Expand Down Expand Up @@ -663,16 +662,17 @@ const repl = async () => {
readline.emitKeypressEvents(process.stdin);
process.stdin.setRawMode(true);
process.stdin.on('keypress', async (_str, key) => {
// Quit on Ctrl+K
// Quit on Ctrl+K or Ctrl+X
if (key.name === 'k' && key.ctrl) process.exit(0)
if (key.name === 'x' && key.ctrl) process.exit(0)

// Send anything to the device, if connected
if (micropython.isConnected() && micropython.isTerminalMode()) {
micropython.sendData(key.sequence)
}
});

console.log('Exit REPL by pressing Ctrl+K')
console.log('Exit REPL by pressing Ctrl+K or Ctrl+X')
} catch (e) {
console.log('Error:', e)
await micropython.disconnect()
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "micropython-ctl",
"version": "1.13.8-beta1",
"name": "micropython-ctl-cont",
"version": "1.13.8",
"description": "Async TypeScript MicroPython interface (for serial and network connections, REPL & WebREPL)",
"repository": "https://github.com/metachris/micropython-ctl",
"browser": "./dist-browser/main.js",
Expand Down Expand Up @@ -32,12 +32,11 @@
"express": "^4.17.1",
"isomorphic-ws": "^4.0.1",
"node-fetch": "^2.6.1",
"serialport": "^9.0.3",
"serialport": "^10.4.0",
"ws": "^7.4.1"
},
"devDependencies": {
"@types/node": "^14.14.9",
"@types/serialport": "^8.0.1",
"@types/ws": "^7.4.0",
"esbuild": "^0.8.46",
"ts-jest": "^26.4.4",
Expand Down
16 changes: 8 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* - Author: chris@linuxuser.at / https://twitter.com/metachris
*/
import WebSocket from 'isomorphic-ws'
import { Buffer } from 'buffer/'
import { Buffer } from 'buffer'
import { InvalidPassword, CouldNotConnect, ScriptExecutionError } from './errors'
import { debug, debug2, dedent } from './utils';
import * as PythonScripts from './python-scripts';
Expand Down Expand Up @@ -187,11 +187,11 @@ export class MicroPythonDevice {
inputBuffer: '',
errorBuffer: '',
broadcastCommandOutputAsTerminalData: false,
dataRawBuffer: new Buffer(0),
dataRawBuffer: Buffer.alloc(0),

isReadingUntil: false,
readUntilData: new Buffer(0),
readUntilBuffer: new Buffer(0),
readUntilData: Buffer.alloc(0),
readUntilBuffer: Buffer.alloc(0),
readUntilPromise: null,
readUntilPromiseResolve: null,
readUntilPromiseReject: null,
Expand Down Expand Up @@ -290,10 +290,10 @@ export class MicroPythonDevice {
this.clearBuffer()

// Get serialport either through window.SerialPort, or require
const SerialPort = typeof window !== 'undefined' && window.SerialPort ? window.SerialPort : require('serialport')
const SerialPort = typeof window !== 'undefined' && window.SerialPort ? window.SerialPort : require('serialport').SerialPort

// Open the serial port
this.state.port = new SerialPort(path, { baudRate: 115200 })
this.state.port = new SerialPort({ path, baudRate: 115200 })

// error listener
this.state.port.on('error', async (err: string) => {
Expand Down Expand Up @@ -502,7 +502,7 @@ export class MicroPythonDevice {
private clearBuffer() {
this.state.inputBuffer = ''
this.state.errorBuffer = ''
this.state.dataRawBuffer = new Buffer(0)
this.state.dataRawBuffer = Buffer.alloc(0)
}

/**
Expand All @@ -511,7 +511,7 @@ export class MicroPythonDevice {
*/
private async readUntil(data: Buffer | string, timeout = 10) {
this.state.readUntilData = Buffer.isBuffer(data) ? data : Buffer.from(data)
this.state.readUntilBuffer = new Buffer(0)
this.state.readUntilBuffer = Buffer.alloc(0)
this.state.isReadingUntil = true

// Create promise
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Buffer } from 'buffer/'
import { Buffer } from 'buffer'

// export const IS_ELECTRON = typeof (navigator) !== 'undefined' && navigator.userAgent.indexOf('Electron/') > -1

Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MicroPythonDevice } from '../src/main';
import assert from 'assert'
import crypto from 'crypto';
import { Buffer } from 'buffer/'
import SerialPort from 'serialport';
import { SerialPort } from 'serialport';
import { delayMillis } from '../src/utils';
import { Command } from 'commander';

Expand Down
Loading