webserial-core 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Core.d.ts +6 -2
- package/dist/Core.d.ts.map +1 -1
- package/dist/webserial-core.js +100 -86
- package/dist/webserial-core.umd.cjs +2 -2
- package/package.json +4 -4
package/dist/Core.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ interface QueueData {
|
|
|
26
26
|
action: string;
|
|
27
27
|
}
|
|
28
28
|
type SerialData = {
|
|
29
|
+
aux_connecting: string;
|
|
30
|
+
connecting: boolean;
|
|
29
31
|
connected: boolean;
|
|
30
32
|
port: SerialPort | null;
|
|
31
33
|
last_action: string | null;
|
|
@@ -86,6 +88,7 @@ interface ICore {
|
|
|
86
88
|
set serialConfigPort(config_port: SerialOptions);
|
|
87
89
|
get serialConfigPort(): SerialOptions;
|
|
88
90
|
get isConnected(): boolean;
|
|
91
|
+
get isConnecting(): boolean;
|
|
89
92
|
get isDisconnected(): boolean;
|
|
90
93
|
get useRTSCTS(): boolean;
|
|
91
94
|
set useRTSCTS(value: boolean);
|
|
@@ -109,7 +112,7 @@ interface ICore {
|
|
|
109
112
|
set bypassSerialBytesConnection(value: boolean);
|
|
110
113
|
timeout(bytes: string[], event: string): Promise<void>;
|
|
111
114
|
disconnect(detail?: null): Promise<void>;
|
|
112
|
-
connect(): Promise<
|
|
115
|
+
connect(): Promise<boolean>;
|
|
113
116
|
serialDisconnect(): Promise<void>;
|
|
114
117
|
serialPortsSaved(ports: SerialPort[]): Promise<void>;
|
|
115
118
|
serialErrors(error: unknown | Error | DOMException): void;
|
|
@@ -158,6 +161,7 @@ export declare class Core extends Dispatcher implements ICore {
|
|
|
158
161
|
get useRTSCTS(): boolean;
|
|
159
162
|
set useRTSCTS(value: boolean);
|
|
160
163
|
get isConnected(): boolean;
|
|
164
|
+
get isConnecting(): boolean;
|
|
161
165
|
get isDisconnected(): boolean;
|
|
162
166
|
get deviceNumber(): number;
|
|
163
167
|
get uuid(): string;
|
|
@@ -179,7 +183,7 @@ export declare class Core extends Dispatcher implements ICore {
|
|
|
179
183
|
set bypassSerialBytesConnection(value: boolean);
|
|
180
184
|
timeout(bytes: string | Uint8Array | Array<string> | Array<number>, event: string): Promise<void>;
|
|
181
185
|
disconnect(detail?: null): Promise<void>;
|
|
182
|
-
connect(): Promise<
|
|
186
|
+
connect(): Promise<boolean>;
|
|
183
187
|
serialDisconnect(): Promise<void>;
|
|
184
188
|
getResponseAsArrayBuffer(): void;
|
|
185
189
|
getResponseAsArrayHex(): void;
|
package/dist/Core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Core.d.ts","sourceRoot":"","sources":["../lib/Core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAI7C,UAAU,SAAS;IACjB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,MAAM,CAAC;IAC1E,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,KAAK,gBAAgB,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,aAAa,CAAC;AAEnE,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,UAAU,CAAC;IACnB,EAAE,EAAE,gBAAgB,CAAC;IACrB,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,OAAO,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;IAChC,a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WAAW,GAAG,IAAI;IAgBxG,gBAAgB,IAAI,IAAI;IAIxB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM;IAQ7B,QAAQ,IAAI,MAAM;IAUlB,UAAU,IAAI,IAAI;IAKZ,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B,cAAc,CAAC,EAAE,IAAS,EAAE,GAAE,UAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAY7E,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;IAI1C,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,GAAE,MAAa,GAAG,eAAe;IAIxE,wBAAwB,CAAC,MAAM,GAAE,MAAW,EAAE,GAAG,GAAE,MAAa,GAAG,UAAU;IAM7E,kBAAkB,CAAC,MAAM,GAAE,MAAW,EAAE,GAAG,GAAE,MAAa,GAAG,MAAM,EAAE;IAKrE,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE;IAI5C,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU;IAI5C,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU;IAatD,uBAAuB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE,GAAG,MAAM;IAgB7D,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IASxC,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IASvC,2BAA2B,IAAI,OAAO;CAG9C"}
|
package/dist/webserial-core.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Q = Object.defineProperty;
|
|
2
2
|
var T = (l) => {
|
|
3
3
|
throw TypeError(l);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var g = (l, s, e) =>
|
|
5
|
+
var V = (l, s, e) => s in l ? Q(l, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[s] = e;
|
|
6
|
+
var g = (l, s, e) => V(l, typeof s != "symbol" ? s + "" : s, e), z = (l, s, e) => s.has(l) || T("Cannot " + e);
|
|
7
7
|
var E = (l, s, e) => s.has(l) ? T("Cannot add the same private member more than once") : s instanceof WeakSet ? s.add(l) : s.set(l, e);
|
|
8
|
-
var a = (l, s, e) => (
|
|
8
|
+
var a = (l, s, e) => (z(l, s, "access private method"), e);
|
|
9
9
|
class A extends CustomEvent {
|
|
10
10
|
constructor(s, e) {
|
|
11
11
|
super(s, e);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
class
|
|
14
|
+
class B extends EventTarget {
|
|
15
15
|
constructor() {
|
|
16
16
|
super(...arguments);
|
|
17
17
|
g(this, "__listeners__", {
|
|
@@ -45,7 +45,7 @@ class L extends EventTarget {
|
|
|
45
45
|
}));
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
const o = class o extends
|
|
48
|
+
const o = class o extends B {
|
|
49
49
|
constructor() {
|
|
50
50
|
super(), ["change"].forEach((e) => {
|
|
51
51
|
this.serialRegisterAvailableListener(e);
|
|
@@ -88,15 +88,15 @@ const o = class o extends L {
|
|
|
88
88
|
g(o, "instance"), g(o, "devices", {});
|
|
89
89
|
let h = o;
|
|
90
90
|
h.instance || (h.instance = new h());
|
|
91
|
-
function
|
|
91
|
+
function L(l = 100) {
|
|
92
92
|
return new Promise(
|
|
93
93
|
(s) => setTimeout(() => s(), l)
|
|
94
94
|
);
|
|
95
95
|
}
|
|
96
|
-
function
|
|
96
|
+
function G() {
|
|
97
97
|
return "serial" in navigator;
|
|
98
98
|
}
|
|
99
|
-
const
|
|
99
|
+
const x = {
|
|
100
100
|
baudRate: 9600,
|
|
101
101
|
dataBits: 8,
|
|
102
102
|
stopBits: 1,
|
|
@@ -104,17 +104,17 @@ const v = {
|
|
|
104
104
|
bufferSize: 32768,
|
|
105
105
|
flowControl: "none"
|
|
106
106
|
};
|
|
107
|
-
var n, y,
|
|
108
|
-
class
|
|
107
|
+
var n, y, w, U, v, k, p, I, P, $, D, R, M, m, q, N, O, F, H, j, W;
|
|
108
|
+
class K extends B {
|
|
109
109
|
constructor({
|
|
110
110
|
filters: e = null,
|
|
111
|
-
config_port: t =
|
|
111
|
+
config_port: t = x,
|
|
112
112
|
no_device: i = 1,
|
|
113
113
|
device_listen_on_channel: r = 1,
|
|
114
|
-
bypassSerialBytesConnection:
|
|
114
|
+
bypassSerialBytesConnection: _ = !1
|
|
115
115
|
} = {
|
|
116
116
|
filters: null,
|
|
117
|
-
config_port:
|
|
117
|
+
config_port: x,
|
|
118
118
|
no_device: 1,
|
|
119
119
|
device_listen_on_channel: 1,
|
|
120
120
|
bypassSerialBytesConnection: !1
|
|
@@ -133,6 +133,8 @@ class G extends L {
|
|
|
133
133
|
no_code: 0
|
|
134
134
|
},
|
|
135
135
|
serial: {
|
|
136
|
+
aux_connecting: "idle",
|
|
137
|
+
connecting: !1,
|
|
136
138
|
connected: !1,
|
|
137
139
|
port: null,
|
|
138
140
|
last_action: null,
|
|
@@ -156,7 +158,7 @@ class G extends L {
|
|
|
156
158
|
delay_first_connection: 200,
|
|
157
159
|
bytes_connection: null,
|
|
158
160
|
filters: [],
|
|
159
|
-
config_port:
|
|
161
|
+
config_port: x,
|
|
160
162
|
queue: [],
|
|
161
163
|
auto_response: ["DD", "DD"],
|
|
162
164
|
free_timeout_ms: 50,
|
|
@@ -182,7 +184,7 @@ class G extends L {
|
|
|
182
184
|
});
|
|
183
185
|
if (!("serial" in navigator))
|
|
184
186
|
throw new Error("Web Serial not supported");
|
|
185
|
-
e && (this.serialFilters = e), t && (this.serialConfigPort = t),
|
|
187
|
+
e && (this.serialFilters = e), t && (this.serialConfigPort = t), _ && (this.__internal__.bypassSerialBytesConnection = _), i && a(this, n, j).call(this, i), r && ["number", "string"].includes(typeof r) && (this.listenOnChannel = r), a(this, n, N).call(this), a(this, n, O).call(this);
|
|
186
188
|
}
|
|
187
189
|
set listenOnChannel(e) {
|
|
188
190
|
if (typeof e == "string" && (e = parseInt(e)), isNaN(e) || e < 1 || e > 255)
|
|
@@ -217,11 +219,14 @@ class G extends L {
|
|
|
217
219
|
}
|
|
218
220
|
get isConnected() {
|
|
219
221
|
const e = this.__internal__.serial.connected, t = a(this, n, y).call(this, this.__internal__.serial.port);
|
|
220
|
-
return e && !t && a(this, n,
|
|
222
|
+
return e && !t && a(this, n, w).call(this, { error: "Port is closed, not readable or writable." }), this.__internal__.serial.connected = t, this.__internal__.serial.connected;
|
|
223
|
+
}
|
|
224
|
+
get isConnecting() {
|
|
225
|
+
return this.__internal__.serial.connecting;
|
|
221
226
|
}
|
|
222
227
|
get isDisconnected() {
|
|
223
228
|
const e = this.__internal__.serial.connected, t = a(this, n, y).call(this, this.__internal__.serial.port);
|
|
224
|
-
return !e && t && (this.dispatch("serial:connected"), h.$dispatchChange(this)), this.__internal__.serial.connected = t, !this.__internal__.serial.connected;
|
|
229
|
+
return !e && t && (this.dispatch("serial:connected"), a(this, n, m).call(this, !1), h.$dispatchChange(this)), this.__internal__.serial.connected = t, !this.__internal__.serial.connected;
|
|
225
230
|
}
|
|
226
231
|
get deviceNumber() {
|
|
227
232
|
return this.__internal__.device_number;
|
|
@@ -299,14 +304,18 @@ class G extends L {
|
|
|
299
304
|
});
|
|
300
305
|
}
|
|
301
306
|
async disconnect(e = null) {
|
|
302
|
-
await this.serialDisconnect(), a(this, n,
|
|
307
|
+
await this.serialDisconnect(), a(this, n, w).call(this, e);
|
|
303
308
|
}
|
|
304
309
|
async connect() {
|
|
305
|
-
return this.isConnected ?
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
+
return this.isConnected ? !0 : (this.__internal__.serial.aux_connecting = "idle", new Promise((e, t) => {
|
|
311
|
+
G() || t("Web Serial not supported");
|
|
312
|
+
const i = a(this, n, U).bind(this);
|
|
313
|
+
this.on("serial:connecting", i);
|
|
314
|
+
const r = setInterval(() => {
|
|
315
|
+
this.__internal__.serial.aux_connecting === "finished" ? (clearInterval(r), this.__internal__.serial.aux_connecting = "idle", this.off("serial:connecting", i), this.isConnected ? e(!0) : t(`${this.typeDevice} device ${this.deviceNumber} not connected`)) : this.__internal__.serial.aux_connecting === "connecting" && (this.__internal__.serial.aux_connecting = "idle", this.dispatch("serial:connecting", { active: !0 }));
|
|
316
|
+
}, 100);
|
|
317
|
+
this.serialConnect();
|
|
318
|
+
}));
|
|
310
319
|
}
|
|
311
320
|
async serialDisconnect() {
|
|
312
321
|
try {
|
|
@@ -391,8 +400,8 @@ class G extends L {
|
|
|
391
400
|
}
|
|
392
401
|
async serialConnect() {
|
|
393
402
|
try {
|
|
394
|
-
this.
|
|
395
|
-
const e = await a(this, n,
|
|
403
|
+
a(this, n, m).call(this, !0);
|
|
404
|
+
const e = await a(this, n, I).call(this);
|
|
396
405
|
if (e.length > 0)
|
|
397
406
|
await this.serialPortsSaved(e);
|
|
398
407
|
else {
|
|
@@ -407,21 +416,22 @@ class G extends L {
|
|
|
407
416
|
await t.open(this.serialConfigPort);
|
|
408
417
|
const i = this;
|
|
409
418
|
t.onconnect = (r) => {
|
|
410
|
-
|
|
419
|
+
var _;
|
|
420
|
+
i.dispatch("serial:connected", r), a(_ = i, n, m).call(_, !1), h.$dispatchChange(this), i.__internal__.serial.queue.length > 0 && i.dispatch("internal:queue", {});
|
|
411
421
|
}, t.ondisconnect = async () => {
|
|
412
422
|
await i.disconnect();
|
|
413
|
-
}, await
|
|
423
|
+
}, await L(this.__internal__.serial.delay_first_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
|
|
414
424
|
await i.timeout(i.__internal__.serial.bytes_connection ?? [], "connection:start");
|
|
415
|
-
}, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await a(this, n,
|
|
425
|
+
}, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await a(this, n, v).call(this, this.__internal__.serial.bytes_connection ?? []), this.dispatch("serial:sent", {
|
|
416
426
|
action: "connect",
|
|
417
427
|
bytes: this.__internal__.serial.bytes_connection
|
|
418
|
-
}), this.__internal__.auto_response && a(this, n, p).call(this, this.__internal__.serial.auto_response), await a(this, n,
|
|
428
|
+
}), this.__internal__.auto_response && a(this, n, p).call(this, this.__internal__.serial.auto_response), await a(this, n, M).call(this);
|
|
419
429
|
} catch (e) {
|
|
420
|
-
this.serialErrors(e);
|
|
430
|
+
a(this, n, m).call(this, !1), this.serialErrors(e);
|
|
421
431
|
}
|
|
422
432
|
}
|
|
423
433
|
async serialForget() {
|
|
424
|
-
return await a(this, n,
|
|
434
|
+
return await a(this, n, q).call(this);
|
|
425
435
|
}
|
|
426
436
|
decToHex(e) {
|
|
427
437
|
return typeof e == "string" && (e = parseInt(e, 10)), e.toString(16);
|
|
@@ -466,7 +476,7 @@ class G extends L {
|
|
|
466
476
|
}
|
|
467
477
|
serialSetConnectionConstant(e = 1) {
|
|
468
478
|
if (this.__internal__.bypassSerialBytesConnection) return this.__internal__.serial.bytes_connection;
|
|
469
|
-
throw
|
|
479
|
+
throw new Error(`Method not implemented 'serialSetConnectionConstant' to listen on channel ${e}`);
|
|
470
480
|
}
|
|
471
481
|
serialMessage(e) {
|
|
472
482
|
throw console.log(e), this.dispatch("serial:message", { code: e }), new Error("Method not implemented 'serialMessage'");
|
|
@@ -493,7 +503,7 @@ class G extends L {
|
|
|
493
503
|
});
|
|
494
504
|
}
|
|
495
505
|
softReload() {
|
|
496
|
-
a(this, n,
|
|
506
|
+
a(this, n, W).call(this), this.dispatch("serial:soft-reload", {});
|
|
497
507
|
}
|
|
498
508
|
async sendConnect() {
|
|
499
509
|
if (!this.__internal__.serial.bytes_connection)
|
|
@@ -551,8 +561,8 @@ class G extends L {
|
|
|
551
561
|
asciiToHex(e) {
|
|
552
562
|
const t = [];
|
|
553
563
|
for (let i = 0, r = e.length; i < r; i++) {
|
|
554
|
-
const
|
|
555
|
-
t.push(
|
|
564
|
+
const _ = Number(e.charCodeAt(i)).toString(16);
|
|
565
|
+
t.push(_);
|
|
556
566
|
}
|
|
557
567
|
return t.join("");
|
|
558
568
|
}
|
|
@@ -562,38 +572,40 @@ class G extends L {
|
|
|
562
572
|
}
|
|
563
573
|
n = new WeakSet(), y = function(e) {
|
|
564
574
|
return !!(e && e.readable && e.writable);
|
|
565
|
-
},
|
|
575
|
+
}, w = function(e = null) {
|
|
566
576
|
this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector = 0, this.dispatch("serial:disconnected", e), h.$dispatchChange(this);
|
|
567
|
-
},
|
|
577
|
+
}, U = function(e) {
|
|
578
|
+
this.__internal__.serial.aux_connecting = e.detail.active ? "connecting" : "finished";
|
|
579
|
+
}, v = async function(e) {
|
|
568
580
|
const t = this.__internal__.serial.port;
|
|
569
581
|
if (!t || t && (!t.readable || !t.writable))
|
|
570
|
-
throw a(this, n,
|
|
582
|
+
throw a(this, n, w).call(this, { error: "Port is closed, not readable or writable." }), new Error("The port is closed or is not readable/writable");
|
|
571
583
|
const i = this.validateBytes(e);
|
|
572
|
-
if (this.useRTSCTS && await a(this, n,
|
|
584
|
+
if (this.useRTSCTS && await a(this, n, k).call(this, t, 5e3), t.writable === null) return;
|
|
573
585
|
const r = t.writable.getWriter();
|
|
574
586
|
await r.write(i), r.releaseLock();
|
|
575
|
-
},
|
|
587
|
+
}, k = async function(e, t = 5e3) {
|
|
576
588
|
const i = Date.now();
|
|
577
589
|
for (; ; ) {
|
|
578
590
|
if (Date.now() - i > t)
|
|
579
591
|
throw new Error("Timeout waiting for clearToSend signal");
|
|
580
592
|
const { clearToSend: r } = await e.getSignals();
|
|
581
593
|
if (r) return;
|
|
582
|
-
await
|
|
594
|
+
await L(100);
|
|
583
595
|
}
|
|
584
596
|
}, p = function(e = new Uint8Array([]), t = !1) {
|
|
585
597
|
if (e && e.length > 0) {
|
|
586
598
|
const i = this.__internal__.serial.connected;
|
|
587
|
-
if (this.__internal__.serial.connected = a(this, n, y).call(this, this.__internal__.serial.port), h.$dispatchChange(this), !i && this.__internal__.serial.connected && this.dispatch("serial:connected"), this.__internal__.interval.reconnection && (clearInterval(this.__internal__.interval.reconnection), this.__internal__.interval.reconnection = 0), this.__internal__.timeout.until_response && (clearTimeout(this.__internal__.timeout.until_response), this.__internal__.timeout.until_response = 0), this.__internal__.serial.response.as === "hex")
|
|
599
|
+
if (this.__internal__.serial.connected = a(this, n, y).call(this, this.__internal__.serial.port), h.$dispatchChange(this), !i && this.__internal__.serial.connected && (this.dispatch("serial:connected"), a(this, n, m).call(this, !1)), this.__internal__.interval.reconnection && (clearInterval(this.__internal__.interval.reconnection), this.__internal__.interval.reconnection = 0), this.__internal__.timeout.until_response && (clearTimeout(this.__internal__.timeout.until_response), this.__internal__.timeout.until_response = 0), this.__internal__.serial.response.as === "hex")
|
|
588
600
|
t ? this.serialCorruptMessage(this.parseUint8ToHex(e)) : this.serialMessage(this.parseUint8ToHex(e));
|
|
589
601
|
else if (this.__internal__.serial.response.as === "uint8")
|
|
590
602
|
t ? this.serialCorruptMessage(e) : this.serialMessage(e);
|
|
591
603
|
else if (this.__internal__.serial.response.as === "string") {
|
|
592
604
|
const r = this.parseUint8ArrayToString(e);
|
|
593
605
|
if (this.__internal__.serial.response.limiter !== null) {
|
|
594
|
-
const
|
|
595
|
-
for (const
|
|
596
|
-
c
|
|
606
|
+
const _ = r.split(this.__internal__.serial.response.limiter);
|
|
607
|
+
for (const c in _)
|
|
608
|
+
_[c] && (t ? this.serialCorruptMessage(_[c]) : this.serialMessage(_[c]));
|
|
597
609
|
} else
|
|
598
610
|
t ? this.serialCorruptMessage(r) : this.serialMessage(r);
|
|
599
611
|
} else {
|
|
@@ -602,18 +614,18 @@ n = new WeakSet(), y = function(e) {
|
|
|
602
614
|
}
|
|
603
615
|
}
|
|
604
616
|
this.__internal__.serial.queue.length !== 0 && this.dispatch("internal:queue", {});
|
|
605
|
-
},
|
|
617
|
+
}, I = async function() {
|
|
606
618
|
const e = this.serialFilters, t = await navigator.serial.getPorts({ filters: e });
|
|
607
619
|
return e.length === 0 ? t : t.filter((r) => {
|
|
608
|
-
const
|
|
609
|
-
return e.some((
|
|
620
|
+
const _ = r.getInfo();
|
|
621
|
+
return e.some((c) => _.usbProductId === c.usbProductId && _.usbVendorId === c.usbVendorId);
|
|
610
622
|
}).filter((r) => !a(this, n, y).call(this, r));
|
|
611
|
-
},
|
|
623
|
+
}, P = function(e) {
|
|
612
624
|
if (e) {
|
|
613
625
|
const t = this.__internal__.serial.response.buffer, i = new Uint8Array(t.length + e.byteLength);
|
|
614
626
|
i.set(t, 0), i.set(new Uint8Array(e), t.length), this.__internal__.serial.response.buffer = i;
|
|
615
627
|
}
|
|
616
|
-
},
|
|
628
|
+
}, $ = async function() {
|
|
617
629
|
this.__internal__.serial.time_until_send_bytes && (clearTimeout(this.__internal__.serial.time_until_send_bytes), this.__internal__.serial.time_until_send_bytes = 0), this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
618
630
|
this.__internal__.serial.response.buffer && a(this, n, p).call(this, this.__internal__.serial.response.buffer), this.__internal__.serial.response.buffer = new Uint8Array(0);
|
|
619
631
|
}, this.__internal__.serial.free_timeout_ms || 50);
|
|
@@ -629,7 +641,7 @@ n = new WeakSet(), y = function(e) {
|
|
|
629
641
|
a(this, n, p).call(this, this.__internal__.serial.response.buffer, !0);
|
|
630
642
|
}, this.__internal__.serial.free_timeout_ms || 50));
|
|
631
643
|
}
|
|
632
|
-
},
|
|
644
|
+
}, R = async function() {
|
|
633
645
|
const {
|
|
634
646
|
limiter: e,
|
|
635
647
|
prefixLimiter: t = !1,
|
|
@@ -640,8 +652,8 @@ n = new WeakSet(), y = function(e) {
|
|
|
640
652
|
const r = this.__internal__.serial.response.buffer;
|
|
641
653
|
if (!e || !r || r.length === 0) return;
|
|
642
654
|
this.__internal__.serial.time_until_send_bytes && (clearTimeout(this.__internal__.serial.time_until_send_bytes), this.__internal__.serial.time_until_send_bytes = 0);
|
|
643
|
-
let
|
|
644
|
-
const
|
|
655
|
+
let c = new TextDecoder().decode(r);
|
|
656
|
+
const b = [];
|
|
645
657
|
if (typeof e == "string") {
|
|
646
658
|
let u;
|
|
647
659
|
if (t && i)
|
|
@@ -653,36 +665,36 @@ n = new WeakSet(), y = function(e) {
|
|
|
653
665
|
else
|
|
654
666
|
return;
|
|
655
667
|
let f, d = 0;
|
|
656
|
-
for (; (f = u.exec(
|
|
657
|
-
|
|
658
|
-
|
|
668
|
+
for (; (f = u.exec(c)) !== null; )
|
|
669
|
+
b.push(new TextEncoder().encode(f[1])), d = u.lastIndex;
|
|
670
|
+
c = c.slice(d);
|
|
659
671
|
} else if (e instanceof RegExp) {
|
|
660
672
|
let u, f = 0;
|
|
661
673
|
if (t && i) {
|
|
662
674
|
const d = new RegExp(`${e.source}(.*?)${e.source}`, "g");
|
|
663
|
-
for (; (u = d.exec(
|
|
664
|
-
|
|
675
|
+
for (; (u = d.exec(c)) !== null; )
|
|
676
|
+
b.push(new TextEncoder().encode(u[1])), f = d.lastIndex;
|
|
665
677
|
} else if (i)
|
|
666
|
-
for (; (u = e.exec(
|
|
667
|
-
const d = u.index,
|
|
668
|
-
|
|
678
|
+
for (; (u = e.exec(c)) !== null; ) {
|
|
679
|
+
const d = u.index, C = c.slice(f, d);
|
|
680
|
+
b.push(new TextEncoder().encode(C)), f = e.lastIndex;
|
|
669
681
|
}
|
|
670
682
|
else if (t) {
|
|
671
|
-
const d =
|
|
683
|
+
const d = c.split(e);
|
|
672
684
|
d.shift();
|
|
673
|
-
for (const
|
|
674
|
-
|
|
675
|
-
|
|
685
|
+
for (const C of d)
|
|
686
|
+
b.push(new TextEncoder().encode(C));
|
|
687
|
+
c = "";
|
|
676
688
|
}
|
|
677
|
-
|
|
689
|
+
c = c.slice(f);
|
|
678
690
|
}
|
|
679
|
-
for (const u of
|
|
691
|
+
for (const u of b)
|
|
680
692
|
a(this, n, p).call(this, u);
|
|
681
|
-
const S = new TextEncoder().encode(
|
|
693
|
+
const S = new TextEncoder().encode(c);
|
|
682
694
|
this.__internal__.serial.response.buffer = S, S.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
683
695
|
a(this, n, p).call(this, this.__internal__.serial.response.buffer, !0), this.__internal__.serial.response.buffer = new Uint8Array(0);
|
|
684
696
|
}, this.__internal__.serial.free_timeout_ms ?? 50));
|
|
685
|
-
},
|
|
697
|
+
}, M = async function() {
|
|
686
698
|
const e = this.__internal__.serial.port;
|
|
687
699
|
if (!e || !e.readable) throw new Error("Port is not readable");
|
|
688
700
|
const t = e.readable.getReader();
|
|
@@ -691,16 +703,18 @@ n = new WeakSet(), y = function(e) {
|
|
|
691
703
|
for (; this.__internal__.serial.keep_reading; ) {
|
|
692
704
|
const { value: i, done: r } = await t.read();
|
|
693
705
|
if (r) break;
|
|
694
|
-
a(this, n,
|
|
706
|
+
a(this, n, P).call(this, i), this.__internal__.serial.response.delimited ? await a(this, n, R).call(this) : this.__internal__.serial.response.length === null ? await a(this, n, $).call(this) : await a(this, n, D).call(this);
|
|
695
707
|
}
|
|
696
708
|
} catch (i) {
|
|
697
709
|
this.serialErrors(i);
|
|
698
710
|
} finally {
|
|
699
711
|
t.releaseLock(), this.__internal__.serial.keep_reading = !0, this.__internal__.serial.port && await this.__internal__.serial.port.close();
|
|
700
712
|
}
|
|
701
|
-
},
|
|
713
|
+
}, m = function(e) {
|
|
714
|
+
e !== this.__internal__.serial.connecting && (this.__internal__.serial.connecting = e, e ? this.dispatch("serial:connecting", { active: !0 }) : this.dispatch("serial:connecting", { active: !1 }));
|
|
715
|
+
}, q = async function() {
|
|
702
716
|
return typeof window > "u" ? !1 : "serial" in navigator && "forget" in SerialPort.prototype && this.__internal__.serial.port ? (await this.__internal__.serial.port.forget(), !0) : !1;
|
|
703
|
-
},
|
|
717
|
+
}, N = function() {
|
|
704
718
|
[
|
|
705
719
|
"serial:connected",
|
|
706
720
|
"serial:connecting",
|
|
@@ -720,21 +734,21 @@ n = new WeakSet(), y = function(e) {
|
|
|
720
734
|
].forEach((t) => {
|
|
721
735
|
this.serialRegisterAvailableListener(t);
|
|
722
736
|
});
|
|
723
|
-
},
|
|
737
|
+
}, O = function() {
|
|
724
738
|
const e = this;
|
|
725
739
|
this.on("internal:queue", async () => {
|
|
726
740
|
var t;
|
|
727
|
-
await a(t = e, n,
|
|
728
|
-
}), a(this, n,
|
|
729
|
-
},
|
|
741
|
+
await a(t = e, n, H).call(t);
|
|
742
|
+
}), a(this, n, F).call(this);
|
|
743
|
+
}, F = function() {
|
|
730
744
|
const e = this;
|
|
731
745
|
navigator.serial.addEventListener("connect", async () => {
|
|
732
746
|
e.isDisconnected && await e.serialConnect().catch(() => {
|
|
733
747
|
});
|
|
734
748
|
});
|
|
735
|
-
},
|
|
749
|
+
}, H = async function() {
|
|
736
750
|
if (!a(this, n, y).call(this, this.__internal__.serial.port)) {
|
|
737
|
-
a(this, n,
|
|
751
|
+
a(this, n, w).call(this, { error: "Port is closed, not readable or writable." }), await this.serialConnect();
|
|
738
752
|
return;
|
|
739
753
|
}
|
|
740
754
|
if (this.__internal__.timeout.until_response || this.__internal__.serial.queue.length === 0) return;
|
|
@@ -742,23 +756,23 @@ n = new WeakSet(), y = function(e) {
|
|
|
742
756
|
let t = this.__internal__.time.response_general;
|
|
743
757
|
if (e.action === "connect" && (t = this.__internal__.time.response_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
|
|
744
758
|
await this.timeout(e.bytes, e.action);
|
|
745
|
-
}, t), this.__internal__.serial.last_action = e.action ?? "unknown", await a(this, n,
|
|
759
|
+
}, t), this.__internal__.serial.last_action = e.action ?? "unknown", await a(this, n, v).call(this, e.bytes), this.dispatch("serial:sent", {
|
|
746
760
|
action: e.action,
|
|
747
761
|
bytes: e.bytes
|
|
748
762
|
}), this.__internal__.auto_response) {
|
|
749
763
|
let r = new Uint8Array(0);
|
|
750
764
|
try {
|
|
751
765
|
r = this.validateBytes(this.__internal__.serial.auto_response);
|
|
752
|
-
} catch (
|
|
753
|
-
this.serialErrors(
|
|
766
|
+
} catch (_) {
|
|
767
|
+
this.serialErrors(_);
|
|
754
768
|
}
|
|
755
769
|
a(this, n, p).call(this, r);
|
|
756
770
|
}
|
|
757
771
|
const i = [...this.__internal__.serial.queue];
|
|
758
772
|
this.__internal__.serial.queue = i.splice(1);
|
|
759
|
-
},
|
|
773
|
+
}, j = function(e = 1) {
|
|
760
774
|
this.__internal__.device_number = e, !this.__internal__.bypassSerialBytesConnection && (this.__internal__.serial.bytes_connection = this.serialSetConnectionConstant(e));
|
|
761
|
-
},
|
|
775
|
+
}, W = function() {
|
|
762
776
|
this.__internal__.last_error = {
|
|
763
777
|
message: null,
|
|
764
778
|
action: null,
|
|
@@ -767,7 +781,7 @@ n = new WeakSet(), y = function(e) {
|
|
|
767
781
|
};
|
|
768
782
|
};
|
|
769
783
|
export {
|
|
770
|
-
|
|
784
|
+
K as Core,
|
|
771
785
|
h as Devices,
|
|
772
|
-
|
|
786
|
+
B as Dispatcher
|
|
773
787
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(l,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(l=typeof globalThis<"u"?globalThis:l||self,_(l.WebSerialCore={}))})(this,function(l){"use strict";var V=Object.defineProperty;var L=l=>{throw TypeError(l)};var z=(l,_,d)=>_ in l?V(l,_,{enumerable:!0,configurable:!0,writable:!0,value:d}):l[_]=d;var m=(l,_,d)=>z(l,typeof _!="symbol"?_+"":_,d),G=(l,_,d)=>_.has(l)||L("Cannot "+d);var B=(l,_,d)=>_.has(l)?L("Cannot add the same private member more than once"):_ instanceof WeakSet?_.add(l):_.set(l,d);var a=(l,_,d)=>(G(l,_,"access private method"),d);var s,b,C,E,$,g,D,U,k,P,I,R,M,q,N,O,H,F,j;class _ extends CustomEvent{constructor(r,e){super(r,e)}}class d extends EventTarget{constructor(){super(...arguments);m(this,"__listeners__",{debug:!1});m(this,"__debug__",!1)}dispatch(e,t=null){const i=new _(e,{detail:t});this.dispatchEvent(i),this.__debug__&&this.dispatchEvent(new _("debug",{detail:{type:e,data:t}}))}dispatchAsync(e,t=null,i=100){const n=this;setTimeout(()=>{n.dispatch(e,t)},i)}on(e,t){typeof this.__listeners__[e]<"u"&&!this.__listeners__[e]&&(this.__listeners__[e]=!0),this.addEventListener(e,t)}off(e,t){this.removeEventListener(e,t)}serialRegisterAvailableListener(e){this.__listeners__[e]||(this.__listeners__[e]=!1)}get availableListeners(){return Object.keys(this.__listeners__).sort().map(t=>({type:t,listening:this.__listeners__[t]}))}}const o=class o extends d{constructor(){super(),["change"].forEach(e=>{this.serialRegisterAvailableListener(e)})}static $dispatchChange(r=null){r&&r.$checkAndDispatchConnection(),o.instance.dispatch("change",{devices:o.devices,dispatcher:r})}static typeError(r){const e=new Error;throw e.message=`Type ${r} is not supported`,e.name="DeviceTypeError",e}static registerType(r){typeof o.devices[r]>"u"&&(o.devices[r]={})}static add(r){const e=r.typeDevice;typeof o.devices[e]>"u"&&(o.devices[e]={});const t=r.uuid;if(typeof o.devices[e]>"u"&&o.typeError(e),o.devices[e][t])throw new Error(`Device with id ${t} already exists`);return o.devices[e][t]=r,o.$dispatchChange(r),Object.keys(o.devices[e]).indexOf(t)}static get(r,e){return typeof o.devices[r]>"u"&&(o.devices[r]={}),typeof o.devices[r]>"u"&&o.typeError(r),o.devices[r][e]}static getAll(r=null){return r===null?o.devices:(typeof o.devices[r]>"u"&&o.typeError(r),o.devices[r])}static getList(){return Object.values(o.devices).map(e=>Object.values(e)).flat()}static getByNumber(r,e){return typeof o.devices[r]>"u"&&o.typeError(r),Object.values(o.devices[r]).find(i=>i.deviceNumber===e)??null}static getCustom(r,e=1){return typeof o.devices[r]>"u"&&o.typeError(r),Object.values(o.devices[r]).find(i=>i.deviceNumber===e)??null}};m(o,"instance"),m(o,"devices",{});let h=o;h.instance||(h.instance=new h);function x(v=100){return new Promise(r=>setTimeout(()=>r(),v))}function W(){return"serial"in navigator}const S={baudRate:9600,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"};class Q extends d{constructor({filters:e=null,config_port:t=S,no_device:i=1,device_listen_on_channel:n=1,bypassSerialBytesConnection:u=!1}={filters:null,config_port:S,no_device:1,device_listen_on_channel:1,bypassSerialBytesConnection:!1}){super();B(this,s);m(this,"__internal__",{bypassSerialBytesConnection:!1,auto_response:!1,device_number:1,aux_port_connector:0,last_error:{message:null,action:null,code:null,no_code:0},serial:{connected:!1,port:null,last_action:null,response:{length:null,buffer:new Uint8Array([]),as:"uint8",replacer:/[\n\r]+/g,limiter:null,prefixLimiter:!1,sufixLimiter:!0,delimited:!1},reader:null,input_done:null,output_done:null,input_stream:null,output_stream:null,keep_reading:!0,time_until_send_bytes:void 0,delay_first_connection:200,bytes_connection:null,filters:[],config_port:S,queue:[],auto_response:["DD","DD"],free_timeout_ms:50,useRTSCTS:!1},device:{type:"unknown",id:window.crypto.randomUUID(),listen_on_port:null},time:{response_connection:500,response_general:2e3},timeout:{until_response:0},interval:{reconnection:0}});if(!("serial"in navigator))throw new Error("Web Serial not supported");e&&(this.serialFilters=e),t&&(this.serialConfigPort=t),u&&(this.__internal__.bypassSerialBytesConnection=u),i&&a(this,s,F).call(this,i),n&&["number","string"].includes(typeof n)&&(this.listenOnChannel=n),a(this,s,q).call(this),a(this,s,N).call(this)}set listenOnChannel(e){if(typeof e=="string"&&(e=parseInt(e)),isNaN(e)||e<1||e>255)throw new Error("Invalid port number");this.__internal__.device.listen_on_port=e,!this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(e))}get lastAction(){return this.__internal__.serial.last_action}get listenOnChannel(){return this.__internal__.device.listen_on_port??1}set serialFilters(e){if(this.isConnected)throw new Error("Cannot change serial filters while connected");this.__internal__.serial.filters=e}get serialFilters(){return this.__internal__.serial.filters}set serialConfigPort(e){if(this.isConnected)throw new Error("Cannot change serial filters while connected");this.__internal__.serial.config_port=e}get serialConfigPort(){return this.__internal__.serial.config_port}get useRTSCTS(){return this.__internal__.serial.useRTSCTS}set useRTSCTS(e){this.__internal__.serial.useRTSCTS=e}get isConnected(){const e=this.__internal__.serial.connected,t=a(this,s,b).call(this,this.__internal__.serial.port);return e&&!t&&a(this,s,C).call(this,{error:"Port is closed, not readable or writable."}),this.__internal__.serial.connected=t,this.__internal__.serial.connected}get isDisconnected(){const e=this.__internal__.serial.connected,t=a(this,s,b).call(this,this.__internal__.serial.port);return!e&&t&&(this.dispatch("serial:connected"),h.$dispatchChange(this)),this.__internal__.serial.connected=t,!this.__internal__.serial.connected}get deviceNumber(){return this.__internal__.device_number}get uuid(){return this.__internal__.device.id}get typeDevice(){return this.__internal__.device.type}get queue(){return this.__internal__.serial.queue}get responseDelimited(){return this.__internal__.serial.response.delimited}set responseDelimited(e){if(typeof e!="boolean")throw new Error("responseDelimited must be a boolean");this.__internal__.serial.response.delimited=e}get responsePrefixLimited(){return this.__internal__.serial.response.prefixLimiter}set responsePrefixLimited(e){if(typeof e!="boolean")throw new Error("responsePrefixLimited must be a boolean");this.__internal__.serial.response.prefixLimiter=e}get responseSufixLimited(){return this.__internal__.serial.response.sufixLimiter}set responseSufixLimited(e){if(typeof e!="boolean")throw new Error("responseSufixLimited must be a boolean");this.__internal__.serial.response.sufixLimiter=e}get responseLimiter(){return this.__internal__.serial.response.limiter}set responseLimiter(e){if(typeof e!="string"&&!(e instanceof RegExp))throw new Error("responseLimiter must be a string or a RegExp");this.__internal__.serial.response.limiter=e}get fixedBytesMessage(){return this.__internal__.serial.response.length}set fixedBytesMessage(e){if(e!==null&&(typeof e!="number"||e<1))throw new Error("Invalid length for fixed bytes message");this.__internal__.serial.response.length=e}get timeoutBeforeResponseBytes(){return this.__internal__.serial.free_timeout_ms||50}set timeoutBeforeResponseBytes(e){if(e!==void 0&&(typeof e!="number"||e<1))throw new Error("Invalid timeout for response bytes");this.__internal__.serial.free_timeout_ms=e??50}get bypassSerialBytesConnection(){return this.__internal__.bypassSerialBytesConnection}set bypassSerialBytesConnection(e){if(typeof e!="boolean")throw new Error("bypassSerialBytesConnection must be a boolean");this.__internal__.bypassSerialBytesConnection=e}async timeout(e,t){this.__internal__.last_error.message="Operation response timed out.",this.__internal__.last_error.action=t,this.__internal__.last_error.code=e,this.__internal__.timeout.until_response&&(clearTimeout(this.__internal__.timeout.until_response),this.__internal__.timeout.until_response=0),t==="connect"?(this.__internal__.serial.connected=!1,this.dispatch("serial:reconnect",{}),h.$dispatchChange(this)):t==="connection:start"&&(await this.serialDisconnect(),this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector+=1,h.$dispatchChange(this),await this.serialConnect()),this.dispatch("serial:timeout",{...this.__internal__.last_error,bytes:e,action:t})}async disconnect(e=null){await this.serialDisconnect(),a(this,s,C).call(this,e)}async connect(){return this.isConnected?`${this.typeDevice} device ${this.deviceNumber} already connected`:new Promise((e,t)=>{W()||t("Web Serial not supported"),setTimeout(async()=>{await x(499),await this.serialConnect(),this.isConnected?e(`${this.typeDevice} device ${this.deviceNumber} connected`):t(`${this.typeDevice} device ${this.deviceNumber} not connected`)},1)})}async serialDisconnect(){try{const e=this.__internal__.serial.reader,t=this.__internal__.serial.output_stream;e&&(await e.cancel().catch(n=>this.serialErrors(n)),await this.__internal__.serial.input_done),t&&(await t.getWriter().close(),await this.__internal__.serial.output_done),this.__internal__.serial.connected&&this.__internal__.serial&&this.__internal__.serial.port&&await this.__internal__.serial.port.close()}catch(e){this.serialErrors(e)}finally{this.__internal__.serial.reader=null,this.__internal__.serial.input_done=null,this.__internal__.serial.output_stream=null,this.__internal__.serial.output_done=null,this.__internal__.serial.connected=!1,this.__internal__.serial.port=null,h.$dispatchChange(this)}}getResponseAsArrayBuffer(){this.__internal__.serial.response.as="arraybuffer"}getResponseAsArrayHex(){this.__internal__.serial.response.as="hex"}getResponseAsUint8Array(){this.__internal__.serial.response.as="uint8"}getResponseAsString(){this.__internal__.serial.response.as="string"}async serialPortsSaved(e){const t=this.serialFilters;if(this.__internal__.aux_port_connector<e.length){const i=this.__internal__.aux_port_connector;this.__internal__.serial.port=e[i]}else this.__internal__.aux_port_connector=0,this.__internal__.serial.port=await navigator.serial.requestPort({filters:t});if(!this.__internal__.serial.port)throw new Error("Select another port please")}serialErrors(e){const t=e.toString().toLowerCase();switch(!0){case t.includes("must be handling a user gesture to show a permission request"):case t.includes("the port is closed."):case t.includes("the port is closed or is not writable"):case t.includes("the port is closed or is not readable"):case t.includes("the port is closed or is not readable/writable"):case t.includes("select another port please"):case t.includes("no port selected by the user"):case t.includes("this readable stream reader has been released and cannot be used to cancel its previous owner stream"):this.dispatch("serial:need-permission",{}),h.$dispatchChange(this);break;case t.includes("the port is already open."):case t.includes("failed to open serial port"):this.serialDisconnect().then(async()=>{this.__internal__.aux_port_connector+=1,await this.serialConnect()});break;case t.includes("cannot read properties of undefined (reading 'writable')"):case t.includes("cannot read properties of null (reading 'writable')"):case t.includes("cannot read property 'writable' of null"):case t.includes("cannot read property 'writable' of undefined"):this.serialDisconnect().then(async()=>{await this.serialConnect()});break;case t.includes("'close' on 'serialport': a call to close() is already in progress."):break;case t.includes("failed to execute 'open' on 'serialport': a call to open() is already in progress."):break;case t.includes("the port is already closed."):break;case t.includes("the device has been lost"):this.dispatch("serial:lost",{}),h.$dispatchChange(this);break;case t.includes("navigator.serial is undefined"):this.dispatch("serial:unsupported",{});break;default:console.error(e);break}this.dispatch("serial:error",e)}async serialConnect(){try{this.dispatch("serial:connecting",{});const e=await a(this,s,D).call(this);if(e.length>0)await this.serialPortsSaved(e);else{const n=this.serialFilters;this.__internal__.serial.port=await navigator.serial.requestPort({filters:n})}const t=this.__internal__.serial.port;if(!t)throw new Error("No port selected by the user");await t.open(this.serialConfigPort);const i=this;t.onconnect=n=>{console.log(n),i.dispatch("serial:connected",n),h.$dispatchChange(this),i.__internal__.serial.queue.length>0&&i.dispatch("internal:queue",{})},t.ondisconnect=async()=>{await i.disconnect()},await x(this.__internal__.serial.delay_first_connection),this.__internal__.timeout.until_response=setTimeout(async()=>{await i.timeout(i.__internal__.serial.bytes_connection??[],"connection:start")},this.__internal__.time.response_connection),this.__internal__.serial.last_action="connect",await a(this,s,E).call(this,this.__internal__.serial.bytes_connection??[]),this.dispatch("serial:sent",{action:"connect",bytes:this.__internal__.serial.bytes_connection}),this.__internal__.auto_response&&a(this,s,g).call(this,this.__internal__.serial.auto_response),await a(this,s,R).call(this)}catch(e){this.serialErrors(e)}}async serialForget(){return await a(this,s,M).call(this)}decToHex(e){return typeof e=="string"&&(e=parseInt(e,10)),e.toString(16)}hexToDec(e){return parseInt(e,16)}hexMaker(e="00",t=2){return e.toString().padStart(t,"0").toLowerCase()}add0x(e){const t=[];return e.forEach((i,n)=>{t[n]="0x"+i}),t}bytesToHex(e){return this.add0x(Array.from(e,t=>this.hexMaker(t)))}validateBytes(e){let t=new Uint8Array(0);if(e instanceof Uint8Array)t=e;else if(typeof e=="string")t=this.parseStringToTextEncoder(e);else if(Array.isArray(e)&&typeof e[0]=="string")t=this.stringArrayToUint8Array(e);else if(Array.isArray(e)&&typeof e[0]=="number")t=new Uint8Array(e);else throw new Error("Invalid data type");return t}async appendToQueue(e,t){const i=this.validateBytes(e);if(["connect","connection:start"].includes(t)){if(this.__internal__.serial.connected)return;await this.serialConnect();return}this.__internal__.serial.queue.push({bytes:i,action:t}),this.dispatch("internal:queue",{})}serialSetConnectionConstant(e=1){if(this.__internal__.bypassSerialBytesConnection)return this.__internal__.serial.bytes_connection;throw console.warn("wtf?",this.bypassSerialBytesConnection),new Error(`Method not implemented 'serialSetConnectionConstant' to listen on channel ${e}`)}serialMessage(e){throw console.log(e),this.dispatch("serial:message",{code:e}),new Error("Method not implemented 'serialMessage'")}serialCorruptMessage(e){throw console.log(e),this.dispatch("serial:corrupt-message",{code:e}),new Error("Method not implemented 'serialCorruptMessage'")}clearSerialQueue(){this.__internal__.serial.queue=[]}sumHex(e){let t=0;return e.forEach(i=>{t+=parseInt(i,16)}),t.toString(16)}toString(){return JSON.stringify({__class:this.typeDevice,device_number:this.deviceNumber,uuid:this.uuid,connected:this.isConnected,connection:this.__internal__.serial.bytes_connection})}softReload(){a(this,s,j).call(this),this.dispatch("serial:soft-reload",{})}async sendConnect(){if(!this.__internal__.serial.bytes_connection)throw new Error("No connection bytes defined");await this.appendToQueue(this.__internal__.serial.bytes_connection,"connect")}async sendCustomCode({code:e=[]}={code:[]}){if(!e)throw new Error("No data to send");this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.validateBytes(e)),await this.appendToQueue(e,"custom")}stringToArrayHex(e){return Array.from(e).map(t=>t.charCodeAt(0).toString(16))}stringToArrayBuffer(e,t=`
|
|
1
|
+
(function(l,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(l=typeof globalThis<"u"?globalThis:l||self,_(l.WebSerialCore={}))})(this,function(l){"use strict";var G=Object.defineProperty;var B=l=>{throw TypeError(l)};var J=(l,_,d)=>_ in l?G(l,_,{enumerable:!0,configurable:!0,writable:!0,value:d}):l[_]=d;var m=(l,_,d)=>J(l,typeof _!="symbol"?_+"":_,d),K=(l,_,d)=>_.has(l)||B("Cannot "+d);var U=(l,_,d)=>_.has(l)?B("Cannot add the same private member more than once"):_ instanceof WeakSet?_.add(l):_.set(l,d);var a=(l,_,d)=>(K(l,_,"access private method"),d);var n,b,v,k,E,D,g,I,P,$,R,M,q,w,N,O,F,H,j,W,Q;class _ extends CustomEvent{constructor(r,e){super(r,e)}}class d extends EventTarget{constructor(){super(...arguments);m(this,"__listeners__",{debug:!1});m(this,"__debug__",!1)}dispatch(e,t=null){const i=new _(e,{detail:t});this.dispatchEvent(i),this.__debug__&&this.dispatchEvent(new _("debug",{detail:{type:e,data:t}}))}dispatchAsync(e,t=null,i=100){const s=this;setTimeout(()=>{s.dispatch(e,t)},i)}on(e,t){typeof this.__listeners__[e]<"u"&&!this.__listeners__[e]&&(this.__listeners__[e]=!0),this.addEventListener(e,t)}off(e,t){this.removeEventListener(e,t)}serialRegisterAvailableListener(e){this.__listeners__[e]||(this.__listeners__[e]=!1)}get availableListeners(){return Object.keys(this.__listeners__).sort().map(t=>({type:t,listening:this.__listeners__[t]}))}}const o=class o extends d{constructor(){super(),["change"].forEach(e=>{this.serialRegisterAvailableListener(e)})}static $dispatchChange(r=null){r&&r.$checkAndDispatchConnection(),o.instance.dispatch("change",{devices:o.devices,dispatcher:r})}static typeError(r){const e=new Error;throw e.message=`Type ${r} is not supported`,e.name="DeviceTypeError",e}static registerType(r){typeof o.devices[r]>"u"&&(o.devices[r]={})}static add(r){const e=r.typeDevice;typeof o.devices[e]>"u"&&(o.devices[e]={});const t=r.uuid;if(typeof o.devices[e]>"u"&&o.typeError(e),o.devices[e][t])throw new Error(`Device with id ${t} already exists`);return o.devices[e][t]=r,o.$dispatchChange(r),Object.keys(o.devices[e]).indexOf(t)}static get(r,e){return typeof o.devices[r]>"u"&&(o.devices[r]={}),typeof o.devices[r]>"u"&&o.typeError(r),o.devices[r][e]}static getAll(r=null){return r===null?o.devices:(typeof o.devices[r]>"u"&&o.typeError(r),o.devices[r])}static getList(){return Object.values(o.devices).map(e=>Object.values(e)).flat()}static getByNumber(r,e){return typeof o.devices[r]>"u"&&o.typeError(r),Object.values(o.devices[r]).find(i=>i.deviceNumber===e)??null}static getCustom(r,e=1){return typeof o.devices[r]>"u"&&o.typeError(r),Object.values(o.devices[r]).find(i=>i.deviceNumber===e)??null}};m(o,"instance"),m(o,"devices",{});let u=o;u.instance||(u.instance=new u);function A(x=100){return new Promise(r=>setTimeout(()=>r(),x))}function V(){return"serial"in navigator}const S={baudRate:9600,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"};class z extends d{constructor({filters:e=null,config_port:t=S,no_device:i=1,device_listen_on_channel:s=1,bypassSerialBytesConnection:c=!1}={filters:null,config_port:S,no_device:1,device_listen_on_channel:1,bypassSerialBytesConnection:!1}){super();U(this,n);m(this,"__internal__",{bypassSerialBytesConnection:!1,auto_response:!1,device_number:1,aux_port_connector:0,last_error:{message:null,action:null,code:null,no_code:0},serial:{aux_connecting:"idle",connecting:!1,connected:!1,port:null,last_action:null,response:{length:null,buffer:new Uint8Array([]),as:"uint8",replacer:/[\n\r]+/g,limiter:null,prefixLimiter:!1,sufixLimiter:!0,delimited:!1},reader:null,input_done:null,output_done:null,input_stream:null,output_stream:null,keep_reading:!0,time_until_send_bytes:void 0,delay_first_connection:200,bytes_connection:null,filters:[],config_port:S,queue:[],auto_response:["DD","DD"],free_timeout_ms:50,useRTSCTS:!1},device:{type:"unknown",id:window.crypto.randomUUID(),listen_on_port:null},time:{response_connection:500,response_general:2e3},timeout:{until_response:0},interval:{reconnection:0}});if(!("serial"in navigator))throw new Error("Web Serial not supported");e&&(this.serialFilters=e),t&&(this.serialConfigPort=t),c&&(this.__internal__.bypassSerialBytesConnection=c),i&&a(this,n,W).call(this,i),s&&["number","string"].includes(typeof s)&&(this.listenOnChannel=s),a(this,n,O).call(this),a(this,n,F).call(this)}set listenOnChannel(e){if(typeof e=="string"&&(e=parseInt(e)),isNaN(e)||e<1||e>255)throw new Error("Invalid port number");this.__internal__.device.listen_on_port=e,!this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(e))}get lastAction(){return this.__internal__.serial.last_action}get listenOnChannel(){return this.__internal__.device.listen_on_port??1}set serialFilters(e){if(this.isConnected)throw new Error("Cannot change serial filters while connected");this.__internal__.serial.filters=e}get serialFilters(){return this.__internal__.serial.filters}set serialConfigPort(e){if(this.isConnected)throw new Error("Cannot change serial filters while connected");this.__internal__.serial.config_port=e}get serialConfigPort(){return this.__internal__.serial.config_port}get useRTSCTS(){return this.__internal__.serial.useRTSCTS}set useRTSCTS(e){this.__internal__.serial.useRTSCTS=e}get isConnected(){const e=this.__internal__.serial.connected,t=a(this,n,b).call(this,this.__internal__.serial.port);return e&&!t&&a(this,n,v).call(this,{error:"Port is closed, not readable or writable."}),this.__internal__.serial.connected=t,this.__internal__.serial.connected}get isConnecting(){return this.__internal__.serial.connecting}get isDisconnected(){const e=this.__internal__.serial.connected,t=a(this,n,b).call(this,this.__internal__.serial.port);return!e&&t&&(this.dispatch("serial:connected"),a(this,n,w).call(this,!1),u.$dispatchChange(this)),this.__internal__.serial.connected=t,!this.__internal__.serial.connected}get deviceNumber(){return this.__internal__.device_number}get uuid(){return this.__internal__.device.id}get typeDevice(){return this.__internal__.device.type}get queue(){return this.__internal__.serial.queue}get responseDelimited(){return this.__internal__.serial.response.delimited}set responseDelimited(e){if(typeof e!="boolean")throw new Error("responseDelimited must be a boolean");this.__internal__.serial.response.delimited=e}get responsePrefixLimited(){return this.__internal__.serial.response.prefixLimiter}set responsePrefixLimited(e){if(typeof e!="boolean")throw new Error("responsePrefixLimited must be a boolean");this.__internal__.serial.response.prefixLimiter=e}get responseSufixLimited(){return this.__internal__.serial.response.sufixLimiter}set responseSufixLimited(e){if(typeof e!="boolean")throw new Error("responseSufixLimited must be a boolean");this.__internal__.serial.response.sufixLimiter=e}get responseLimiter(){return this.__internal__.serial.response.limiter}set responseLimiter(e){if(typeof e!="string"&&!(e instanceof RegExp))throw new Error("responseLimiter must be a string or a RegExp");this.__internal__.serial.response.limiter=e}get fixedBytesMessage(){return this.__internal__.serial.response.length}set fixedBytesMessage(e){if(e!==null&&(typeof e!="number"||e<1))throw new Error("Invalid length for fixed bytes message");this.__internal__.serial.response.length=e}get timeoutBeforeResponseBytes(){return this.__internal__.serial.free_timeout_ms||50}set timeoutBeforeResponseBytes(e){if(e!==void 0&&(typeof e!="number"||e<1))throw new Error("Invalid timeout for response bytes");this.__internal__.serial.free_timeout_ms=e??50}get bypassSerialBytesConnection(){return this.__internal__.bypassSerialBytesConnection}set bypassSerialBytesConnection(e){if(typeof e!="boolean")throw new Error("bypassSerialBytesConnection must be a boolean");this.__internal__.bypassSerialBytesConnection=e}async timeout(e,t){this.__internal__.last_error.message="Operation response timed out.",this.__internal__.last_error.action=t,this.__internal__.last_error.code=e,this.__internal__.timeout.until_response&&(clearTimeout(this.__internal__.timeout.until_response),this.__internal__.timeout.until_response=0),t==="connect"?(this.__internal__.serial.connected=!1,this.dispatch("serial:reconnect",{}),u.$dispatchChange(this)):t==="connection:start"&&(await this.serialDisconnect(),this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector+=1,u.$dispatchChange(this),await this.serialConnect()),this.dispatch("serial:timeout",{...this.__internal__.last_error,bytes:e,action:t})}async disconnect(e=null){await this.serialDisconnect(),a(this,n,v).call(this,e)}async connect(){return this.isConnected?!0:(this.__internal__.serial.aux_connecting="idle",new Promise((e,t)=>{V()||t("Web Serial not supported");const i=a(this,n,k).bind(this);this.on("serial:connecting",i);const s=setInterval(()=>{this.__internal__.serial.aux_connecting==="finished"?(clearInterval(s),this.__internal__.serial.aux_connecting="idle",this.off("serial:connecting",i),this.isConnected?e(!0):t(`${this.typeDevice} device ${this.deviceNumber} not connected`)):this.__internal__.serial.aux_connecting==="connecting"&&(this.__internal__.serial.aux_connecting="idle",this.dispatch("serial:connecting",{active:!0}))},100);this.serialConnect()}))}async serialDisconnect(){try{const e=this.__internal__.serial.reader,t=this.__internal__.serial.output_stream;e&&(await e.cancel().catch(s=>this.serialErrors(s)),await this.__internal__.serial.input_done),t&&(await t.getWriter().close(),await this.__internal__.serial.output_done),this.__internal__.serial.connected&&this.__internal__.serial&&this.__internal__.serial.port&&await this.__internal__.serial.port.close()}catch(e){this.serialErrors(e)}finally{this.__internal__.serial.reader=null,this.__internal__.serial.input_done=null,this.__internal__.serial.output_stream=null,this.__internal__.serial.output_done=null,this.__internal__.serial.connected=!1,this.__internal__.serial.port=null,u.$dispatchChange(this)}}getResponseAsArrayBuffer(){this.__internal__.serial.response.as="arraybuffer"}getResponseAsArrayHex(){this.__internal__.serial.response.as="hex"}getResponseAsUint8Array(){this.__internal__.serial.response.as="uint8"}getResponseAsString(){this.__internal__.serial.response.as="string"}async serialPortsSaved(e){const t=this.serialFilters;if(this.__internal__.aux_port_connector<e.length){const i=this.__internal__.aux_port_connector;this.__internal__.serial.port=e[i]}else this.__internal__.aux_port_connector=0,this.__internal__.serial.port=await navigator.serial.requestPort({filters:t});if(!this.__internal__.serial.port)throw new Error("Select another port please")}serialErrors(e){const t=e.toString().toLowerCase();switch(!0){case t.includes("must be handling a user gesture to show a permission request"):case t.includes("the port is closed."):case t.includes("the port is closed or is not writable"):case t.includes("the port is closed or is not readable"):case t.includes("the port is closed or is not readable/writable"):case t.includes("select another port please"):case t.includes("no port selected by the user"):case t.includes("this readable stream reader has been released and cannot be used to cancel its previous owner stream"):this.dispatch("serial:need-permission",{}),u.$dispatchChange(this);break;case t.includes("the port is already open."):case t.includes("failed to open serial port"):this.serialDisconnect().then(async()=>{this.__internal__.aux_port_connector+=1,await this.serialConnect()});break;case t.includes("cannot read properties of undefined (reading 'writable')"):case t.includes("cannot read properties of null (reading 'writable')"):case t.includes("cannot read property 'writable' of null"):case t.includes("cannot read property 'writable' of undefined"):this.serialDisconnect().then(async()=>{await this.serialConnect()});break;case t.includes("'close' on 'serialport': a call to close() is already in progress."):break;case t.includes("failed to execute 'open' on 'serialport': a call to open() is already in progress."):break;case t.includes("the port is already closed."):break;case t.includes("the device has been lost"):this.dispatch("serial:lost",{}),u.$dispatchChange(this);break;case t.includes("navigator.serial is undefined"):this.dispatch("serial:unsupported",{});break;default:console.error(e);break}this.dispatch("serial:error",e)}async serialConnect(){try{a(this,n,w).call(this,!0);const e=await a(this,n,I).call(this);if(e.length>0)await this.serialPortsSaved(e);else{const s=this.serialFilters;this.__internal__.serial.port=await navigator.serial.requestPort({filters:s})}const t=this.__internal__.serial.port;if(!t)throw new Error("No port selected by the user");await t.open(this.serialConfigPort);const i=this;t.onconnect=s=>{var c;i.dispatch("serial:connected",s),a(c=i,n,w).call(c,!1),u.$dispatchChange(this),i.__internal__.serial.queue.length>0&&i.dispatch("internal:queue",{})},t.ondisconnect=async()=>{await i.disconnect()},await A(this.__internal__.serial.delay_first_connection),this.__internal__.timeout.until_response=setTimeout(async()=>{await i.timeout(i.__internal__.serial.bytes_connection??[],"connection:start")},this.__internal__.time.response_connection),this.__internal__.serial.last_action="connect",await a(this,n,E).call(this,this.__internal__.serial.bytes_connection??[]),this.dispatch("serial:sent",{action:"connect",bytes:this.__internal__.serial.bytes_connection}),this.__internal__.auto_response&&a(this,n,g).call(this,this.__internal__.serial.auto_response),await a(this,n,q).call(this)}catch(e){a(this,n,w).call(this,!1),this.serialErrors(e)}}async serialForget(){return await a(this,n,N).call(this)}decToHex(e){return typeof e=="string"&&(e=parseInt(e,10)),e.toString(16)}hexToDec(e){return parseInt(e,16)}hexMaker(e="00",t=2){return e.toString().padStart(t,"0").toLowerCase()}add0x(e){const t=[];return e.forEach((i,s)=>{t[s]="0x"+i}),t}bytesToHex(e){return this.add0x(Array.from(e,t=>this.hexMaker(t)))}validateBytes(e){let t=new Uint8Array(0);if(e instanceof Uint8Array)t=e;else if(typeof e=="string")t=this.parseStringToTextEncoder(e);else if(Array.isArray(e)&&typeof e[0]=="string")t=this.stringArrayToUint8Array(e);else if(Array.isArray(e)&&typeof e[0]=="number")t=new Uint8Array(e);else throw new Error("Invalid data type");return t}async appendToQueue(e,t){const i=this.validateBytes(e);if(["connect","connection:start"].includes(t)){if(this.__internal__.serial.connected)return;await this.serialConnect();return}this.__internal__.serial.queue.push({bytes:i,action:t}),this.dispatch("internal:queue",{})}serialSetConnectionConstant(e=1){if(this.__internal__.bypassSerialBytesConnection)return this.__internal__.serial.bytes_connection;throw new Error(`Method not implemented 'serialSetConnectionConstant' to listen on channel ${e}`)}serialMessage(e){throw console.log(e),this.dispatch("serial:message",{code:e}),new Error("Method not implemented 'serialMessage'")}serialCorruptMessage(e){throw console.log(e),this.dispatch("serial:corrupt-message",{code:e}),new Error("Method not implemented 'serialCorruptMessage'")}clearSerialQueue(){this.__internal__.serial.queue=[]}sumHex(e){let t=0;return e.forEach(i=>{t+=parseInt(i,16)}),t.toString(16)}toString(){return JSON.stringify({__class:this.typeDevice,device_number:this.deviceNumber,uuid:this.uuid,connected:this.isConnected,connection:this.__internal__.serial.bytes_connection})}softReload(){a(this,n,Q).call(this),this.dispatch("serial:soft-reload",{})}async sendConnect(){if(!this.__internal__.serial.bytes_connection)throw new Error("No connection bytes defined");await this.appendToQueue(this.__internal__.serial.bytes_connection,"connect")}async sendCustomCode({code:e=[]}={code:[]}){if(!e)throw new Error("No data to send");this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.validateBytes(e)),await this.appendToQueue(e,"custom")}stringToArrayHex(e){return Array.from(e).map(t=>t.charCodeAt(0).toString(16))}stringToArrayBuffer(e,t=`
|
|
2
2
|
`){return this.parseStringToTextEncoder(e,t).buffer}parseStringToTextEncoder(e="",t=`
|
|
3
3
|
`){const i=new TextEncoder;return e+=t,i.encode(e)}parseStringToBytes(e="",t=`
|
|
4
|
-
`){const i=this.parseStringToTextEncoder(e,t);return Array.from(i).map(
|
|
4
|
+
`){const i=this.parseStringToTextEncoder(e,t);return Array.from(i).map(s=>s.toString(16))}parseUint8ToHex(e){return Array.from(e).map(t=>t.toString(16))}parseHexToUint8(e){return new Uint8Array(e.map(t=>parseInt(t,16)))}stringArrayToUint8Array(e){const t=[];return typeof e=="string"?this.parseStringToTextEncoder(e).buffer:(e.forEach(i=>{const s=i.replace("0x","");t.push(parseInt(s,16))}),new Uint8Array(t))}parseUint8ArrayToString(e){let t=new Uint8Array(0);e instanceof Uint8Array?t=e:t=this.stringArrayToUint8Array(e),e=this.parseUint8ToHex(t);const i=e.map(s=>parseInt(s,16));return this.__internal__.serial.response.replacer?String.fromCharCode(...i).replace(this.__internal__.serial.response.replacer,""):String.fromCharCode(...i)}hexToAscii(e){const t=e.toString();let i="";for(let s=0;s<t.length;s+=2)i+=String.fromCharCode(parseInt(t.substring(s,2),16));return i}asciiToHex(e){const t=[];for(let i=0,s=e.length;i<s;i++){const c=Number(e.charCodeAt(i)).toString(16);t.push(c)}return t.join("")}$checkAndDispatchConnection(){return this.isConnected}}n=new WeakSet,b=function(e){return!!(e&&e.readable&&e.writable)},v=function(e=null){this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector=0,this.dispatch("serial:disconnected",e),u.$dispatchChange(this)},k=function(e){this.__internal__.serial.aux_connecting=e.detail.active?"connecting":"finished"},E=async function(e){const t=this.__internal__.serial.port;if(!t||t&&(!t.readable||!t.writable))throw a(this,n,v).call(this,{error:"Port is closed, not readable or writable."}),new Error("The port is closed or is not readable/writable");const i=this.validateBytes(e);if(this.useRTSCTS&&await a(this,n,D).call(this,t,5e3),t.writable===null)return;const s=t.writable.getWriter();await s.write(i),s.releaseLock()},D=async function(e,t=5e3){const i=Date.now();for(;;){if(Date.now()-i>t)throw new Error("Timeout waiting for clearToSend signal");const{clearToSend:s}=await e.getSignals();if(s)return;await A(100)}},g=function(e=new Uint8Array([]),t=!1){if(e&&e.length>0){const i=this.__internal__.serial.connected;if(this.__internal__.serial.connected=a(this,n,b).call(this,this.__internal__.serial.port),u.$dispatchChange(this),!i&&this.__internal__.serial.connected&&(this.dispatch("serial:connected"),a(this,n,w).call(this,!1)),this.__internal__.interval.reconnection&&(clearInterval(this.__internal__.interval.reconnection),this.__internal__.interval.reconnection=0),this.__internal__.timeout.until_response&&(clearTimeout(this.__internal__.timeout.until_response),this.__internal__.timeout.until_response=0),this.__internal__.serial.response.as==="hex")t?this.serialCorruptMessage(this.parseUint8ToHex(e)):this.serialMessage(this.parseUint8ToHex(e));else if(this.__internal__.serial.response.as==="uint8")t?this.serialCorruptMessage(e):this.serialMessage(e);else if(this.__internal__.serial.response.as==="string"){const s=this.parseUint8ArrayToString(e);if(this.__internal__.serial.response.limiter!==null){const c=s.split(this.__internal__.serial.response.limiter);for(const h in c)c[h]&&(t?this.serialCorruptMessage(c[h]):this.serialMessage(c[h]))}else t?this.serialCorruptMessage(s):this.serialMessage(s)}else{const s=this.stringToArrayBuffer(this.parseUint8ArrayToString(e));t?this.serialCorruptMessage(s):this.serialMessage(s)}}this.__internal__.serial.queue.length!==0&&this.dispatch("internal:queue",{})},I=async function(){const e=this.serialFilters,t=await navigator.serial.getPorts({filters:e});return e.length===0?t:t.filter(s=>{const c=s.getInfo();return e.some(h=>c.usbProductId===h.usbProductId&&c.usbVendorId===h.usbVendorId)}).filter(s=>!a(this,n,b).call(this,s))},P=function(e){if(e){const t=this.__internal__.serial.response.buffer,i=new Uint8Array(t.length+e.byteLength);i.set(t,0),i.set(new Uint8Array(e),t.length),this.__internal__.serial.response.buffer=i}},$=async function(){this.__internal__.serial.time_until_send_bytes&&(clearTimeout(this.__internal__.serial.time_until_send_bytes),this.__internal__.serial.time_until_send_bytes=0),this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{this.__internal__.serial.response.buffer&&a(this,n,g).call(this,this.__internal__.serial.response.buffer),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms||50)},R=async function(){const e=this.__internal__.serial.response.length;let t=this.__internal__.serial.response.buffer;if(this.__internal__.serial.time_until_send_bytes&&(clearTimeout(this.__internal__.serial.time_until_send_bytes),this.__internal__.serial.time_until_send_bytes=0),!(e===null||!t||t.length===0)){for(;t.length>=e;){const i=t.slice(0,e);a(this,n,g).call(this,i),t=t.slice(e)}this.__internal__.serial.response.buffer=t,t.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{a(this,n,g).call(this,this.__internal__.serial.response.buffer,!0)},this.__internal__.serial.free_timeout_ms||50))}},M=async function(){const{limiter:e,prefixLimiter:t=!1,sufixLimiter:i=!0}=this.__internal__.serial.response;if(!e)throw new Error("No limiter defined for delimited serial response");const s=this.__internal__.serial.response.buffer;if(!e||!s||s.length===0)return;this.__internal__.serial.time_until_send_bytes&&(clearTimeout(this.__internal__.serial.time_until_send_bytes),this.__internal__.serial.time_until_send_bytes=0);let h=new TextDecoder().decode(s);const C=[];if(typeof e=="string"){let p;if(t&&i)p=new RegExp(`${e}([^${e}]+)${e}`,"g");else if(t)p=new RegExp(`${e}([^${e}]*)`,"g");else if(i)p=new RegExp(`([^${e}]+)${e}`,"g");else return;let y,f=0;for(;(y=p.exec(h))!==null;)C.push(new TextEncoder().encode(y[1])),f=p.lastIndex;h=h.slice(f)}else if(e instanceof RegExp){let p,y=0;if(t&&i){const f=new RegExp(`${e.source}(.*?)${e.source}`,"g");for(;(p=f.exec(h))!==null;)C.push(new TextEncoder().encode(p[1])),y=f.lastIndex}else if(i)for(;(p=e.exec(h))!==null;){const f=p.index,T=h.slice(y,f);C.push(new TextEncoder().encode(T)),y=e.lastIndex}else if(t){const f=h.split(e);f.shift();for(const T of f)C.push(new TextEncoder().encode(T));h=""}h=h.slice(y)}for(const p of C)a(this,n,g).call(this,p);const L=new TextEncoder().encode(h);this.__internal__.serial.response.buffer=L,L.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{a(this,n,g).call(this,this.__internal__.serial.response.buffer,!0),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms??50))},q=async function(){const e=this.__internal__.serial.port;if(!e||!e.readable)throw new Error("Port is not readable");const t=e.readable.getReader();this.__internal__.serial.reader=t;try{for(;this.__internal__.serial.keep_reading;){const{value:i,done:s}=await t.read();if(s)break;a(this,n,P).call(this,i),this.__internal__.serial.response.delimited?await a(this,n,M).call(this):this.__internal__.serial.response.length===null?await a(this,n,$).call(this):await a(this,n,R).call(this)}}catch(i){this.serialErrors(i)}finally{t.releaseLock(),this.__internal__.serial.keep_reading=!0,this.__internal__.serial.port&&await this.__internal__.serial.port.close()}},w=function(e){e!==this.__internal__.serial.connecting&&(this.__internal__.serial.connecting=e,e?this.dispatch("serial:connecting",{active:!0}):this.dispatch("serial:connecting",{active:!1}))},N=async function(){return typeof window>"u"?!1:"serial"in navigator&&"forget"in SerialPort.prototype&&this.__internal__.serial.port?(await this.__internal__.serial.port.forget(),!0):!1},O=function(){["serial:connected","serial:connecting","serial:reconnect","serial:timeout","serial:disconnected","serial:sent","serial:soft-reload","serial:message","serial:corrupt-message","unknown","serial:need-permission","serial:lost","serial:unsupported","serial:error","debug"].forEach(t=>{this.serialRegisterAvailableListener(t)})},F=function(){const e=this;this.on("internal:queue",async()=>{var t;await a(t=e,n,j).call(t)}),a(this,n,H).call(this)},H=function(){const e=this;navigator.serial.addEventListener("connect",async()=>{e.isDisconnected&&await e.serialConnect().catch(()=>{})})},j=async function(){if(!a(this,n,b).call(this,this.__internal__.serial.port)){a(this,n,v).call(this,{error:"Port is closed, not readable or writable."}),await this.serialConnect();return}if(this.__internal__.timeout.until_response||this.__internal__.serial.queue.length===0)return;const e=this.__internal__.serial.queue[0];let t=this.__internal__.time.response_general;if(e.action==="connect"&&(t=this.__internal__.time.response_connection),this.__internal__.timeout.until_response=setTimeout(async()=>{await this.timeout(e.bytes,e.action)},t),this.__internal__.serial.last_action=e.action??"unknown",await a(this,n,E).call(this,e.bytes),this.dispatch("serial:sent",{action:e.action,bytes:e.bytes}),this.__internal__.auto_response){let s=new Uint8Array(0);try{s=this.validateBytes(this.__internal__.serial.auto_response)}catch(c){this.serialErrors(c)}a(this,n,g).call(this,s)}const i=[...this.__internal__.serial.queue];this.__internal__.serial.queue=i.splice(1)},W=function(e=1){this.__internal__.device_number=e,!this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(e))},Q=function(){this.__internal__.last_error={message:null,action:null,code:null,no_code:0}},l.Core=z,l.Devices=u,l.Dispatcher=d,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webserial-core",
|
|
3
3
|
"description": "Webserial Core to easy connections with serial devices",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.9",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "danidoble",
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"format": "prettier --write ./lib/**/*.ts"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@eslint/js": "^9.
|
|
48
|
+
"@eslint/js": "^9.29.0",
|
|
49
49
|
"@types/w3c-web-serial": "^1.0.8",
|
|
50
|
-
"eslint": "^9.
|
|
50
|
+
"eslint": "^9.29.0",
|
|
51
51
|
"globals": "^15.15.0",
|
|
52
52
|
"prettier": "3.4.2",
|
|
53
53
|
"typescript": "~5.7.3",
|
|
54
|
-
"typescript-eslint": "^8.
|
|
54
|
+
"typescript-eslint": "^8.35.0",
|
|
55
55
|
"vite": "^6.3.5"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|