This commit is contained in:
Eugene Pankov 2022-02-07 17:54:44 +01:00
parent 50f01b6794
commit 6e9f497d22
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4
2 changed files with 12 additions and 12 deletions

View File

@ -41,7 +41,7 @@ class SlowFeedMiddleware extends SessionMiddleware {
}
export class SerialSession extends BaseSession {
serial: SerialPort
serial: SerialPort|null
get serviceMessage$ (): Observable<string> { return this.serviceMessage }
private serviceMessage = new Subject<string>()
@ -72,7 +72,7 @@ export class SerialSession extends BaseSession {
this.profile.options.port = (await this.serialService.listPorts())[0].name
}
this.serial = new SerialPort({
const serial = this.serial = new SerialPort({
path: this.profile.options.port,
autoOpen: false,
baudRate: parseInt(this.profile.options.baudrate as any),
@ -86,27 +86,27 @@ export class SerialSession extends BaseSession {
})
let connected = false
await new Promise(async (resolve, reject) => {
this.serial.on('open', () => {
serial.on('open', () => {
connected = true
this.zone.run(resolve)
})
this.serial.on('error', error => {
serial.on('error', error => {
this.zone.run(() => {
if (connected) {
this.notifications.error(error.toString())
this.notifications.error(error.message)
} else {
reject(error)
}
this.destroy()
})
})
this.serial.on('close', () => {
serial.on('close', () => {
this.emitServiceMessage('Port closed')
this.destroy()
})
try {
this.serial.open()
serial.open()
} catch (e) {
this.notifications.error(e.message)
reject(e)
@ -116,11 +116,11 @@ export class SerialSession extends BaseSession {
this.open = true
setTimeout(() => this.streamProcessor.start())
this.serial.on('readable', () => {
this.emitOutput(this.serial.read())
serial.on('readable', () => {
this.emitOutput(serial.read())
})
this.serial.on('end', () => {
serial.on('end', () => {
this.logger.info('Shell session ended')
if (this.open) {
this.destroy()
@ -145,7 +145,7 @@ export class SerialSession extends BaseSession {
}
kill (_?: string): void {
this.serial.close()
this.serial?.close()
}
emitServiceMessage (msg: string): void {

View File

@ -13,7 +13,7 @@ export class SerialService {
async listPorts (): Promise<SerialPortInfo[]> {
return (await SerialPort.list()).map(x => ({
name: x.path,
description: x.manufacturer || x.serialNumber ? `${x.manufacturer || ''} ${x.serialNumber || ''}` : undefined,
description: `${x.manufacturer ?? ''} ${x.serialNumber ?? ''}`.trim() || undefined,
}))
}