mirror of
https://github.com/Eugeny/tabby.git
synced 2025-10-05 06:24:56 +00:00
fixed serial opening ports
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import stripAnsi from 'strip-ansi'
|
||||
import { SerialPort } from 'serialport'
|
||||
import { SerialPortStream } from '@serialport/stream'
|
||||
import { LogService, NotificationsService, Profile } from 'tabby-core'
|
||||
import { Subject, Observable } from 'rxjs'
|
||||
import { Injector, NgZone } from '@angular/core'
|
||||
@@ -41,7 +41,7 @@ class SlowFeedMiddleware extends SessionMiddleware {
|
||||
}
|
||||
|
||||
export class SerialSession extends BaseSession {
|
||||
serial: SerialPort|null
|
||||
serial: SerialPortStream|null
|
||||
|
||||
get serviceMessage$ (): Observable<string> { return this.serviceMessage }
|
||||
private serviceMessage = new Subject<string>()
|
||||
@@ -72,7 +72,8 @@ export class SerialSession extends BaseSession {
|
||||
this.profile.options.port = (await this.serialService.listPorts())[0].name
|
||||
}
|
||||
|
||||
const serial = this.serial = new SerialPort({
|
||||
const serial = this.serial = new SerialPortStream({
|
||||
binding: this.serialService.detectBinding(),
|
||||
path: this.profile.options.port,
|
||||
autoOpen: false,
|
||||
baudRate: parseInt(this.profile.options.baudrate as any),
|
||||
|
@@ -1,6 +1,4 @@
|
||||
import slugify from 'slugify'
|
||||
import { SerialPort } from 'serialport'
|
||||
import WSABinding from 'serialport-binding-webserialapi'
|
||||
import deepClone from 'clone-deep'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { ProfileProvider, NewTabParameters, SelectorService, HostAppService, Platform, TranslateService } from 'tabby-core'
|
||||
@@ -41,9 +39,6 @@ export class SerialProfilesService extends ProfileProvider<SerialProfile> {
|
||||
private translate: TranslateService,
|
||||
) {
|
||||
super()
|
||||
if (hostApp.platform === Platform.Web) {
|
||||
SerialPort['Binding'] = WSABinding
|
||||
}
|
||||
}
|
||||
|
||||
async getBuiltinProfiles (): Promise<SerialProfile[]> {
|
||||
|
@@ -1,6 +1,8 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { SerialPort } from 'serialport'
|
||||
import { PartialProfile, ProfilesService } from 'tabby-core'
|
||||
import WSABinding from 'serialport-binding-webserialapi'
|
||||
import AbstractBinding from '@serialport/binding-abstract'
|
||||
import { autoDetect } from '@serialport/bindings-cpp'
|
||||
import { HostAppService, PartialProfile, Platform, ProfilesService } from 'tabby-core'
|
||||
import { SerialPortInfo, SerialProfile } from '../api'
|
||||
import { SerialTabComponent } from '../components/serialTab.component'
|
||||
|
||||
@@ -8,13 +10,23 @@ import { SerialTabComponent } from '../components/serialTab.component'
|
||||
export class SerialService {
|
||||
private constructor (
|
||||
private profilesService: ProfilesService,
|
||||
private hostApp: HostAppService,
|
||||
) { }
|
||||
|
||||
detectBinding (): typeof AbstractBinding {
|
||||
return this.hostApp.platform === Platform.Web ? WSABinding : autoDetect()
|
||||
}
|
||||
|
||||
async listPorts (): Promise<SerialPortInfo[]> {
|
||||
return (await SerialPort.list()).map(x => ({
|
||||
name: x.path,
|
||||
description: `${x.manufacturer ?? ''} ${x.serialNumber ?? ''}`.trim() || undefined,
|
||||
}))
|
||||
try {
|
||||
return (await this.detectBinding().list()).map(x => ({
|
||||
name: x.path,
|
||||
description: `${x.manufacturer ?? ''} ${x.serialNumber ?? ''}`.trim() || undefined,
|
||||
}))
|
||||
} catch (err) {
|
||||
console.error('Failed to list serial ports', err)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
quickConnect (query: string): Promise<SerialTabComponent|null> {
|
||||
|
Reference in New Issue
Block a user