Skip to content

Commit 7538995

Browse files
authored
fix: improve repl (#2425)
- show all the globals - show baudRate
1 parent fa10fce commit 7538995

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

‎packages/repl/lib/index.ts‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import { promirepl } from 'promirepl'
44
import repl from 'repl'
55
import { SerialPort, SerialPortMock } from 'serialport'
66

7-
const baudRate = Number(process.env.BAUDRATE) || 9600
8-
97
// outputs the path to an arduino or nothing
108
async function findArduino() {
11-
const envPort = process.argv[2] || process.env.TEST_PORT
12-
if (envPort) {
13-
return envPort
9+
const path = process.argv[2] || process.env.TEST_PORT
10+
const baudRate = Number(process.argv[3] || process.env.BAUDRATE) || 9600
11+
if (path && baudRate) {
12+
return { path, baudRate }
1413
}
14+
1515
const ports = await SerialPort.list()
1616
for (const port of ports) {
1717
if (/arduino/i.test(port.manufacturer || '')) {
18-
return port.path
18+
return { path: port.path, baudRate }
1919
}
2020
}
2121
throw new Error(
@@ -24,16 +24,16 @@ async function findArduino() {
2424
}
2525

2626
findArduino()
27-
.then(portName => {
27+
.then(({ path, baudRate }: { path: string; baudRate: number }) => {
2828
console.log(`DEBUG=${process.env.DEBUG || ''} # enable debugging with DEBUG=serialport*`)
29-
console.log(`port = SerialPort({ path: "${portName}", autoOpen: false })`)
30-
console.log('globals { SerialPort, SerialPortMock, portName, port }')
31-
const port = new SerialPort({ path: portName, baudRate, autoOpen: false })
29+
console.log(`port = SerialPort({ path: "${path}", baudRate: ${baudRate}, autoOpen: false })`)
30+
console.log('globals { SerialPort, SerialPortMock, path, port }')
31+
const port = new SerialPort({ path, baudRate, autoOpen: false })
3232
const spRepl = repl.start({ prompt: '> ' })
3333
promirepl(spRepl)
3434
spRepl.context.SerialPort = SerialPort
3535
spRepl.context.SerialPortMock = SerialPortMock
36-
spRepl.context.portName = portName
36+
spRepl.context.path = path
3737
spRepl.context.port = port
3838
})
3939
.catch(e => {

0 commit comments

Comments
 (0)