webserial-core 1.0.9 → 1.0.11
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.map +1 -1
- package/dist/Devices.d.ts +6 -0
- package/dist/Devices.d.ts.map +1 -1
- package/dist/Dispatcher.d.ts +5 -0
- package/dist/Dispatcher.d.ts.map +1 -1
- package/dist/webserial-core.js +209 -172
- package/dist/webserial-core.umd.cjs +2 -2
- package/package.json +3 -3
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,aAAa,EAAE,OAAO,CAAC;IACvB,YAAY,EAAE,OAAO,CAAC;IACtB,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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/Devices.d.ts
CHANGED
|
@@ -19,6 +19,12 @@ export declare class Devices extends Dispatcher {
|
|
|
19
19
|
static getList(): Core[];
|
|
20
20
|
static getByNumber(type: string, device_number: number): Core | null;
|
|
21
21
|
static getCustom(type: string, device_number?: number): Core | null;
|
|
22
|
+
static connectToAll(): Promise<boolean>;
|
|
23
|
+
static disconnectAll(): Promise<boolean>;
|
|
24
|
+
static areAllConnected(): Promise<boolean>;
|
|
25
|
+
static areAllDisconnected(): Promise<boolean>;
|
|
26
|
+
static getAllConnected(): Promise<Core[]>;
|
|
27
|
+
static getAllDisconnected(): Promise<Core[]>;
|
|
22
28
|
}
|
|
23
29
|
export {};
|
|
24
30
|
//# sourceMappingURL=Devices.d.ts.map
|
package/dist/Devices.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Devices.d.ts","sourceRoot":"","sources":["../lib/Devices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,UAAU,OAAO;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAED,UAAU,QAAQ;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,qBAAa,OAAQ,SAAQ,UAAU;IACrC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC;IACzB,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAM;;WAYhB,eAAe,CAAC,MAAM,GAAE,IAAI,GAAG,IAAW,GAAG,IAAI;WAOjD,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;WAO7B,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;WAMhC,GAAG,CAAC,MAAM,EAAE,IAAI,GAAG,MAAM;WAoBzB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI;WAUnC,MAAM,CAAC,IAAI,GAAE,MAAM,GAAG,IAAW,GAAG,OAAO,GAAG,QAAQ;WAOtD,OAAO,IAAI,IAAI,EAAE;WAWjB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;WAO7D,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,GAAE,MAAU,GAAG,IAAI,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"Devices.d.ts","sourceRoot":"","sources":["../lib/Devices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAA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ventTarget implements IDispatcher {
|
|
20
20
|
__listeners__: Listeners;
|
|
21
21
|
__debug__: boolean;
|
|
22
|
+
__listenersCallbacks__: {
|
|
23
|
+
key: string;
|
|
24
|
+
callback: EventListenerOrEventListenerObject;
|
|
25
|
+
}[];
|
|
22
26
|
dispatch(type: string, data?: DataType): void;
|
|
23
27
|
dispatchAsync(type: string, data?: null, ms?: number): void;
|
|
24
28
|
on(type: string, callback: EventListenerOrEventListenerObject): void;
|
|
25
29
|
off(type: string, callback: EventListenerOrEventListenerObject): void;
|
|
26
30
|
serialRegisterAvailableListener(type: string): void;
|
|
27
31
|
get availableListeners(): AvailableListeners;
|
|
32
|
+
removeAllListeners(): void;
|
|
28
33
|
}
|
|
29
34
|
export {};
|
|
30
35
|
//# sourceMappingURL=Dispatcher.d.ts.map
|
package/dist/Dispatcher.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dispatcher.d.ts","sourceRoot":"","sources":["../lib/Dispatcher.ts"],"names":[],"mappings":"AAEA,KAAK,iBAAiB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AAC9D,KAAK,kBAAkB,GAAG,iBAAiB,EAAE,CAAC;AAE9C,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC;AAE1D,UAAU,WAAW;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IAE9C,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEhE,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;IAEhD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,a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B;AAED,qBAAa,UAAW,SAAQ,WAAY,YAAW,WAAW;IAChE,aAAa,EAAE,SAAS,CAEtB;IACF,SAAS,EAAE,OAAO,CAAS;IAE3B,sBAAsB,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,kCAAkC,CAAA;KAAE,EAAE,CAAM;IAEtF,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,QAAe;IAQ5C,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,OAAO,EAAE,EAAE,SAAM;IAQjD,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,kCAAkC;IAS7D,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,kCAAkC;IAQ9D,+BAA+B,CAAC,IAAI,EAAE,MAAM;IAMnD,IAAI,kBAAkB,IAAI,kBAAkB,CAQ3C;IAEM,kBAAkB,IAAI,IAAI;CAalC"}
|
package/dist/webserial-core.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var J = Object.defineProperty;
|
|
2
|
+
var k = (l) => {
|
|
3
3
|
throw TypeError(l);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
super(s, e);
|
|
5
|
+
var K = (l, i, e) => i in l ? J(l, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[i] = e;
|
|
6
|
+
var y = (l, i, e) => K(l, typeof i != "symbol" ? i + "" : i, e), T = (l, i, e) => i.has(l) || k("Cannot " + e);
|
|
7
|
+
var v = (l, i, e) => (T(l, i, "read from private field"), e ? e.call(l) : i.get(l)), S = (l, i, e) => i.has(l) ? k("Cannot add the same private member more than once") : i instanceof WeakSet ? i.add(l) : i.set(l, e), P = (l, i, e, t) => (T(l, i, "write to private field"), t ? t.call(l, e) : i.set(l, e), e), o = (l, i, e) => (T(l, i, "access private method"), e);
|
|
8
|
+
class B extends CustomEvent {
|
|
9
|
+
constructor(i, e) {
|
|
10
|
+
super(i, e);
|
|
12
11
|
}
|
|
13
12
|
}
|
|
14
|
-
class
|
|
13
|
+
class U extends EventTarget {
|
|
15
14
|
constructor() {
|
|
16
15
|
super(...arguments);
|
|
17
|
-
|
|
16
|
+
y(this, "__listeners__", {
|
|
18
17
|
debug: !1
|
|
19
18
|
});
|
|
20
|
-
|
|
19
|
+
y(this, "__debug__", !1);
|
|
20
|
+
y(this, "__listenersCallbacks__", []);
|
|
21
21
|
}
|
|
22
22
|
dispatch(e, t = null) {
|
|
23
|
-
const
|
|
24
|
-
this.dispatchEvent(
|
|
23
|
+
const n = new B(e, { detail: t });
|
|
24
|
+
this.dispatchEvent(n), this.__debug__ && this.dispatchEvent(new B("debug", { detail: { type: e, data: t } }));
|
|
25
25
|
}
|
|
26
|
-
dispatchAsync(e, t = null,
|
|
26
|
+
dispatchAsync(e, t = null, n = 100) {
|
|
27
27
|
const r = this;
|
|
28
28
|
setTimeout(() => {
|
|
29
29
|
r.dispatch(e, t);
|
|
30
|
-
},
|
|
30
|
+
}, n);
|
|
31
31
|
}
|
|
32
32
|
on(e, t) {
|
|
33
|
-
typeof this.__listeners__[e] < "u" && !this.__listeners__[e] && (this.__listeners__[e] = !0), this.addEventListener(e, t);
|
|
33
|
+
typeof this.__listeners__[e] < "u" && !this.__listeners__[e] && (this.__listeners__[e] = !0), this.__listenersCallbacks__.push({ key: e, callback: t }), this.addEventListener(e, t);
|
|
34
34
|
}
|
|
35
35
|
off(e, t) {
|
|
36
|
-
this.removeEventListener(e, t);
|
|
36
|
+
this.__listenersCallbacks__ = this.__listenersCallbacks__.filter((n) => !(n.key === e && n.callback === t)), this.removeEventListener(e, t);
|
|
37
37
|
}
|
|
38
38
|
serialRegisterAvailableListener(e) {
|
|
39
39
|
this.__listeners__[e] || (this.__listeners__[e] = !1);
|
|
@@ -44,59 +44,97 @@ class B extends EventTarget {
|
|
|
44
44
|
listening: this.__listeners__[t]
|
|
45
45
|
}));
|
|
46
46
|
}
|
|
47
|
+
removeAllListeners() {
|
|
48
|
+
for (const e of this.__listenersCallbacks__)
|
|
49
|
+
["internal:queue"].includes(e.key) || (this.__listenersCallbacks__ = this.__listenersCallbacks__.filter((t) => !(t.key === e.key && t.callback === e.callback)), this.removeEventListener(e.key, e.callback));
|
|
50
|
+
for (const e of Object.keys(this.__listeners__))
|
|
51
|
+
this.__listeners__[e] = !1;
|
|
52
|
+
}
|
|
47
53
|
}
|
|
48
|
-
const
|
|
54
|
+
const a = class a extends U {
|
|
49
55
|
constructor() {
|
|
50
56
|
super(), ["change"].forEach((e) => {
|
|
51
57
|
this.serialRegisterAvailableListener(e);
|
|
52
58
|
});
|
|
53
59
|
}
|
|
54
|
-
static $dispatchChange(
|
|
55
|
-
|
|
60
|
+
static $dispatchChange(i = null) {
|
|
61
|
+
i && i.$checkAndDispatchConnection(), a.instance.dispatch("change", { devices: a.devices, dispatcher: i });
|
|
56
62
|
}
|
|
57
|
-
static typeError(
|
|
63
|
+
static typeError(i) {
|
|
58
64
|
const e = new Error();
|
|
59
|
-
throw e.message = `Type ${
|
|
65
|
+
throw e.message = `Type ${i} is not supported`, e.name = "DeviceTypeError", e;
|
|
60
66
|
}
|
|
61
|
-
static registerType(
|
|
62
|
-
typeof
|
|
67
|
+
static registerType(i) {
|
|
68
|
+
typeof a.devices[i] > "u" && (a.devices = { ...a.devices, [i]: {} });
|
|
63
69
|
}
|
|
64
|
-
static add(
|
|
65
|
-
const e =
|
|
66
|
-
typeof
|
|
67
|
-
const t =
|
|
68
|
-
if (typeof
|
|
70
|
+
static add(i) {
|
|
71
|
+
const e = i.typeDevice;
|
|
72
|
+
typeof a.devices[e] > "u" && a.registerType(e);
|
|
73
|
+
const t = i.uuid;
|
|
74
|
+
if (typeof a.devices[e] > "u" && a.typeError(e), a.devices[e][t])
|
|
69
75
|
throw new Error(`Device with id ${t} already exists`);
|
|
70
|
-
return
|
|
76
|
+
return a.devices[e][t] = i, a.$dispatchChange(i), Object.keys(a.devices[e]).indexOf(t);
|
|
71
77
|
}
|
|
72
|
-
static get(
|
|
73
|
-
return typeof
|
|
78
|
+
static get(i, e) {
|
|
79
|
+
return typeof a.devices[i] > "u" && a.registerType(i), typeof a.devices[i] > "u" && a.typeError(i), a.devices[i][e];
|
|
74
80
|
}
|
|
75
|
-
static getAll(
|
|
76
|
-
return
|
|
81
|
+
static getAll(i = null) {
|
|
82
|
+
return i === null ? a.devices : (typeof a.devices[i] > "u" && a.typeError(i), a.devices[i]);
|
|
77
83
|
}
|
|
78
84
|
static getList() {
|
|
79
|
-
return Object.values(
|
|
80
|
-
}
|
|
81
|
-
static getByNumber(
|
|
82
|
-
return typeof
|
|
83
|
-
}
|
|
84
|
-
static getCustom(
|
|
85
|
-
return typeof
|
|
85
|
+
return Object.values(a.devices).map((e) => Object.values(e)).flat();
|
|
86
|
+
}
|
|
87
|
+
static getByNumber(i, e) {
|
|
88
|
+
return typeof a.devices[i] > "u" && a.typeError(i), Object.values(a.devices[i]).find((n) => n.deviceNumber === e) ?? null;
|
|
89
|
+
}
|
|
90
|
+
static getCustom(i, e = 1) {
|
|
91
|
+
return typeof a.devices[i] > "u" && a.typeError(i), Object.values(a.devices[i]).find((n) => n.deviceNumber === e) ?? null;
|
|
92
|
+
}
|
|
93
|
+
static async connectToAll() {
|
|
94
|
+
const i = a.getList();
|
|
95
|
+
for (const e of i)
|
|
96
|
+
e.isConnected || await e.connect().catch(console.warn);
|
|
97
|
+
return Promise.resolve(a.areAllConnected());
|
|
98
|
+
}
|
|
99
|
+
static async disconnectAll() {
|
|
100
|
+
const i = a.getList();
|
|
101
|
+
for (const e of i)
|
|
102
|
+
e.isDisconnected || await e.disconnect().catch(console.warn);
|
|
103
|
+
return Promise.resolve(a.areAllDisconnected());
|
|
104
|
+
}
|
|
105
|
+
static async areAllConnected() {
|
|
106
|
+
const i = a.getList();
|
|
107
|
+
for (const e of i)
|
|
108
|
+
if (!e.isConnected) return Promise.resolve(!1);
|
|
109
|
+
return Promise.resolve(!0);
|
|
110
|
+
}
|
|
111
|
+
static async areAllDisconnected() {
|
|
112
|
+
const i = a.getList();
|
|
113
|
+
for (const e of i)
|
|
114
|
+
if (!e.isDisconnected) return Promise.resolve(!1);
|
|
115
|
+
return Promise.resolve(!0);
|
|
116
|
+
}
|
|
117
|
+
static async getAllConnected() {
|
|
118
|
+
const i = a.getList();
|
|
119
|
+
return Promise.resolve(i.filter((e) => e.isConnected));
|
|
120
|
+
}
|
|
121
|
+
static async getAllDisconnected() {
|
|
122
|
+
const i = a.getList();
|
|
123
|
+
return Promise.resolve(i.filter((e) => e.isDisconnected));
|
|
86
124
|
}
|
|
87
125
|
};
|
|
88
|
-
|
|
89
|
-
let h =
|
|
126
|
+
y(a, "instance"), y(a, "devices", {});
|
|
127
|
+
let h = a;
|
|
90
128
|
h.instance || (h.instance = new h());
|
|
91
|
-
function
|
|
129
|
+
function D(l = 100) {
|
|
92
130
|
return new Promise(
|
|
93
|
-
(
|
|
131
|
+
(i) => setTimeout(() => i(), l)
|
|
94
132
|
);
|
|
95
133
|
}
|
|
96
|
-
function
|
|
134
|
+
function X() {
|
|
97
135
|
return "serial" in navigator;
|
|
98
136
|
}
|
|
99
|
-
const
|
|
137
|
+
const E = {
|
|
100
138
|
baudRate: 9600,
|
|
101
139
|
dataBits: 8,
|
|
102
140
|
stopBits: 1,
|
|
@@ -104,24 +142,24 @@ const x = {
|
|
|
104
142
|
bufferSize: 32768,
|
|
105
143
|
flowControl: "none"
|
|
106
144
|
};
|
|
107
|
-
var
|
|
108
|
-
class
|
|
145
|
+
var p, s, m, C, I, A, $, f, R, M, q, N, O, F, b, H, j, W, Q, V, z, G;
|
|
146
|
+
class Z extends U {
|
|
109
147
|
constructor({
|
|
110
148
|
filters: e = null,
|
|
111
|
-
config_port: t =
|
|
112
|
-
no_device:
|
|
149
|
+
config_port: t = E,
|
|
150
|
+
no_device: n = 1,
|
|
113
151
|
device_listen_on_channel: r = 1,
|
|
114
152
|
bypassSerialBytesConnection: _ = !1
|
|
115
153
|
} = {
|
|
116
154
|
filters: null,
|
|
117
|
-
config_port:
|
|
155
|
+
config_port: E,
|
|
118
156
|
no_device: 1,
|
|
119
157
|
device_listen_on_channel: 1,
|
|
120
158
|
bypassSerialBytesConnection: !1
|
|
121
159
|
}) {
|
|
122
160
|
super();
|
|
123
|
-
|
|
124
|
-
|
|
161
|
+
S(this, s);
|
|
162
|
+
y(this, "__internal__", {
|
|
125
163
|
bypassSerialBytesConnection: !1,
|
|
126
164
|
auto_response: !1,
|
|
127
165
|
device_number: 1,
|
|
@@ -158,7 +196,7 @@ class K extends B {
|
|
|
158
196
|
delay_first_connection: 200,
|
|
159
197
|
bytes_connection: null,
|
|
160
198
|
filters: [],
|
|
161
|
-
config_port:
|
|
199
|
+
config_port: E,
|
|
162
200
|
queue: [],
|
|
163
201
|
auto_response: ["DD", "DD"],
|
|
164
202
|
free_timeout_ms: 50,
|
|
@@ -182,9 +220,10 @@ class K extends B {
|
|
|
182
220
|
reconnection: 0
|
|
183
221
|
}
|
|
184
222
|
});
|
|
223
|
+
S(this, p, null);
|
|
185
224
|
if (!("serial" in navigator))
|
|
186
225
|
throw new Error("Web Serial not supported");
|
|
187
|
-
e && (this.serialFilters = e), t && (this.serialConfigPort = t), _ && (this.__internal__.bypassSerialBytesConnection = _),
|
|
226
|
+
e && (this.serialFilters = e), t && (this.serialConfigPort = t), _ && (this.__internal__.bypassSerialBytesConnection = _), n && o(this, s, z).call(this, n), r && ["number", "string"].includes(typeof r) && (this.listenOnChannel = r), o(this, s, j).call(this), o(this, s, W).call(this);
|
|
188
227
|
}
|
|
189
228
|
set listenOnChannel(e) {
|
|
190
229
|
if (typeof e == "string" && (e = parseInt(e)), isNaN(e) || e < 1 || e > 255)
|
|
@@ -218,15 +257,15 @@ class K extends B {
|
|
|
218
257
|
this.__internal__.serial.useRTSCTS = e;
|
|
219
258
|
}
|
|
220
259
|
get isConnected() {
|
|
221
|
-
const e = this.__internal__.serial.connected, t =
|
|
222
|
-
return e && !t &&
|
|
260
|
+
const e = this.__internal__.serial.connected, t = o(this, s, m).call(this, this.__internal__.serial.port);
|
|
261
|
+
return e && !t && o(this, s, C).call(this, { error: "Port is closed, not readable or writable." }), this.__internal__.serial.connected = t, this.__internal__.serial.connected;
|
|
223
262
|
}
|
|
224
263
|
get isConnecting() {
|
|
225
264
|
return this.__internal__.serial.connecting;
|
|
226
265
|
}
|
|
227
266
|
get isDisconnected() {
|
|
228
|
-
const e = this.__internal__.serial.connected, t =
|
|
229
|
-
return !e && t && (this.dispatch("serial:connected"),
|
|
267
|
+
const e = this.__internal__.serial.connected, t = o(this, s, m).call(this, this.__internal__.serial.port);
|
|
268
|
+
return !e && t && (this.dispatch("serial:connected"), o(this, s, b).call(this, !1), h.$dispatchChange(this)), this.__internal__.serial.connected = t, !this.__internal__.serial.connected;
|
|
230
269
|
}
|
|
231
270
|
get deviceNumber() {
|
|
232
271
|
return this.__internal__.device_number;
|
|
@@ -304,15 +343,13 @@ class K extends B {
|
|
|
304
343
|
});
|
|
305
344
|
}
|
|
306
345
|
async disconnect(e = null) {
|
|
307
|
-
await this.serialDisconnect(),
|
|
346
|
+
await this.serialDisconnect(), o(this, s, C).call(this, e);
|
|
308
347
|
}
|
|
309
348
|
async connect() {
|
|
310
349
|
return this.isConnected ? !0 : (this.__internal__.serial.aux_connecting = "idle", new Promise((e, t) => {
|
|
311
|
-
|
|
312
|
-
const
|
|
313
|
-
|
|
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 }));
|
|
350
|
+
X() || t("Web Serial not supported"), v(this, p) || P(this, p, o(this, s, I).bind(this)), this.on("internal:connecting", v(this, p));
|
|
351
|
+
const n = setInterval(() => {
|
|
352
|
+
this.__internal__.serial.aux_connecting === "finished" ? (clearInterval(n), this.__internal__.serial.aux_connecting = "idle", v(this, p) !== null && this.off("internal:connecting", v(this, p)), 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("internal:connecting", { active: !0 }), this.dispatch("serial:connecting", { active: !0 }));
|
|
316
353
|
}, 100);
|
|
317
354
|
this.serialConnect();
|
|
318
355
|
}));
|
|
@@ -342,8 +379,8 @@ class K extends B {
|
|
|
342
379
|
async serialPortsSaved(e) {
|
|
343
380
|
const t = this.serialFilters;
|
|
344
381
|
if (this.__internal__.aux_port_connector < e.length) {
|
|
345
|
-
const
|
|
346
|
-
this.__internal__.serial.port = e[
|
|
382
|
+
const n = this.__internal__.aux_port_connector;
|
|
383
|
+
this.__internal__.serial.port = e[n];
|
|
347
384
|
} else
|
|
348
385
|
this.__internal__.aux_port_connector = 0, this.__internal__.serial.port = await navigator.serial.requestPort({
|
|
349
386
|
filters: t
|
|
@@ -400,8 +437,8 @@ class K extends B {
|
|
|
400
437
|
}
|
|
401
438
|
async serialConnect() {
|
|
402
439
|
try {
|
|
403
|
-
|
|
404
|
-
const e = await
|
|
440
|
+
o(this, s, b).call(this, !0);
|
|
441
|
+
const e = await o(this, s, R).call(this);
|
|
405
442
|
if (e.length > 0)
|
|
406
443
|
await this.serialPortsSaved(e);
|
|
407
444
|
else {
|
|
@@ -414,24 +451,24 @@ class K extends B {
|
|
|
414
451
|
if (!t)
|
|
415
452
|
throw new Error("No port selected by the user");
|
|
416
453
|
await t.open(this.serialConfigPort);
|
|
417
|
-
const
|
|
454
|
+
const n = this;
|
|
418
455
|
t.onconnect = (r) => {
|
|
419
456
|
var _;
|
|
420
|
-
|
|
457
|
+
n.dispatch("serial:connected", r), o(_ = n, s, b).call(_, !1), h.$dispatchChange(this), n.__internal__.serial.queue.length > 0 && n.dispatch("internal:queue", {});
|
|
421
458
|
}, t.ondisconnect = async () => {
|
|
422
|
-
await
|
|
423
|
-
}, await
|
|
424
|
-
await
|
|
425
|
-
}, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await
|
|
459
|
+
await n.disconnect();
|
|
460
|
+
}, await D(this.__internal__.serial.delay_first_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
|
|
461
|
+
await n.timeout(n.__internal__.serial.bytes_connection ?? [], "connection:start");
|
|
462
|
+
}, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await o(this, s, A).call(this, this.__internal__.serial.bytes_connection ?? []), this.dispatch("serial:sent", {
|
|
426
463
|
action: "connect",
|
|
427
464
|
bytes: this.__internal__.serial.bytes_connection
|
|
428
|
-
}), this.__internal__.auto_response &&
|
|
465
|
+
}), this.__internal__.auto_response && o(this, s, f).call(this, this.__internal__.serial.auto_response), await o(this, s, F).call(this);
|
|
429
466
|
} catch (e) {
|
|
430
|
-
|
|
467
|
+
o(this, s, b).call(this, !1), this.serialErrors(e);
|
|
431
468
|
}
|
|
432
469
|
}
|
|
433
470
|
async serialForget() {
|
|
434
|
-
return await
|
|
471
|
+
return await o(this, s, H).call(this);
|
|
435
472
|
}
|
|
436
473
|
decToHex(e) {
|
|
437
474
|
return typeof e == "string" && (e = parseInt(e, 10)), e.toString(16);
|
|
@@ -444,8 +481,8 @@ class K extends B {
|
|
|
444
481
|
}
|
|
445
482
|
add0x(e) {
|
|
446
483
|
const t = [];
|
|
447
|
-
return e.forEach((
|
|
448
|
-
t[r] = "0x" +
|
|
484
|
+
return e.forEach((n, r) => {
|
|
485
|
+
t[r] = "0x" + n;
|
|
449
486
|
}), t;
|
|
450
487
|
}
|
|
451
488
|
bytesToHex(e) {
|
|
@@ -466,13 +503,13 @@ class K extends B {
|
|
|
466
503
|
return t;
|
|
467
504
|
}
|
|
468
505
|
async appendToQueue(e, t) {
|
|
469
|
-
const
|
|
506
|
+
const n = this.validateBytes(e);
|
|
470
507
|
if (["connect", "connection:start"].includes(t)) {
|
|
471
508
|
if (this.__internal__.serial.connected) return;
|
|
472
509
|
await this.serialConnect();
|
|
473
510
|
return;
|
|
474
511
|
}
|
|
475
|
-
this.__internal__.serial.queue.push({ bytes:
|
|
512
|
+
this.__internal__.serial.queue.push({ bytes: n, action: t }), this.dispatch("internal:queue", {});
|
|
476
513
|
}
|
|
477
514
|
serialSetConnectionConstant(e = 1) {
|
|
478
515
|
if (this.__internal__.bypassSerialBytesConnection) return this.__internal__.serial.bytes_connection;
|
|
@@ -489,8 +526,8 @@ class K extends B {
|
|
|
489
526
|
}
|
|
490
527
|
sumHex(e) {
|
|
491
528
|
let t = 0;
|
|
492
|
-
return e.forEach((
|
|
493
|
-
t += parseInt(
|
|
529
|
+
return e.forEach((n) => {
|
|
530
|
+
t += parseInt(n, 16);
|
|
494
531
|
}), t.toString(16);
|
|
495
532
|
}
|
|
496
533
|
toString() {
|
|
@@ -503,7 +540,7 @@ class K extends B {
|
|
|
503
540
|
});
|
|
504
541
|
}
|
|
505
542
|
softReload() {
|
|
506
|
-
|
|
543
|
+
o(this, s, G).call(this), this.dispatch("serial:soft-reload", {});
|
|
507
544
|
}
|
|
508
545
|
async sendConnect() {
|
|
509
546
|
if (!this.__internal__.serial.bytes_connection)
|
|
@@ -524,13 +561,13 @@ class K extends B {
|
|
|
524
561
|
}
|
|
525
562
|
parseStringToTextEncoder(e = "", t = `
|
|
526
563
|
`) {
|
|
527
|
-
const
|
|
528
|
-
return e += t,
|
|
564
|
+
const n = new TextEncoder();
|
|
565
|
+
return e += t, n.encode(e);
|
|
529
566
|
}
|
|
530
567
|
parseStringToBytes(e = "", t = `
|
|
531
568
|
`) {
|
|
532
|
-
const
|
|
533
|
-
return Array.from(
|
|
569
|
+
const n = this.parseStringToTextEncoder(e, t);
|
|
570
|
+
return Array.from(n).map((r) => r.toString(16));
|
|
534
571
|
}
|
|
535
572
|
parseUint8ToHex(e) {
|
|
536
573
|
return Array.from(e).map((t) => t.toString(16));
|
|
@@ -540,28 +577,28 @@ class K extends B {
|
|
|
540
577
|
}
|
|
541
578
|
stringArrayToUint8Array(e) {
|
|
542
579
|
const t = [];
|
|
543
|
-
return typeof e == "string" ? this.parseStringToTextEncoder(e).buffer : (e.forEach((
|
|
544
|
-
const r =
|
|
580
|
+
return typeof e == "string" ? this.parseStringToTextEncoder(e).buffer : (e.forEach((n) => {
|
|
581
|
+
const r = n.replace("0x", "");
|
|
545
582
|
t.push(parseInt(r, 16));
|
|
546
583
|
}), new Uint8Array(t));
|
|
547
584
|
}
|
|
548
585
|
parseUint8ArrayToString(e) {
|
|
549
586
|
let t = new Uint8Array(0);
|
|
550
587
|
e instanceof Uint8Array ? t = e : t = this.stringArrayToUint8Array(e), e = this.parseUint8ToHex(t);
|
|
551
|
-
const
|
|
552
|
-
return this.__internal__.serial.response.replacer ? String.fromCharCode(...
|
|
588
|
+
const n = e.map((r) => parseInt(r, 16));
|
|
589
|
+
return this.__internal__.serial.response.replacer ? String.fromCharCode(...n).replace(this.__internal__.serial.response.replacer, "") : String.fromCharCode(...n);
|
|
553
590
|
}
|
|
554
591
|
hexToAscii(e) {
|
|
555
592
|
const t = e.toString();
|
|
556
|
-
let
|
|
593
|
+
let n = "";
|
|
557
594
|
for (let r = 0; r < t.length; r += 2)
|
|
558
|
-
|
|
559
|
-
return
|
|
595
|
+
n += String.fromCharCode(parseInt(t.substring(r, 2), 16));
|
|
596
|
+
return n;
|
|
560
597
|
}
|
|
561
598
|
asciiToHex(e) {
|
|
562
599
|
const t = [];
|
|
563
|
-
for (let
|
|
564
|
-
const _ = Number(e.charCodeAt(
|
|
600
|
+
for (let n = 0, r = e.length; n < r; n++) {
|
|
601
|
+
const _ = Number(e.charCodeAt(n)).toString(16);
|
|
565
602
|
t.push(_);
|
|
566
603
|
}
|
|
567
604
|
return t.join("");
|
|
@@ -570,33 +607,33 @@ class K extends B {
|
|
|
570
607
|
return this.isConnected;
|
|
571
608
|
}
|
|
572
609
|
}
|
|
573
|
-
|
|
610
|
+
p = new WeakMap(), s = new WeakSet(), m = function(e) {
|
|
574
611
|
return !!(e && e.readable && e.writable);
|
|
575
|
-
},
|
|
612
|
+
}, C = function(e = null) {
|
|
576
613
|
this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector = 0, this.dispatch("serial:disconnected", e), h.$dispatchChange(this);
|
|
577
|
-
},
|
|
614
|
+
}, I = function(e) {
|
|
578
615
|
this.__internal__.serial.aux_connecting = e.detail.active ? "connecting" : "finished";
|
|
579
|
-
},
|
|
616
|
+
}, A = async function(e) {
|
|
580
617
|
const t = this.__internal__.serial.port;
|
|
581
618
|
if (!t || t && (!t.readable || !t.writable))
|
|
582
|
-
throw
|
|
583
|
-
const
|
|
584
|
-
if (this.useRTSCTS && await
|
|
619
|
+
throw o(this, s, C).call(this, { error: "Port is closed, not readable or writable." }), new Error("The port is closed or is not readable/writable");
|
|
620
|
+
const n = this.validateBytes(e);
|
|
621
|
+
if (this.useRTSCTS && await o(this, s, $).call(this, t, 5e3), t.writable === null) return;
|
|
585
622
|
const r = t.writable.getWriter();
|
|
586
|
-
await r.write(
|
|
587
|
-
},
|
|
588
|
-
const
|
|
623
|
+
await r.write(n), r.releaseLock();
|
|
624
|
+
}, $ = async function(e, t = 5e3) {
|
|
625
|
+
const n = Date.now();
|
|
589
626
|
for (; ; ) {
|
|
590
|
-
if (Date.now() -
|
|
627
|
+
if (Date.now() - n > t)
|
|
591
628
|
throw new Error("Timeout waiting for clearToSend signal");
|
|
592
629
|
const { clearToSend: r } = await e.getSignals();
|
|
593
630
|
if (r) return;
|
|
594
|
-
await
|
|
631
|
+
await D(100);
|
|
595
632
|
}
|
|
596
|
-
},
|
|
633
|
+
}, f = function(e = new Uint8Array([]), t = !1) {
|
|
597
634
|
if (e && e.length > 0) {
|
|
598
|
-
const
|
|
599
|
-
if (this.__internal__.serial.connected =
|
|
635
|
+
const n = this.__internal__.serial.connected;
|
|
636
|
+
if (this.__internal__.serial.connected = o(this, s, m).call(this, this.__internal__.serial.port), h.$dispatchChange(this), !n && this.__internal__.serial.connected && (this.dispatch("serial:connected"), o(this, s, b).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")
|
|
600
637
|
t ? this.serialCorruptMessage(this.parseUint8ToHex(e)) : this.serialMessage(this.parseUint8ToHex(e));
|
|
601
638
|
else if (this.__internal__.serial.response.as === "uint8")
|
|
602
639
|
t ? this.serialCorruptMessage(e) : this.serialMessage(e);
|
|
@@ -614,38 +651,38 @@ n = new WeakSet(), y = function(e) {
|
|
|
614
651
|
}
|
|
615
652
|
}
|
|
616
653
|
this.__internal__.serial.queue.length !== 0 && this.dispatch("internal:queue", {});
|
|
617
|
-
},
|
|
654
|
+
}, R = async function() {
|
|
618
655
|
const e = this.serialFilters, t = await navigator.serial.getPorts({ filters: e });
|
|
619
656
|
return e.length === 0 ? t : t.filter((r) => {
|
|
620
657
|
const _ = r.getInfo();
|
|
621
658
|
return e.some((c) => _.usbProductId === c.usbProductId && _.usbVendorId === c.usbVendorId);
|
|
622
|
-
}).filter((r) => !
|
|
623
|
-
},
|
|
659
|
+
}).filter((r) => !o(this, s, m).call(this, r));
|
|
660
|
+
}, M = function(e) {
|
|
624
661
|
if (e) {
|
|
625
|
-
const t = this.__internal__.serial.response.buffer,
|
|
626
|
-
|
|
662
|
+
const t = this.__internal__.serial.response.buffer, n = new Uint8Array(t.length + e.byteLength);
|
|
663
|
+
n.set(t, 0), n.set(new Uint8Array(e), t.length), this.__internal__.serial.response.buffer = n;
|
|
627
664
|
}
|
|
628
|
-
},
|
|
665
|
+
}, q = async function() {
|
|
629
666
|
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(() => {
|
|
630
|
-
this.__internal__.serial.response.buffer &&
|
|
667
|
+
this.__internal__.serial.response.buffer && o(this, s, f).call(this, this.__internal__.serial.response.buffer), this.__internal__.serial.response.buffer = new Uint8Array(0);
|
|
631
668
|
}, this.__internal__.serial.free_timeout_ms || 50);
|
|
632
|
-
},
|
|
669
|
+
}, N = async function() {
|
|
633
670
|
const e = this.__internal__.serial.response.length;
|
|
634
671
|
let t = this.__internal__.serial.response.buffer;
|
|
635
672
|
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)) {
|
|
636
673
|
for (; t.length >= e; ) {
|
|
637
|
-
const
|
|
638
|
-
|
|
674
|
+
const n = t.slice(0, e);
|
|
675
|
+
o(this, s, f).call(this, n), t = t.slice(e);
|
|
639
676
|
}
|
|
640
677
|
this.__internal__.serial.response.buffer = t, t.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
641
|
-
|
|
678
|
+
o(this, s, f).call(this, this.__internal__.serial.response.buffer, !0);
|
|
642
679
|
}, this.__internal__.serial.free_timeout_ms || 50));
|
|
643
680
|
}
|
|
644
|
-
},
|
|
681
|
+
}, O = async function() {
|
|
645
682
|
const {
|
|
646
683
|
limiter: e,
|
|
647
684
|
prefixLimiter: t = !1,
|
|
648
|
-
sufixLimiter:
|
|
685
|
+
sufixLimiter: n = !0
|
|
649
686
|
} = this.__internal__.serial.response;
|
|
650
687
|
if (!e)
|
|
651
688
|
throw new Error("No limiter defined for delimited serial response");
|
|
@@ -653,68 +690,68 @@ n = new WeakSet(), y = function(e) {
|
|
|
653
690
|
if (!e || !r || r.length === 0) return;
|
|
654
691
|
this.__internal__.serial.time_until_send_bytes && (clearTimeout(this.__internal__.serial.time_until_send_bytes), this.__internal__.serial.time_until_send_bytes = 0);
|
|
655
692
|
let c = new TextDecoder().decode(r);
|
|
656
|
-
const
|
|
693
|
+
const w = [];
|
|
657
694
|
if (typeof e == "string") {
|
|
658
695
|
let u;
|
|
659
|
-
if (t &&
|
|
696
|
+
if (t && n)
|
|
660
697
|
u = new RegExp(`${e}([^${e}]+)${e}`, "g");
|
|
661
698
|
else if (t)
|
|
662
699
|
u = new RegExp(`${e}([^${e}]*)`, "g");
|
|
663
|
-
else if (
|
|
700
|
+
else if (n)
|
|
664
701
|
u = new RegExp(`([^${e}]+)${e}`, "g");
|
|
665
702
|
else
|
|
666
703
|
return;
|
|
667
|
-
let
|
|
668
|
-
for (; (
|
|
669
|
-
|
|
704
|
+
let g, d = 0;
|
|
705
|
+
for (; (g = u.exec(c)) !== null; )
|
|
706
|
+
w.push(new TextEncoder().encode(g[1])), d = u.lastIndex;
|
|
670
707
|
c = c.slice(d);
|
|
671
708
|
} else if (e instanceof RegExp) {
|
|
672
|
-
let u,
|
|
673
|
-
if (t &&
|
|
709
|
+
let u, g = 0;
|
|
710
|
+
if (t && n) {
|
|
674
711
|
const d = new RegExp(`${e.source}(.*?)${e.source}`, "g");
|
|
675
712
|
for (; (u = d.exec(c)) !== null; )
|
|
676
|
-
|
|
677
|
-
} else if (
|
|
713
|
+
w.push(new TextEncoder().encode(u[1])), g = d.lastIndex;
|
|
714
|
+
} else if (n)
|
|
678
715
|
for (; (u = e.exec(c)) !== null; ) {
|
|
679
|
-
const d = u.index,
|
|
680
|
-
|
|
716
|
+
const d = u.index, x = c.slice(g, d);
|
|
717
|
+
w.push(new TextEncoder().encode(x)), g = e.lastIndex;
|
|
681
718
|
}
|
|
682
719
|
else if (t) {
|
|
683
720
|
const d = c.split(e);
|
|
684
721
|
d.shift();
|
|
685
|
-
for (const
|
|
686
|
-
|
|
722
|
+
for (const x of d)
|
|
723
|
+
w.push(new TextEncoder().encode(x));
|
|
687
724
|
c = "";
|
|
688
725
|
}
|
|
689
|
-
c = c.slice(
|
|
726
|
+
c = c.slice(g);
|
|
690
727
|
}
|
|
691
|
-
for (const u of
|
|
692
|
-
|
|
693
|
-
const
|
|
694
|
-
this.__internal__.serial.response.buffer =
|
|
695
|
-
|
|
728
|
+
for (const u of w)
|
|
729
|
+
o(this, s, f).call(this, u);
|
|
730
|
+
const L = new TextEncoder().encode(c);
|
|
731
|
+
this.__internal__.serial.response.buffer = L, L.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
732
|
+
o(this, s, f).call(this, this.__internal__.serial.response.buffer, !0), this.__internal__.serial.response.buffer = new Uint8Array(0);
|
|
696
733
|
}, this.__internal__.serial.free_timeout_ms ?? 50));
|
|
697
|
-
},
|
|
734
|
+
}, F = async function() {
|
|
698
735
|
const e = this.__internal__.serial.port;
|
|
699
736
|
if (!e || !e.readable) throw new Error("Port is not readable");
|
|
700
737
|
const t = e.readable.getReader();
|
|
701
738
|
this.__internal__.serial.reader = t;
|
|
702
739
|
try {
|
|
703
740
|
for (; this.__internal__.serial.keep_reading; ) {
|
|
704
|
-
const { value:
|
|
741
|
+
const { value: n, done: r } = await t.read();
|
|
705
742
|
if (r) break;
|
|
706
|
-
|
|
743
|
+
o(this, s, M).call(this, n), this.__internal__.serial.response.delimited ? await o(this, s, O).call(this) : this.__internal__.serial.response.length === null ? await o(this, s, q).call(this) : await o(this, s, N).call(this);
|
|
707
744
|
}
|
|
708
|
-
} catch (
|
|
709
|
-
this.serialErrors(
|
|
745
|
+
} catch (n) {
|
|
746
|
+
this.serialErrors(n);
|
|
710
747
|
} finally {
|
|
711
748
|
t.releaseLock(), this.__internal__.serial.keep_reading = !0, this.__internal__.serial.port && await this.__internal__.serial.port.close();
|
|
712
749
|
}
|
|
713
|
-
},
|
|
714
|
-
e !== this.__internal__.serial.connecting && (this.__internal__.serial.connecting = e,
|
|
715
|
-
},
|
|
750
|
+
}, b = function(e) {
|
|
751
|
+
e !== this.__internal__.serial.connecting && (this.__internal__.serial.connecting = e, this.dispatch("serial:connecting", { active: e }), this.dispatch("internal:connecting", { active: e }));
|
|
752
|
+
}, H = async function() {
|
|
716
753
|
return typeof window > "u" ? !1 : "serial" in navigator && "forget" in SerialPort.prototype && this.__internal__.serial.port ? (await this.__internal__.serial.port.forget(), !0) : !1;
|
|
717
|
-
},
|
|
754
|
+
}, j = function() {
|
|
718
755
|
[
|
|
719
756
|
"serial:connected",
|
|
720
757
|
"serial:connecting",
|
|
@@ -734,21 +771,21 @@ n = new WeakSet(), y = function(e) {
|
|
|
734
771
|
].forEach((t) => {
|
|
735
772
|
this.serialRegisterAvailableListener(t);
|
|
736
773
|
});
|
|
737
|
-
},
|
|
774
|
+
}, W = function() {
|
|
738
775
|
const e = this;
|
|
739
776
|
this.on("internal:queue", async () => {
|
|
740
777
|
var t;
|
|
741
|
-
await
|
|
742
|
-
}),
|
|
743
|
-
},
|
|
778
|
+
await o(t = e, s, V).call(t);
|
|
779
|
+
}), o(this, s, Q).call(this);
|
|
780
|
+
}, Q = function() {
|
|
744
781
|
const e = this;
|
|
745
782
|
navigator.serial.addEventListener("connect", async () => {
|
|
746
783
|
e.isDisconnected && await e.serialConnect().catch(() => {
|
|
747
784
|
});
|
|
748
785
|
});
|
|
749
|
-
},
|
|
750
|
-
if (!
|
|
751
|
-
|
|
786
|
+
}, V = async function() {
|
|
787
|
+
if (!o(this, s, m).call(this, this.__internal__.serial.port)) {
|
|
788
|
+
o(this, s, C).call(this, { error: "Port is closed, not readable or writable." }), await this.serialConnect();
|
|
752
789
|
return;
|
|
753
790
|
}
|
|
754
791
|
if (this.__internal__.timeout.until_response || this.__internal__.serial.queue.length === 0) return;
|
|
@@ -756,7 +793,7 @@ n = new WeakSet(), y = function(e) {
|
|
|
756
793
|
let t = this.__internal__.time.response_general;
|
|
757
794
|
if (e.action === "connect" && (t = this.__internal__.time.response_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
|
|
758
795
|
await this.timeout(e.bytes, e.action);
|
|
759
|
-
}, t), this.__internal__.serial.last_action = e.action ?? "unknown", await
|
|
796
|
+
}, t), this.__internal__.serial.last_action = e.action ?? "unknown", await o(this, s, A).call(this, e.bytes), this.dispatch("serial:sent", {
|
|
760
797
|
action: e.action,
|
|
761
798
|
bytes: e.bytes
|
|
762
799
|
}), this.__internal__.auto_response) {
|
|
@@ -766,13 +803,13 @@ n = new WeakSet(), y = function(e) {
|
|
|
766
803
|
} catch (_) {
|
|
767
804
|
this.serialErrors(_);
|
|
768
805
|
}
|
|
769
|
-
|
|
806
|
+
o(this, s, f).call(this, r);
|
|
770
807
|
}
|
|
771
|
-
const
|
|
772
|
-
this.__internal__.serial.queue =
|
|
773
|
-
},
|
|
808
|
+
const n = [...this.__internal__.serial.queue];
|
|
809
|
+
this.__internal__.serial.queue = n.splice(1);
|
|
810
|
+
}, z = function(e = 1) {
|
|
774
811
|
this.__internal__.device_number = e, !this.__internal__.bypassSerialBytesConnection && (this.__internal__.serial.bytes_connection = this.serialSetConnectionConstant(e));
|
|
775
|
-
},
|
|
812
|
+
}, G = function() {
|
|
776
813
|
this.__internal__.last_error = {
|
|
777
814
|
message: null,
|
|
778
815
|
action: null,
|
|
@@ -781,7 +818,7 @@ n = new WeakSet(), y = function(e) {
|
|
|
781
818
|
};
|
|
782
819
|
};
|
|
783
820
|
export {
|
|
784
|
-
|
|
821
|
+
Z as Core,
|
|
785
822
|
h as Devices,
|
|
786
|
-
|
|
823
|
+
U as Dispatcher
|
|
787
824
|
};
|
|
@@ -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 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=`
|
|
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 Y=Object.defineProperty;var U=l=>{throw TypeError(l)};var Z=(l,_,c)=>_ in l?Y(l,_,{enumerable:!0,configurable:!0,writable:!0,value:c}):l[_]=c;var b=(l,_,c)=>Z(l,typeof _!="symbol"?_+"":_,c),L=(l,_,c)=>_.has(l)||U("Cannot "+c);var x=(l,_,c)=>(L(l,_,"read from private field"),c?c.call(l):_.get(l)),k=(l,_,c)=>_.has(l)?U("Cannot add the same private member more than once"):_ instanceof WeakSet?_.add(l):_.set(l,c),I=(l,_,c,h)=>(L(l,_,"write to private field"),h?h.call(l,c):_.set(l,c),c),o=(l,_,c)=>(L(l,_,"access private method"),c);var g,n,w,T,$,P,R,y,M,q,O,N,F,H,v,j,W,Q,V,z,G,J;class _ extends CustomEvent{constructor(s,e){super(s,e)}}class c extends EventTarget{constructor(){super(...arguments);b(this,"__listeners__",{debug:!1});b(this,"__debug__",!1);b(this,"__listenersCallbacks__",[])}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 r=this;setTimeout(()=>{r.dispatch(e,t)},i)}on(e,t){typeof this.__listeners__[e]<"u"&&!this.__listeners__[e]&&(this.__listeners__[e]=!0),this.__listenersCallbacks__.push({key:e,callback:t}),this.addEventListener(e,t)}off(e,t){this.__listenersCallbacks__=this.__listenersCallbacks__.filter(i=>!(i.key===e&&i.callback===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]}))}removeAllListeners(){for(const e of this.__listenersCallbacks__)["internal:queue"].includes(e.key)||(this.__listenersCallbacks__=this.__listenersCallbacks__.filter(t=>!(t.key===e.key&&t.callback===e.callback)),this.removeEventListener(e.key,e.callback));for(const e of Object.keys(this.__listeners__))this.__listeners__[e]=!1}}const a=class a extends c{constructor(){super(),["change"].forEach(e=>{this.serialRegisterAvailableListener(e)})}static $dispatchChange(s=null){s&&s.$checkAndDispatchConnection(),a.instance.dispatch("change",{devices:a.devices,dispatcher:s})}static typeError(s){const e=new Error;throw e.message=`Type ${s} is not supported`,e.name="DeviceTypeError",e}static registerType(s){typeof a.devices[s]>"u"&&(a.devices={...a.devices,[s]:{}})}static add(s){const e=s.typeDevice;typeof a.devices[e]>"u"&&a.registerType(e);const t=s.uuid;if(typeof a.devices[e]>"u"&&a.typeError(e),a.devices[e][t])throw new Error(`Device with id ${t} already exists`);return a.devices[e][t]=s,a.$dispatchChange(s),Object.keys(a.devices[e]).indexOf(t)}static get(s,e){return typeof a.devices[s]>"u"&&a.registerType(s),typeof a.devices[s]>"u"&&a.typeError(s),a.devices[s][e]}static getAll(s=null){return s===null?a.devices:(typeof a.devices[s]>"u"&&a.typeError(s),a.devices[s])}static getList(){return Object.values(a.devices).map(e=>Object.values(e)).flat()}static getByNumber(s,e){return typeof a.devices[s]>"u"&&a.typeError(s),Object.values(a.devices[s]).find(i=>i.deviceNumber===e)??null}static getCustom(s,e=1){return typeof a.devices[s]>"u"&&a.typeError(s),Object.values(a.devices[s]).find(i=>i.deviceNumber===e)??null}static async connectToAll(){const s=a.getList();for(const e of s)e.isConnected||await e.connect().catch(console.warn);return Promise.resolve(a.areAllConnected())}static async disconnectAll(){const s=a.getList();for(const e of s)e.isDisconnected||await e.disconnect().catch(console.warn);return Promise.resolve(a.areAllDisconnected())}static async areAllConnected(){const s=a.getList();for(const e of s)if(!e.isConnected)return Promise.resolve(!1);return Promise.resolve(!0)}static async areAllDisconnected(){const s=a.getList();for(const e of s)if(!e.isDisconnected)return Promise.resolve(!1);return Promise.resolve(!0)}static async getAllConnected(){const s=a.getList();return Promise.resolve(s.filter(e=>e.isConnected))}static async getAllDisconnected(){const s=a.getList();return Promise.resolve(s.filter(e=>e.isDisconnected))}};b(a,"instance"),b(a,"devices",{});let h=a;h.instance||(h.instance=new h);function D(S=100){return new Promise(s=>setTimeout(()=>s(),S))}function K(){return"serial"in navigator}const E={baudRate:9600,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"};class X extends c{constructor({filters:e=null,config_port:t=E,no_device:i=1,device_listen_on_channel:r=1,bypassSerialBytesConnection:u=!1}={filters:null,config_port:E,no_device:1,device_listen_on_channel:1,bypassSerialBytesConnection:!1}){super();k(this,n);b(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:E,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}});k(this,g,null);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&&o(this,n,G).call(this,i),r&&["number","string"].includes(typeof r)&&(this.listenOnChannel=r),o(this,n,W).call(this),o(this,n,Q).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=o(this,n,w).call(this,this.__internal__.serial.port);return e&&!t&&o(this,n,T).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=o(this,n,w).call(this,this.__internal__.serial.port);return!e&&t&&(this.dispatch("serial:connected"),o(this,n,v).call(this,!1),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(),o(this,n,T).call(this,e)}async connect(){return this.isConnected?!0:(this.__internal__.serial.aux_connecting="idle",new Promise((e,t)=>{K()||t("Web Serial not supported"),x(this,g)||I(this,g,o(this,n,$).bind(this)),this.on("internal:connecting",x(this,g));const i=setInterval(()=>{this.__internal__.serial.aux_connecting==="finished"?(clearInterval(i),this.__internal__.serial.aux_connecting="idle",x(this,g)!==null&&this.off("internal:connecting",x(this,g)),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("internal:connecting",{active:!0}),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(r=>this.serialErrors(r)),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{o(this,n,v).call(this,!0);const e=await o(this,n,M).call(this);if(e.length>0)await this.serialPortsSaved(e);else{const r=this.serialFilters;this.__internal__.serial.port=await navigator.serial.requestPort({filters:r})}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=r=>{var u;i.dispatch("serial:connected",r),o(u=i,n,v).call(u,!1),h.$dispatchChange(this),i.__internal__.serial.queue.length>0&&i.dispatch("internal:queue",{})},t.ondisconnect=async()=>{await i.disconnect()},await D(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 o(this,n,P).call(this,this.__internal__.serial.bytes_connection??[]),this.dispatch("serial:sent",{action:"connect",bytes:this.__internal__.serial.bytes_connection}),this.__internal__.auto_response&&o(this,n,y).call(this,this.__internal__.serial.auto_response),await o(this,n,H).call(this)}catch(e){o(this,n,v).call(this,!1),this.serialErrors(e)}}async serialForget(){return await o(this,n,j).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,r)=>{t[r]="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(){o(this,n,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=`
|
|
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(r=>r.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 r=i.replace("0x","");t.push(parseInt(r,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(r=>parseInt(r,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 r=0;r<t.length;r+=2)i+=String.fromCharCode(parseInt(t.substring(r,2),16));return i}asciiToHex(e){const t=[];for(let i=0,r=e.length;i<r;i++){const u=Number(e.charCodeAt(i)).toString(16);t.push(u)}return t.join("")}$checkAndDispatchConnection(){return this.isConnected}}g=new WeakMap,n=new WeakSet,w=function(e){return!!(e&&e.readable&&e.writable)},T=function(e=null){this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector=0,this.dispatch("serial:disconnected",e),h.$dispatchChange(this)},$=function(e){this.__internal__.serial.aux_connecting=e.detail.active?"connecting":"finished"},P=async function(e){const t=this.__internal__.serial.port;if(!t||t&&(!t.readable||!t.writable))throw o(this,n,T).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 o(this,n,R).call(this,t,5e3),t.writable===null)return;const r=t.writable.getWriter();await r.write(i),r.releaseLock()},R=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:r}=await e.getSignals();if(r)return;await D(100)}},y=function(e=new Uint8Array([]),t=!1){if(e&&e.length>0){const i=this.__internal__.serial.connected;if(this.__internal__.serial.connected=o(this,n,w).call(this,this.__internal__.serial.port),h.$dispatchChange(this),!i&&this.__internal__.serial.connected&&(this.dispatch("serial:connected"),o(this,n,v).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 r=this.parseUint8ArrayToString(e);if(this.__internal__.serial.response.limiter!==null){const u=r.split(this.__internal__.serial.response.limiter);for(const d in u)u[d]&&(t?this.serialCorruptMessage(u[d]):this.serialMessage(u[d]))}else t?this.serialCorruptMessage(r):this.serialMessage(r)}else{const r=this.stringToArrayBuffer(this.parseUint8ArrayToString(e));t?this.serialCorruptMessage(r):this.serialMessage(r)}}this.__internal__.serial.queue.length!==0&&this.dispatch("internal:queue",{})},M=async function(){const e=this.serialFilters,t=await navigator.serial.getPorts({filters:e});return e.length===0?t:t.filter(r=>{const u=r.getInfo();return e.some(d=>u.usbProductId===d.usbProductId&&u.usbVendorId===d.usbVendorId)}).filter(r=>!o(this,n,w).call(this,r))},q=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}},O=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&&o(this,n,y).call(this,this.__internal__.serial.response.buffer),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms||50)},N=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);o(this,n,y).call(this,i),t=t.slice(e)}this.__internal__.serial.response.buffer=t,t.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{o(this,n,y).call(this,this.__internal__.serial.response.buffer,!0)},this.__internal__.serial.free_timeout_ms||50))}},F=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 r=this.__internal__.serial.response.buffer;if(!e||!r||r.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 d=new TextDecoder().decode(r);const C=[];if(typeof e=="string"){let f;if(t&&i)f=new RegExp(`${e}([^${e}]+)${e}`,"g");else if(t)f=new RegExp(`${e}([^${e}]*)`,"g");else if(i)f=new RegExp(`([^${e}]+)${e}`,"g");else return;let m,p=0;for(;(m=f.exec(d))!==null;)C.push(new TextEncoder().encode(m[1])),p=f.lastIndex;d=d.slice(p)}else if(e instanceof RegExp){let f,m=0;if(t&&i){const p=new RegExp(`${e.source}(.*?)${e.source}`,"g");for(;(f=p.exec(d))!==null;)C.push(new TextEncoder().encode(f[1])),m=p.lastIndex}else if(i)for(;(f=e.exec(d))!==null;){const p=f.index,A=d.slice(m,p);C.push(new TextEncoder().encode(A)),m=e.lastIndex}else if(t){const p=d.split(e);p.shift();for(const A of p)C.push(new TextEncoder().encode(A));d=""}d=d.slice(m)}for(const f of C)o(this,n,y).call(this,f);const B=new TextEncoder().encode(d);this.__internal__.serial.response.buffer=B,B.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{o(this,n,y).call(this,this.__internal__.serial.response.buffer,!0),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms??50))},H=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:r}=await t.read();if(r)break;o(this,n,q).call(this,i),this.__internal__.serial.response.delimited?await o(this,n,F).call(this):this.__internal__.serial.response.length===null?await o(this,n,O).call(this):await o(this,n,N).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()}},v=function(e){e!==this.__internal__.serial.connecting&&(this.__internal__.serial.connecting=e,this.dispatch("serial:connecting",{active:e}),this.dispatch("internal:connecting",{active:e}))},j=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},W=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)})},Q=function(){const e=this;this.on("internal:queue",async()=>{var t;await o(t=e,n,z).call(t)}),o(this,n,V).call(this)},V=function(){const e=this;navigator.serial.addEventListener("connect",async()=>{e.isDisconnected&&await e.serialConnect().catch(()=>{})})},z=async function(){if(!o(this,n,w).call(this,this.__internal__.serial.port)){o(this,n,T).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 o(this,n,P).call(this,e.bytes),this.dispatch("serial:sent",{action:e.action,bytes:e.bytes}),this.__internal__.auto_response){let r=new Uint8Array(0);try{r=this.validateBytes(this.__internal__.serial.auto_response)}catch(u){this.serialErrors(u)}o(this,n,y).call(this,r)}const i=[...this.__internal__.serial.queue];this.__internal__.serial.queue=i.splice(1)},G=function(e=1){this.__internal__.device_number=e,!this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(e))},J=function(){this.__internal__.last_error={message:null,action:null,code:null,no_code:0}},l.Core=X,l.Devices=h,l.Dispatcher=c,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.11",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "danidoble",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"format": "prettier --write ./lib/**/*.ts"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@eslint/js": "^9.
|
|
48
|
+
"@eslint/js": "^9.30.0",
|
|
49
49
|
"@types/w3c-web-serial": "^1.0.8",
|
|
50
|
-
"eslint": "^9.
|
|
50
|
+
"eslint": "^9.30.0",
|
|
51
51
|
"globals": "^15.15.0",
|
|
52
52
|
"prettier": "3.4.2",
|
|
53
53
|
"typescript": "~5.7.3",
|