mirror of
https://github.com/Eugeny/tabby.git
synced 2025-07-19 18:07:58 +00:00
fixed serial opening ports
This commit is contained in:
@@ -18,8 +18,7 @@
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "14.14.14",
|
||||
"ansi-colors": "^4.1.1",
|
||||
"serialport-binding-webserialapi": "^1.0.3"
|
||||
"ansi-colors": "^4.1.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@angular/animations": "^9.1.9",
|
||||
|
@@ -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> {
|
||||
|
@@ -2,20 +2,6 @@
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@serialport/binding-abstract@^9.0.2":
|
||||
version "9.0.7"
|
||||
resolved "https://registry.yarnpkg.com/@serialport/binding-abstract/-/binding-abstract-9.0.7.tgz#d2c7ecea0f100bdf20187bfc0d34ba90f5504e1e"
|
||||
integrity sha512-g1ncCMIG9rMsxo/28ObYmXZcHThlvtZygsCANmyMUuFS7SwXY4+PhcEnt2+ZcMkEDNRiOklT+ngtIVx5GGpt/A==
|
||||
dependencies:
|
||||
debug "^4.3.1"
|
||||
|
||||
"@serialport/stream@^9.0.2":
|
||||
version "9.0.7"
|
||||
resolved "https://registry.yarnpkg.com/@serialport/stream/-/stream-9.0.7.tgz#0bf023eb0233a714fcc5a86de09e381e466d9882"
|
||||
integrity sha512-c/h7HPAeFiryD9iTGlaSvPqHFHSZ0NMQHxC4rcmKS2Vu3qJuEtkBdTLABwsMp7iWEiSnI4KC3s7bHapaXP06FQ==
|
||||
dependencies:
|
||||
debug "^4.3.1"
|
||||
|
||||
"@types/node@14.14.14":
|
||||
version "14.14.14"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.14.tgz#f7fd5f3cc8521301119f63910f0fb965c7d761ae"
|
||||
@@ -25,23 +11,3 @@ ansi-colors@^4.1.1:
|
||||
version "4.1.1"
|
||||
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348"
|
||||
integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==
|
||||
|
||||
debug@^4.3.1:
|
||||
version "4.3.2"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.2.tgz#f0a49c18ac8779e31d4a0c6029dfb76873c7428b"
|
||||
integrity sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==
|
||||
dependencies:
|
||||
ms "2.1.2"
|
||||
|
||||
ms@2.1.2:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
|
||||
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
|
||||
|
||||
serialport-binding-webserialapi@^1.0.3:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/serialport-binding-webserialapi/-/serialport-binding-webserialapi-1.0.3.tgz#cf4348c075da2de8f6cf9936c0b95645f3ae657b"
|
||||
integrity sha512-TS7dsvetVoTeiWlzpsT/akjtljiYPO56FoJWSFyJSoO/E8icYJ2neQ7CW5NW/sHZDnMqAxULyAny47UFhWz9oQ==
|
||||
dependencies:
|
||||
"@serialport/binding-abstract" "^9.0.2"
|
||||
"@serialport/stream" "^9.0.2"
|
||||
|
Reference in New Issue
Block a user