webserial-core 1.0.10 → 1.0.12
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 +1 -0
- package/dist/Core.d.ts.map +1 -1
- package/dist/Dispatcher.d.ts.map +1 -1
- package/dist/webserial-core.js +414 -403
- package/dist/webserial-core.umd.cjs +2 -2
- package/package.json +5 -5
package/dist/Core.d.ts
CHANGED
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,SAAS,EAAE,OAAO,CAAC;CACpB;AA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AAQ,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,33 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
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) || S("Cannot " + e);
|
|
7
|
-
var E = (l, s, e) => s.has(l) ? S("Cannot add the same private member more than once") : s instanceof WeakSet ? s.add(l) : s.set(l, e);
|
|
8
|
-
var o = (l, s, e) => (z(l, s, "access private method"), e);
|
|
9
|
-
class A extends CustomEvent {
|
|
10
|
-
constructor(s, e) {
|
|
11
|
-
super(s, e);
|
|
1
|
+
class p extends CustomEvent {
|
|
2
|
+
constructor(e, t) {
|
|
3
|
+
super(e, t);
|
|
12
4
|
}
|
|
13
5
|
}
|
|
14
|
-
class
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
g(this, "__debug__", !1);
|
|
21
|
-
g(this, "__listenersCallbacks__", []);
|
|
22
|
-
}
|
|
6
|
+
class y extends EventTarget {
|
|
7
|
+
__listeners__ = {
|
|
8
|
+
debug: !1
|
|
9
|
+
};
|
|
10
|
+
__debug__ = !1;
|
|
11
|
+
__listenersCallbacks__ = [];
|
|
23
12
|
dispatch(e, t = null) {
|
|
24
|
-
const i = new
|
|
25
|
-
this.dispatchEvent(i), this.__debug__ && this.dispatchEvent(new
|
|
13
|
+
const i = new p(e, { detail: t });
|
|
14
|
+
this.dispatchEvent(i), this.__debug__ && this.dispatchEvent(new p("debug", { detail: { type: e, data: t } }));
|
|
26
15
|
}
|
|
27
16
|
dispatchAsync(e, t = null, i = 100) {
|
|
28
|
-
const
|
|
17
|
+
const n = this;
|
|
29
18
|
setTimeout(() => {
|
|
30
|
-
|
|
19
|
+
n.dispatch(e, t);
|
|
31
20
|
}, i);
|
|
32
21
|
}
|
|
33
22
|
on(e, t) {
|
|
@@ -47,96 +36,95 @@ class k extends EventTarget {
|
|
|
47
36
|
}
|
|
48
37
|
removeAllListeners() {
|
|
49
38
|
for (const e of this.__listenersCallbacks__)
|
|
50
|
-
this.removeEventListener(e.key, e.callback);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
};
|
|
39
|
+
["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));
|
|
40
|
+
for (const e of Object.keys(this.__listeners__))
|
|
41
|
+
this.__listeners__[e] = !1;
|
|
54
42
|
}
|
|
55
43
|
}
|
|
56
|
-
|
|
44
|
+
class s extends y {
|
|
45
|
+
static instance;
|
|
46
|
+
static devices = {};
|
|
57
47
|
constructor() {
|
|
58
|
-
super(), ["change"].forEach((
|
|
59
|
-
this.serialRegisterAvailableListener(
|
|
48
|
+
super(), ["change"].forEach((t) => {
|
|
49
|
+
this.serialRegisterAvailableListener(t);
|
|
60
50
|
});
|
|
61
51
|
}
|
|
62
|
-
static $dispatchChange(
|
|
63
|
-
|
|
52
|
+
static $dispatchChange(e = null) {
|
|
53
|
+
e && e.$checkAndDispatchConnection(), s.instance.dispatch("change", { devices: s.devices, dispatcher: e });
|
|
64
54
|
}
|
|
65
|
-
static typeError(
|
|
66
|
-
const
|
|
67
|
-
throw
|
|
55
|
+
static typeError(e) {
|
|
56
|
+
const t = new Error();
|
|
57
|
+
throw t.message = `Type ${e} is not supported`, t.name = "DeviceTypeError", t;
|
|
68
58
|
}
|
|
69
|
-
static registerType(
|
|
70
|
-
typeof
|
|
59
|
+
static registerType(e) {
|
|
60
|
+
typeof s.devices[e] > "u" && (s.devices = { ...s.devices, [e]: {} });
|
|
71
61
|
}
|
|
72
|
-
static add(
|
|
73
|
-
const
|
|
74
|
-
typeof
|
|
75
|
-
const
|
|
76
|
-
if (typeof
|
|
77
|
-
throw new Error(`Device with id ${
|
|
78
|
-
return
|
|
62
|
+
static add(e) {
|
|
63
|
+
const t = e.typeDevice;
|
|
64
|
+
typeof s.devices[t] > "u" && s.registerType(t);
|
|
65
|
+
const i = e.uuid;
|
|
66
|
+
if (typeof s.devices[t] > "u" && s.typeError(t), s.devices[t][i])
|
|
67
|
+
throw new Error(`Device with id ${i} already exists`);
|
|
68
|
+
return s.devices[t][i] = e, s.$dispatchChange(e), Object.keys(s.devices[t]).indexOf(i);
|
|
79
69
|
}
|
|
80
|
-
static get(
|
|
81
|
-
return typeof
|
|
70
|
+
static get(e, t) {
|
|
71
|
+
return typeof s.devices[e] > "u" && s.registerType(e), typeof s.devices[e] > "u" && s.typeError(e), s.devices[e][t];
|
|
82
72
|
}
|
|
83
|
-
static getAll(
|
|
84
|
-
return
|
|
73
|
+
static getAll(e = null) {
|
|
74
|
+
return e === null ? s.devices : (typeof s.devices[e] > "u" && s.typeError(e), s.devices[e]);
|
|
85
75
|
}
|
|
86
76
|
static getList() {
|
|
87
|
-
return Object.values(
|
|
77
|
+
return Object.values(s.devices).map((t) => Object.values(t)).flat();
|
|
88
78
|
}
|
|
89
|
-
static getByNumber(
|
|
90
|
-
return typeof
|
|
79
|
+
static getByNumber(e, t) {
|
|
80
|
+
return typeof s.devices[e] > "u" && s.typeError(e), Object.values(s.devices[e]).find((n) => n.deviceNumber === t) ?? null;
|
|
91
81
|
}
|
|
92
|
-
static getCustom(
|
|
93
|
-
return typeof
|
|
82
|
+
static getCustom(e, t = 1) {
|
|
83
|
+
return typeof s.devices[e] > "u" && s.typeError(e), Object.values(s.devices[e]).find((n) => n.deviceNumber === t) ?? null;
|
|
94
84
|
}
|
|
95
85
|
static async connectToAll() {
|
|
96
|
-
const
|
|
97
|
-
for (const
|
|
98
|
-
|
|
99
|
-
return Promise.resolve(
|
|
86
|
+
const e = s.getList();
|
|
87
|
+
for (const t of e)
|
|
88
|
+
t.isConnected || await t.connect().catch(console.warn);
|
|
89
|
+
return Promise.resolve(s.areAllConnected());
|
|
100
90
|
}
|
|
101
91
|
static async disconnectAll() {
|
|
102
|
-
const
|
|
103
|
-
for (const
|
|
104
|
-
|
|
105
|
-
return Promise.resolve(
|
|
92
|
+
const e = s.getList();
|
|
93
|
+
for (const t of e)
|
|
94
|
+
t.isDisconnected || await t.disconnect().catch(console.warn);
|
|
95
|
+
return Promise.resolve(s.areAllDisconnected());
|
|
106
96
|
}
|
|
107
97
|
static async areAllConnected() {
|
|
108
|
-
const
|
|
109
|
-
for (const
|
|
110
|
-
if (!
|
|
98
|
+
const e = s.getList();
|
|
99
|
+
for (const t of e)
|
|
100
|
+
if (!t.isConnected) return Promise.resolve(!1);
|
|
111
101
|
return Promise.resolve(!0);
|
|
112
102
|
}
|
|
113
103
|
static async areAllDisconnected() {
|
|
114
|
-
const
|
|
115
|
-
for (const
|
|
116
|
-
if (!
|
|
104
|
+
const e = s.getList();
|
|
105
|
+
for (const t of e)
|
|
106
|
+
if (!t.isDisconnected) return Promise.resolve(!1);
|
|
117
107
|
return Promise.resolve(!0);
|
|
118
108
|
}
|
|
119
109
|
static async getAllConnected() {
|
|
120
|
-
const
|
|
121
|
-
return Promise.resolve(
|
|
110
|
+
const e = s.getList();
|
|
111
|
+
return Promise.resolve(e.filter((t) => t.isConnected));
|
|
122
112
|
}
|
|
123
113
|
static async getAllDisconnected() {
|
|
124
|
-
const
|
|
125
|
-
return Promise.resolve(
|
|
114
|
+
const e = s.getList();
|
|
115
|
+
return Promise.resolve(e.filter((t) => t.isDisconnected));
|
|
126
116
|
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
h.instance || (h.instance = new h());
|
|
131
|
-
function L(l = 100) {
|
|
117
|
+
}
|
|
118
|
+
s.instance || (s.instance = new s());
|
|
119
|
+
function g(h = 100) {
|
|
132
120
|
return new Promise(
|
|
133
|
-
(
|
|
121
|
+
(e) => setTimeout(() => e(), h)
|
|
134
122
|
);
|
|
135
123
|
}
|
|
136
|
-
function
|
|
124
|
+
function m() {
|
|
137
125
|
return "serial" in navigator;
|
|
138
126
|
}
|
|
139
|
-
const
|
|
127
|
+
const d = {
|
|
140
128
|
baudRate: 9600,
|
|
141
129
|
dataBits: 8,
|
|
142
130
|
stopBits: 1,
|
|
@@ -144,87 +132,86 @@ const C = {
|
|
|
144
132
|
bufferSize: 32768,
|
|
145
133
|
flowControl: "none"
|
|
146
134
|
};
|
|
147
|
-
|
|
148
|
-
|
|
135
|
+
class b extends y {
|
|
136
|
+
__internal__ = {
|
|
137
|
+
bypassSerialBytesConnection: !1,
|
|
138
|
+
auto_response: !1,
|
|
139
|
+
device_number: 1,
|
|
140
|
+
aux_port_connector: 0,
|
|
141
|
+
last_error: {
|
|
142
|
+
message: null,
|
|
143
|
+
action: null,
|
|
144
|
+
code: null,
|
|
145
|
+
no_code: 0
|
|
146
|
+
},
|
|
147
|
+
serial: {
|
|
148
|
+
aux_connecting: "idle",
|
|
149
|
+
connecting: !1,
|
|
150
|
+
connected: !1,
|
|
151
|
+
port: null,
|
|
152
|
+
last_action: null,
|
|
153
|
+
response: {
|
|
154
|
+
length: null,
|
|
155
|
+
buffer: new Uint8Array([]),
|
|
156
|
+
as: "uint8",
|
|
157
|
+
replacer: /[\n\r]+/g,
|
|
158
|
+
limiter: null,
|
|
159
|
+
prefixLimiter: !1,
|
|
160
|
+
sufixLimiter: !0,
|
|
161
|
+
delimited: !1
|
|
162
|
+
},
|
|
163
|
+
reader: null,
|
|
164
|
+
input_done: null,
|
|
165
|
+
output_done: null,
|
|
166
|
+
input_stream: null,
|
|
167
|
+
output_stream: null,
|
|
168
|
+
keep_reading: !0,
|
|
169
|
+
time_until_send_bytes: void 0,
|
|
170
|
+
delay_first_connection: 200,
|
|
171
|
+
bytes_connection: null,
|
|
172
|
+
filters: [],
|
|
173
|
+
config_port: d,
|
|
174
|
+
queue: [],
|
|
175
|
+
running_queue: !1,
|
|
176
|
+
auto_response: ["DD", "DD"],
|
|
177
|
+
free_timeout_ms: 50,
|
|
178
|
+
// In previous versions 400 was used
|
|
179
|
+
useRTSCTS: !1
|
|
180
|
+
// Use RTS/CTS flow control
|
|
181
|
+
},
|
|
182
|
+
device: {
|
|
183
|
+
type: "unknown",
|
|
184
|
+
id: window.crypto.randomUUID(),
|
|
185
|
+
listen_on_port: null
|
|
186
|
+
},
|
|
187
|
+
time: {
|
|
188
|
+
response_connection: 500,
|
|
189
|
+
response_general: 2e3
|
|
190
|
+
},
|
|
191
|
+
timeout: {
|
|
192
|
+
until_response: 0
|
|
193
|
+
},
|
|
194
|
+
interval: {
|
|
195
|
+
reconnection: 0
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
#t = null;
|
|
149
199
|
constructor({
|
|
150
200
|
filters: e = null,
|
|
151
|
-
config_port: t =
|
|
201
|
+
config_port: t = d,
|
|
152
202
|
no_device: i = 1,
|
|
153
|
-
device_listen_on_channel:
|
|
154
|
-
bypassSerialBytesConnection:
|
|
203
|
+
device_listen_on_channel: n = 1,
|
|
204
|
+
bypassSerialBytesConnection: a = !1
|
|
155
205
|
} = {
|
|
156
206
|
filters: null,
|
|
157
|
-
config_port:
|
|
207
|
+
config_port: d,
|
|
158
208
|
no_device: 1,
|
|
159
209
|
device_listen_on_channel: 1,
|
|
160
210
|
bypassSerialBytesConnection: !1
|
|
161
211
|
}) {
|
|
162
|
-
super()
|
|
163
|
-
E(this, n);
|
|
164
|
-
g(this, "__internal__", {
|
|
165
|
-
bypassSerialBytesConnection: !1,
|
|
166
|
-
auto_response: !1,
|
|
167
|
-
device_number: 1,
|
|
168
|
-
aux_port_connector: 0,
|
|
169
|
-
last_error: {
|
|
170
|
-
message: null,
|
|
171
|
-
action: null,
|
|
172
|
-
code: null,
|
|
173
|
-
no_code: 0
|
|
174
|
-
},
|
|
175
|
-
serial: {
|
|
176
|
-
aux_connecting: "idle",
|
|
177
|
-
connecting: !1,
|
|
178
|
-
connected: !1,
|
|
179
|
-
port: null,
|
|
180
|
-
last_action: null,
|
|
181
|
-
response: {
|
|
182
|
-
length: null,
|
|
183
|
-
buffer: new Uint8Array([]),
|
|
184
|
-
as: "uint8",
|
|
185
|
-
replacer: /[\n\r]+/g,
|
|
186
|
-
limiter: null,
|
|
187
|
-
prefixLimiter: !1,
|
|
188
|
-
sufixLimiter: !0,
|
|
189
|
-
delimited: !1
|
|
190
|
-
},
|
|
191
|
-
reader: null,
|
|
192
|
-
input_done: null,
|
|
193
|
-
output_done: null,
|
|
194
|
-
input_stream: null,
|
|
195
|
-
output_stream: null,
|
|
196
|
-
keep_reading: !0,
|
|
197
|
-
time_until_send_bytes: void 0,
|
|
198
|
-
delay_first_connection: 200,
|
|
199
|
-
bytes_connection: null,
|
|
200
|
-
filters: [],
|
|
201
|
-
config_port: C,
|
|
202
|
-
queue: [],
|
|
203
|
-
auto_response: ["DD", "DD"],
|
|
204
|
-
free_timeout_ms: 50,
|
|
205
|
-
// In previous versions 400 was used
|
|
206
|
-
useRTSCTS: !1
|
|
207
|
-
// Use RTS/CTS flow control
|
|
208
|
-
},
|
|
209
|
-
device: {
|
|
210
|
-
type: "unknown",
|
|
211
|
-
id: window.crypto.randomUUID(),
|
|
212
|
-
listen_on_port: null
|
|
213
|
-
},
|
|
214
|
-
time: {
|
|
215
|
-
response_connection: 500,
|
|
216
|
-
response_general: 2e3
|
|
217
|
-
},
|
|
218
|
-
timeout: {
|
|
219
|
-
until_response: 0
|
|
220
|
-
},
|
|
221
|
-
interval: {
|
|
222
|
-
reconnection: 0
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
if (!("serial" in navigator))
|
|
212
|
+
if (super(), !("serial" in navigator))
|
|
226
213
|
throw new Error("Web Serial not supported");
|
|
227
|
-
e && (this.serialFilters = e), t && (this.serialConfigPort = t),
|
|
214
|
+
e && (this.serialFilters = e), t && (this.serialConfigPort = t), a && (this.__internal__.bypassSerialBytesConnection = a), i && this.#b(i), n && ["number", "string"].includes(typeof n) && (this.listenOnChannel = n), this.#p(), this.#g();
|
|
228
215
|
}
|
|
229
216
|
set listenOnChannel(e) {
|
|
230
217
|
if (typeof e == "string" && (e = parseInt(e)), isNaN(e) || e < 1 || e > 255)
|
|
@@ -258,15 +245,15 @@ class K extends k {
|
|
|
258
245
|
this.__internal__.serial.useRTSCTS = e;
|
|
259
246
|
}
|
|
260
247
|
get isConnected() {
|
|
261
|
-
const e = this.__internal__.serial.connected, t =
|
|
262
|
-
return e && !t &&
|
|
248
|
+
const e = this.__internal__.serial.connected, t = this.#i(this.__internal__.serial.port);
|
|
249
|
+
return e && !t && this.#s({ error: "Port is closed, not readable or writable." }), this.__internal__.serial.connected = t, this.__internal__.serial.connected;
|
|
263
250
|
}
|
|
264
251
|
get isConnecting() {
|
|
265
252
|
return this.__internal__.serial.connecting;
|
|
266
253
|
}
|
|
267
254
|
get isDisconnected() {
|
|
268
|
-
const e = this.__internal__.serial.connected, t =
|
|
269
|
-
return !e && t && (this.dispatch("serial:connected"),
|
|
255
|
+
const e = this.__internal__.serial.connected, t = this.#i(this.__internal__.serial.port);
|
|
256
|
+
return !e && t && (this.dispatch("serial:connected"), this.#n(!1), s.$dispatchChange(this)), this.__internal__.serial.connected = t, !this.__internal__.serial.connected;
|
|
270
257
|
}
|
|
271
258
|
get deviceNumber() {
|
|
272
259
|
return this.__internal__.device_number;
|
|
@@ -336,23 +323,30 @@ class K extends k {
|
|
|
336
323
|
throw new Error("bypassSerialBytesConnection must be a boolean");
|
|
337
324
|
this.__internal__.bypassSerialBytesConnection = e;
|
|
338
325
|
}
|
|
326
|
+
#i(e) {
|
|
327
|
+
return !!(e && e.readable && e.writable);
|
|
328
|
+
}
|
|
339
329
|
async timeout(e, t) {
|
|
340
|
-
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", {}),
|
|
330
|
+
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", {}), s.$dispatchChange(this)) : t === "connection:start" && (await this.serialDisconnect(), this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector += 1, s.$dispatchChange(this), await this.serialConnect()), this.__internal__.serial.queue.length > 0 && this.dispatch("internal:queue", {}), this.dispatch("serial:timeout", {
|
|
341
331
|
...this.__internal__.last_error,
|
|
342
332
|
bytes: e,
|
|
343
333
|
action: t
|
|
344
334
|
});
|
|
345
335
|
}
|
|
346
336
|
async disconnect(e = null) {
|
|
347
|
-
await this.serialDisconnect(),
|
|
337
|
+
await this.serialDisconnect(), this.#s(e);
|
|
338
|
+
}
|
|
339
|
+
#s(e = null) {
|
|
340
|
+
this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector = 0, this.dispatch("serial:disconnected", e), s.$dispatchChange(this);
|
|
341
|
+
}
|
|
342
|
+
#a(e) {
|
|
343
|
+
this.__internal__.serial.aux_connecting = e.detail.active ? "connecting" : "finished";
|
|
348
344
|
}
|
|
349
345
|
async connect() {
|
|
350
346
|
return this.isConnected ? !0 : (this.__internal__.serial.aux_connecting = "idle", new Promise((e, t) => {
|
|
351
|
-
|
|
352
|
-
const i =
|
|
353
|
-
|
|
354
|
-
const r = setInterval(() => {
|
|
355
|
-
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 }));
|
|
347
|
+
m() || t("Web Serial not supported"), this.#t || (this.#t = this.#a.bind(this)), this.on("internal:connecting", this.#t);
|
|
348
|
+
const i = setInterval(() => {
|
|
349
|
+
this.__internal__.serial.aux_connecting === "finished" ? (clearInterval(i), this.__internal__.serial.aux_connecting = "idle", this.#t !== null && this.off("internal:connecting", this.#t), 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 }));
|
|
356
350
|
}, 100);
|
|
357
351
|
this.serialConnect();
|
|
358
352
|
}));
|
|
@@ -360,12 +354,57 @@ class K extends k {
|
|
|
360
354
|
async serialDisconnect() {
|
|
361
355
|
try {
|
|
362
356
|
const e = this.__internal__.serial.reader, t = this.__internal__.serial.output_stream;
|
|
363
|
-
e && (await e.cancel().catch((
|
|
357
|
+
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();
|
|
364
358
|
} catch (e) {
|
|
365
359
|
this.serialErrors(e);
|
|
366
360
|
} finally {
|
|
367
|
-
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,
|
|
361
|
+
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, s.$dispatchChange(this);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
async #r(e) {
|
|
365
|
+
const t = this.__internal__.serial.port;
|
|
366
|
+
if (!t || t && (!t.readable || !t.writable))
|
|
367
|
+
throw this.#s({ error: "Port is closed, not readable or writable." }), new Error("The port is closed or is not readable/writable");
|
|
368
|
+
const i = this.validateBytes(e);
|
|
369
|
+
if (this.useRTSCTS && await this.#l(t, 5e3), t.writable === null) return;
|
|
370
|
+
const n = t.writable.getWriter();
|
|
371
|
+
await n.write(i), n.releaseLock();
|
|
372
|
+
}
|
|
373
|
+
async #l(e, t = 5e3) {
|
|
374
|
+
const i = Date.now();
|
|
375
|
+
for (; ; ) {
|
|
376
|
+
if (Date.now() - i > t)
|
|
377
|
+
throw new Error("Timeout waiting for clearToSend signal");
|
|
378
|
+
const { clearToSend: n } = await e.getSignals();
|
|
379
|
+
if (n) return;
|
|
380
|
+
await g(100);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
#e(e = new Uint8Array([]), t = !1) {
|
|
384
|
+
if (e && e.length > 0) {
|
|
385
|
+
const i = this.__internal__.serial.connected;
|
|
386
|
+
if (this.__internal__.serial.connected = this.#i(this.__internal__.serial.port), s.$dispatchChange(this), !i && this.__internal__.serial.connected && (this.dispatch("serial:connected"), this.#n(!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")
|
|
387
|
+
t ? this.serialCorruptMessage(this.parseUint8ToHex(e)) : this.serialMessage(this.parseUint8ToHex(e));
|
|
388
|
+
else if (this.__internal__.serial.response.as === "uint8")
|
|
389
|
+
t ? this.serialCorruptMessage(e) : this.serialMessage(e);
|
|
390
|
+
else if (this.__internal__.serial.response.as === "string") {
|
|
391
|
+
const n = this.parseUint8ArrayToString(e);
|
|
392
|
+
if (this.__internal__.serial.response.limiter !== null) {
|
|
393
|
+
const a = n.split(this.__internal__.serial.response.limiter);
|
|
394
|
+
for (const r in a)
|
|
395
|
+
a[r] && (t ? this.serialCorruptMessage(a[r]) : this.serialMessage(a[r]));
|
|
396
|
+
} else
|
|
397
|
+
t ? this.serialCorruptMessage(n) : this.serialMessage(n);
|
|
398
|
+
} else {
|
|
399
|
+
const n = this.stringToArrayBuffer(this.parseUint8ArrayToString(e));
|
|
400
|
+
t ? this.serialCorruptMessage(n) : this.serialMessage(n);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
if (this.__internal__.serial.queue.length === 0) {
|
|
404
|
+
this.__internal__.serial.running_queue = !1;
|
|
405
|
+
return;
|
|
368
406
|
}
|
|
407
|
+
this.dispatch("internal:queue", {});
|
|
369
408
|
}
|
|
370
409
|
getResponseAsArrayBuffer() {
|
|
371
410
|
this.__internal__.serial.response.as = "arraybuffer";
|
|
@@ -379,6 +418,13 @@ class K extends k {
|
|
|
379
418
|
getResponseAsString() {
|
|
380
419
|
this.__internal__.serial.response.as = "string";
|
|
381
420
|
}
|
|
421
|
+
async #o() {
|
|
422
|
+
const e = this.serialFilters, t = await navigator.serial.getPorts({ filters: e });
|
|
423
|
+
return e.length === 0 ? t : t.filter((n) => {
|
|
424
|
+
const a = n.getInfo();
|
|
425
|
+
return e.some((r) => a.usbProductId === r.usbProductId && a.usbVendorId === r.usbVendorId);
|
|
426
|
+
}).filter((n) => !this.#i(n));
|
|
427
|
+
}
|
|
382
428
|
async serialPortsSaved(e) {
|
|
383
429
|
const t = this.serialFilters;
|
|
384
430
|
if (this.__internal__.aux_port_connector < e.length) {
|
|
@@ -404,7 +450,7 @@ class K extends k {
|
|
|
404
450
|
case t.includes(
|
|
405
451
|
"this readable stream reader has been released and cannot be used to cancel its previous owner stream"
|
|
406
452
|
):
|
|
407
|
-
this.dispatch("serial:need-permission", {}),
|
|
453
|
+
this.dispatch("serial:need-permission", {}), s.$dispatchChange(this);
|
|
408
454
|
break;
|
|
409
455
|
case t.includes("the port is already open."):
|
|
410
456
|
case t.includes("failed to open serial port"):
|
|
@@ -427,7 +473,7 @@ class K extends k {
|
|
|
427
473
|
case t.includes("the port is already closed."):
|
|
428
474
|
break;
|
|
429
475
|
case t.includes("the device has been lost"):
|
|
430
|
-
this.dispatch("serial:lost", {}),
|
|
476
|
+
this.dispatch("serial:lost", {}), s.$dispatchChange(this);
|
|
431
477
|
break;
|
|
432
478
|
case t.includes("navigator.serial is undefined"):
|
|
433
479
|
this.dispatch("serial:unsupported", {});
|
|
@@ -438,16 +484,114 @@ class K extends k {
|
|
|
438
484
|
}
|
|
439
485
|
this.dispatch("serial:error", e);
|
|
440
486
|
}
|
|
487
|
+
#_(e) {
|
|
488
|
+
if (e) {
|
|
489
|
+
const t = this.__internal__.serial.response.buffer, i = new Uint8Array(t.length + e.byteLength);
|
|
490
|
+
i.set(t, 0), i.set(new Uint8Array(e), t.length), this.__internal__.serial.response.buffer = i;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
async #c() {
|
|
494
|
+
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(() => {
|
|
495
|
+
this.__internal__.serial.response.buffer && this.#e(this.__internal__.serial.response.buffer), this.__internal__.serial.response.buffer = new Uint8Array(0);
|
|
496
|
+
}, this.__internal__.serial.free_timeout_ms || 50);
|
|
497
|
+
}
|
|
498
|
+
async #h() {
|
|
499
|
+
const e = this.__internal__.serial.response.length;
|
|
500
|
+
let t = this.__internal__.serial.response.buffer;
|
|
501
|
+
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)) {
|
|
502
|
+
for (; t.length >= e; ) {
|
|
503
|
+
const i = t.slice(0, e);
|
|
504
|
+
this.#e(i), t = t.slice(e);
|
|
505
|
+
}
|
|
506
|
+
this.__internal__.serial.response.buffer = t, t.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
507
|
+
this.#e(this.__internal__.serial.response.buffer, !0);
|
|
508
|
+
}, this.__internal__.serial.free_timeout_ms || 50));
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
async #u() {
|
|
512
|
+
const {
|
|
513
|
+
limiter: e,
|
|
514
|
+
prefixLimiter: t = !1,
|
|
515
|
+
sufixLimiter: i = !0
|
|
516
|
+
} = this.__internal__.serial.response;
|
|
517
|
+
if (!e)
|
|
518
|
+
throw new Error("No limiter defined for delimited serial response");
|
|
519
|
+
const n = this.__internal__.serial.response.buffer;
|
|
520
|
+
if (!e || !n || n.length === 0) return;
|
|
521
|
+
this.__internal__.serial.time_until_send_bytes && (clearTimeout(this.__internal__.serial.time_until_send_bytes), this.__internal__.serial.time_until_send_bytes = 0);
|
|
522
|
+
let r = new TextDecoder().decode(n);
|
|
523
|
+
const c = [];
|
|
524
|
+
if (typeof e == "string") {
|
|
525
|
+
let l;
|
|
526
|
+
if (t && i)
|
|
527
|
+
l = new RegExp(`${e}([^${e}]+)${e}`, "g");
|
|
528
|
+
else if (t)
|
|
529
|
+
l = new RegExp(`${e}([^${e}]*)`, "g");
|
|
530
|
+
else if (i)
|
|
531
|
+
l = new RegExp(`([^${e}]+)${e}`, "g");
|
|
532
|
+
else
|
|
533
|
+
return;
|
|
534
|
+
let _, o = 0;
|
|
535
|
+
for (; (_ = l.exec(r)) !== null; )
|
|
536
|
+
c.push(new TextEncoder().encode(_[1])), o = l.lastIndex;
|
|
537
|
+
r = r.slice(o);
|
|
538
|
+
} else if (e instanceof RegExp) {
|
|
539
|
+
let l, _ = 0;
|
|
540
|
+
if (t && i) {
|
|
541
|
+
const o = new RegExp(`${e.source}(.*?)${e.source}`, "g");
|
|
542
|
+
for (; (l = o.exec(r)) !== null; )
|
|
543
|
+
c.push(new TextEncoder().encode(l[1])), _ = o.lastIndex;
|
|
544
|
+
} else if (i)
|
|
545
|
+
for (; (l = e.exec(r)) !== null; ) {
|
|
546
|
+
const o = l.index, u = r.slice(_, o);
|
|
547
|
+
c.push(new TextEncoder().encode(u)), _ = e.lastIndex;
|
|
548
|
+
}
|
|
549
|
+
else if (t) {
|
|
550
|
+
const o = r.split(e);
|
|
551
|
+
o.shift();
|
|
552
|
+
for (const u of o)
|
|
553
|
+
c.push(new TextEncoder().encode(u));
|
|
554
|
+
r = "";
|
|
555
|
+
}
|
|
556
|
+
r = r.slice(_);
|
|
557
|
+
}
|
|
558
|
+
for (const l of c)
|
|
559
|
+
this.#e(l);
|
|
560
|
+
const f = new TextEncoder().encode(r);
|
|
561
|
+
this.__internal__.serial.response.buffer = f, f.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
562
|
+
this.#e(this.__internal__.serial.response.buffer, !0), this.__internal__.serial.response.buffer = new Uint8Array(0);
|
|
563
|
+
}, this.__internal__.serial.free_timeout_ms ?? 50));
|
|
564
|
+
}
|
|
565
|
+
async #d() {
|
|
566
|
+
const e = this.__internal__.serial.port;
|
|
567
|
+
if (!e || !e.readable) throw new Error("Port is not readable");
|
|
568
|
+
const t = e.readable.getReader();
|
|
569
|
+
this.__internal__.serial.reader = t;
|
|
570
|
+
try {
|
|
571
|
+
for (; this.__internal__.serial.keep_reading; ) {
|
|
572
|
+
const { value: i, done: n } = await t.read();
|
|
573
|
+
if (n) break;
|
|
574
|
+
this.#_(i), this.__internal__.serial.response.delimited ? await this.#u() : this.__internal__.serial.response.length === null ? await this.#c() : await this.#h();
|
|
575
|
+
}
|
|
576
|
+
} catch (i) {
|
|
577
|
+
this.serialErrors(i);
|
|
578
|
+
} finally {
|
|
579
|
+
t.releaseLock(), this.__internal__.serial.keep_reading = !0, this.__internal__.serial.port && await this.__internal__.serial.port.close();
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
#n(e) {
|
|
583
|
+
e !== this.__internal__.serial.connecting && (this.__internal__.serial.connecting = e, this.dispatch("serial:connecting", { active: e }), this.dispatch("internal:connecting", { active: e }));
|
|
584
|
+
}
|
|
441
585
|
async serialConnect() {
|
|
442
586
|
try {
|
|
443
|
-
|
|
444
|
-
const e = await o(
|
|
587
|
+
this.#n(!0);
|
|
588
|
+
const e = await this.#o();
|
|
445
589
|
if (e.length > 0)
|
|
446
590
|
await this.serialPortsSaved(e);
|
|
447
591
|
else {
|
|
448
|
-
const
|
|
592
|
+
const n = this.serialFilters;
|
|
449
593
|
this.__internal__.serial.port = await navigator.serial.requestPort({
|
|
450
|
-
filters:
|
|
594
|
+
filters: n
|
|
451
595
|
});
|
|
452
596
|
}
|
|
453
597
|
const t = this.__internal__.serial.port;
|
|
@@ -455,23 +599,25 @@ class K extends k {
|
|
|
455
599
|
throw new Error("No port selected by the user");
|
|
456
600
|
await t.open(this.serialConfigPort);
|
|
457
601
|
const i = this;
|
|
458
|
-
t.onconnect = (
|
|
459
|
-
|
|
460
|
-
i.dispatch("serial:connected", r), o(_ = i, n, m).call(_, !1), h.$dispatchChange(this), i.__internal__.serial.queue.length > 0 && i.dispatch("internal:queue", {});
|
|
602
|
+
t.onconnect = (n) => {
|
|
603
|
+
i.dispatch("serial:connected", n), i.#n(!1), s.$dispatchChange(this), i.__internal__.serial.queue.length > 0 ? i.dispatch("internal:queue", {}) : i.__internal__.serial.running_queue = !1;
|
|
461
604
|
}, t.ondisconnect = async () => {
|
|
462
605
|
await i.disconnect();
|
|
463
|
-
}, await
|
|
606
|
+
}, await g(this.__internal__.serial.delay_first_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
|
|
464
607
|
await i.timeout(i.__internal__.serial.bytes_connection ?? [], "connection:start");
|
|
465
|
-
}, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await
|
|
608
|
+
}, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await this.#r(this.__internal__.serial.bytes_connection ?? []), this.dispatch("serial:sent", {
|
|
466
609
|
action: "connect",
|
|
467
610
|
bytes: this.__internal__.serial.bytes_connection
|
|
468
|
-
}), this.__internal__.auto_response &&
|
|
611
|
+
}), this.__internal__.auto_response && this.#e(this.__internal__.serial.auto_response), await this.#d();
|
|
469
612
|
} catch (e) {
|
|
470
|
-
|
|
613
|
+
this.#n(!1), this.serialErrors(e);
|
|
471
614
|
}
|
|
472
615
|
}
|
|
616
|
+
async #f() {
|
|
617
|
+
return typeof window > "u" ? !1 : "serial" in navigator && "forget" in SerialPort.prototype && this.__internal__.serial.port ? (await this.__internal__.serial.port.forget(), !0) : !1;
|
|
618
|
+
}
|
|
473
619
|
async serialForget() {
|
|
474
|
-
return await
|
|
620
|
+
return await this.#f();
|
|
475
621
|
}
|
|
476
622
|
decToHex(e) {
|
|
477
623
|
return typeof e == "string" && (e = parseInt(e, 10)), e.toString(16);
|
|
@@ -484,13 +630,77 @@ class K extends k {
|
|
|
484
630
|
}
|
|
485
631
|
add0x(e) {
|
|
486
632
|
const t = [];
|
|
487
|
-
return e.forEach((i,
|
|
488
|
-
t[
|
|
633
|
+
return e.forEach((i, n) => {
|
|
634
|
+
t[n] = "0x" + i;
|
|
489
635
|
}), t;
|
|
490
636
|
}
|
|
491
637
|
bytesToHex(e) {
|
|
492
638
|
return this.add0x(Array.from(e, (t) => this.hexMaker(t)));
|
|
493
639
|
}
|
|
640
|
+
#p() {
|
|
641
|
+
[
|
|
642
|
+
"serial:connected",
|
|
643
|
+
"serial:connecting",
|
|
644
|
+
"serial:reconnect",
|
|
645
|
+
"serial:timeout",
|
|
646
|
+
"serial:disconnected",
|
|
647
|
+
"serial:sent",
|
|
648
|
+
"serial:soft-reload",
|
|
649
|
+
"serial:message",
|
|
650
|
+
"serial:corrupt-message",
|
|
651
|
+
"unknown",
|
|
652
|
+
"serial:need-permission",
|
|
653
|
+
"serial:lost",
|
|
654
|
+
"serial:unsupported",
|
|
655
|
+
"serial:error",
|
|
656
|
+
"debug"
|
|
657
|
+
].forEach((t) => {
|
|
658
|
+
this.serialRegisterAvailableListener(t);
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
#g() {
|
|
662
|
+
const e = this;
|
|
663
|
+
this.on("internal:queue", async () => {
|
|
664
|
+
await e.#m();
|
|
665
|
+
}), this.#y();
|
|
666
|
+
}
|
|
667
|
+
#y() {
|
|
668
|
+
const e = this;
|
|
669
|
+
navigator.serial.addEventListener("connect", async () => {
|
|
670
|
+
e.isDisconnected && await e.serialConnect().catch(() => {
|
|
671
|
+
});
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
async #m() {
|
|
675
|
+
if (!this.#i(this.__internal__.serial.port)) {
|
|
676
|
+
this.#s({ error: "Port is closed, not readable or writable." }), await this.serialConnect();
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
if (this.__internal__.timeout.until_response) return;
|
|
680
|
+
if (this.__internal__.serial.queue.length === 0) {
|
|
681
|
+
this.__internal__.serial.running_queue = !1;
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
this.__internal__.serial.running_queue = !0;
|
|
685
|
+
const e = this.__internal__.serial.queue[0];
|
|
686
|
+
let t = this.__internal__.time.response_general;
|
|
687
|
+
if (e.action === "connect" && (t = this.__internal__.time.response_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
|
|
688
|
+
await this.timeout(e.bytes, e.action);
|
|
689
|
+
}, t), this.__internal__.serial.last_action = e.action ?? "unknown", await this.#r(e.bytes), this.dispatch("serial:sent", {
|
|
690
|
+
action: e.action,
|
|
691
|
+
bytes: e.bytes
|
|
692
|
+
}), this.__internal__.auto_response) {
|
|
693
|
+
let n = new Uint8Array(0);
|
|
694
|
+
try {
|
|
695
|
+
n = this.validateBytes(this.__internal__.serial.auto_response);
|
|
696
|
+
} catch (a) {
|
|
697
|
+
this.serialErrors(a);
|
|
698
|
+
}
|
|
699
|
+
this.#e(n);
|
|
700
|
+
}
|
|
701
|
+
const i = [...this.__internal__.serial.queue];
|
|
702
|
+
this.__internal__.serial.queue = i.splice(1), this.__internal__.serial.queue.length > 0 && (this.__internal__.serial.running_queue = !0);
|
|
703
|
+
}
|
|
494
704
|
validateBytes(e) {
|
|
495
705
|
let t = new Uint8Array(0);
|
|
496
706
|
if (e instanceof Uint8Array)
|
|
@@ -514,6 +724,9 @@ class K extends k {
|
|
|
514
724
|
}
|
|
515
725
|
this.__internal__.serial.queue.push({ bytes: i, action: t }), this.dispatch("internal:queue", {});
|
|
516
726
|
}
|
|
727
|
+
#b(e = 1) {
|
|
728
|
+
this.__internal__.device_number = e, !this.__internal__.bypassSerialBytesConnection && (this.__internal__.serial.bytes_connection = this.serialSetConnectionConstant(e));
|
|
729
|
+
}
|
|
517
730
|
serialSetConnectionConstant(e = 1) {
|
|
518
731
|
if (this.__internal__.bypassSerialBytesConnection) return this.__internal__.serial.bytes_connection;
|
|
519
732
|
throw new Error(`Method not implemented 'serialSetConnectionConstant' to listen on channel ${e}`);
|
|
@@ -524,6 +737,14 @@ class K extends k {
|
|
|
524
737
|
serialCorruptMessage(e) {
|
|
525
738
|
throw console.log(e), this.dispatch("serial:corrupt-message", { code: e }), new Error("Method not implemented 'serialCorruptMessage'");
|
|
526
739
|
}
|
|
740
|
+
#w() {
|
|
741
|
+
this.__internal__.last_error = {
|
|
742
|
+
message: null,
|
|
743
|
+
action: null,
|
|
744
|
+
code: null,
|
|
745
|
+
no_code: 0
|
|
746
|
+
};
|
|
747
|
+
}
|
|
527
748
|
clearSerialQueue() {
|
|
528
749
|
this.__internal__.serial.queue = [];
|
|
529
750
|
}
|
|
@@ -543,7 +764,7 @@ class K extends k {
|
|
|
543
764
|
});
|
|
544
765
|
}
|
|
545
766
|
softReload() {
|
|
546
|
-
|
|
767
|
+
this.#w(), this.dispatch("serial:soft-reload", {});
|
|
547
768
|
}
|
|
548
769
|
async sendConnect() {
|
|
549
770
|
if (!this.__internal__.serial.bytes_connection)
|
|
@@ -570,7 +791,7 @@ class K extends k {
|
|
|
570
791
|
parseStringToBytes(e = "", t = `
|
|
571
792
|
`) {
|
|
572
793
|
const i = this.parseStringToTextEncoder(e, t);
|
|
573
|
-
return Array.from(i).map((
|
|
794
|
+
return Array.from(i).map((n) => n.toString(16));
|
|
574
795
|
}
|
|
575
796
|
parseUint8ToHex(e) {
|
|
576
797
|
return Array.from(e).map((t) => t.toString(16));
|
|
@@ -581,28 +802,28 @@ class K extends k {
|
|
|
581
802
|
stringArrayToUint8Array(e) {
|
|
582
803
|
const t = [];
|
|
583
804
|
return typeof e == "string" ? this.parseStringToTextEncoder(e).buffer : (e.forEach((i) => {
|
|
584
|
-
const
|
|
585
|
-
t.push(parseInt(
|
|
805
|
+
const n = i.replace("0x", "");
|
|
806
|
+
t.push(parseInt(n, 16));
|
|
586
807
|
}), new Uint8Array(t));
|
|
587
808
|
}
|
|
588
809
|
parseUint8ArrayToString(e) {
|
|
589
810
|
let t = new Uint8Array(0);
|
|
590
811
|
e instanceof Uint8Array ? t = e : t = this.stringArrayToUint8Array(e), e = this.parseUint8ToHex(t);
|
|
591
|
-
const i = e.map((
|
|
812
|
+
const i = e.map((n) => parseInt(n, 16));
|
|
592
813
|
return this.__internal__.serial.response.replacer ? String.fromCharCode(...i).replace(this.__internal__.serial.response.replacer, "") : String.fromCharCode(...i);
|
|
593
814
|
}
|
|
594
815
|
hexToAscii(e) {
|
|
595
816
|
const t = e.toString();
|
|
596
817
|
let i = "";
|
|
597
|
-
for (let
|
|
598
|
-
i += String.fromCharCode(parseInt(t.substring(
|
|
818
|
+
for (let n = 0; n < t.length; n += 2)
|
|
819
|
+
i += String.fromCharCode(parseInt(t.substring(n, 2), 16));
|
|
599
820
|
return i;
|
|
600
821
|
}
|
|
601
822
|
asciiToHex(e) {
|
|
602
823
|
const t = [];
|
|
603
|
-
for (let i = 0,
|
|
604
|
-
const
|
|
605
|
-
t.push(
|
|
824
|
+
for (let i = 0, n = e.length; i < n; i++) {
|
|
825
|
+
const a = Number(e.charCodeAt(i)).toString(16);
|
|
826
|
+
t.push(a);
|
|
606
827
|
}
|
|
607
828
|
return t.join("");
|
|
608
829
|
}
|
|
@@ -610,218 +831,8 @@ class K extends k {
|
|
|
610
831
|
return this.isConnected;
|
|
611
832
|
}
|
|
612
833
|
}
|
|
613
|
-
n = new WeakSet(), y = function(e) {
|
|
614
|
-
return !!(e && e.readable && e.writable);
|
|
615
|
-
}, w = function(e = null) {
|
|
616
|
-
this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector = 0, this.dispatch("serial:disconnected", e), h.$dispatchChange(this);
|
|
617
|
-
}, P = function(e) {
|
|
618
|
-
this.__internal__.serial.aux_connecting = e.detail.active ? "connecting" : "finished";
|
|
619
|
-
}, x = async function(e) {
|
|
620
|
-
const t = this.__internal__.serial.port;
|
|
621
|
-
if (!t || t && (!t.readable || !t.writable))
|
|
622
|
-
throw o(this, n, w).call(this, { error: "Port is closed, not readable or writable." }), new Error("The port is closed or is not readable/writable");
|
|
623
|
-
const i = this.validateBytes(e);
|
|
624
|
-
if (this.useRTSCTS && await o(this, n, B).call(this, t, 5e3), t.writable === null) return;
|
|
625
|
-
const r = t.writable.getWriter();
|
|
626
|
-
await r.write(i), r.releaseLock();
|
|
627
|
-
}, B = async function(e, t = 5e3) {
|
|
628
|
-
const i = Date.now();
|
|
629
|
-
for (; ; ) {
|
|
630
|
-
if (Date.now() - i > t)
|
|
631
|
-
throw new Error("Timeout waiting for clearToSend signal");
|
|
632
|
-
const { clearToSend: r } = await e.getSignals();
|
|
633
|
-
if (r) return;
|
|
634
|
-
await L(100);
|
|
635
|
-
}
|
|
636
|
-
}, f = function(e = new Uint8Array([]), t = !1) {
|
|
637
|
-
if (e && e.length > 0) {
|
|
638
|
-
const i = this.__internal__.serial.connected;
|
|
639
|
-
if (this.__internal__.serial.connected = o(this, n, y).call(this, this.__internal__.serial.port), h.$dispatchChange(this), !i && this.__internal__.serial.connected && (this.dispatch("serial:connected"), o(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")
|
|
640
|
-
t ? this.serialCorruptMessage(this.parseUint8ToHex(e)) : this.serialMessage(this.parseUint8ToHex(e));
|
|
641
|
-
else if (this.__internal__.serial.response.as === "uint8")
|
|
642
|
-
t ? this.serialCorruptMessage(e) : this.serialMessage(e);
|
|
643
|
-
else if (this.__internal__.serial.response.as === "string") {
|
|
644
|
-
const r = this.parseUint8ArrayToString(e);
|
|
645
|
-
if (this.__internal__.serial.response.limiter !== null) {
|
|
646
|
-
const _ = r.split(this.__internal__.serial.response.limiter);
|
|
647
|
-
for (const c in _)
|
|
648
|
-
_[c] && (t ? this.serialCorruptMessage(_[c]) : this.serialMessage(_[c]));
|
|
649
|
-
} else
|
|
650
|
-
t ? this.serialCorruptMessage(r) : this.serialMessage(r);
|
|
651
|
-
} else {
|
|
652
|
-
const r = this.stringToArrayBuffer(this.parseUint8ArrayToString(e));
|
|
653
|
-
t ? this.serialCorruptMessage(r) : this.serialMessage(r);
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
this.__internal__.serial.queue.length !== 0 && this.dispatch("internal:queue", {});
|
|
657
|
-
}, D = async function() {
|
|
658
|
-
const e = this.serialFilters, t = await navigator.serial.getPorts({ filters: e });
|
|
659
|
-
return e.length === 0 ? t : t.filter((r) => {
|
|
660
|
-
const _ = r.getInfo();
|
|
661
|
-
return e.some((c) => _.usbProductId === c.usbProductId && _.usbVendorId === c.usbVendorId);
|
|
662
|
-
}).filter((r) => !o(this, n, y).call(this, r));
|
|
663
|
-
}, U = function(e) {
|
|
664
|
-
if (e) {
|
|
665
|
-
const t = this.__internal__.serial.response.buffer, i = new Uint8Array(t.length + e.byteLength);
|
|
666
|
-
i.set(t, 0), i.set(new Uint8Array(e), t.length), this.__internal__.serial.response.buffer = i;
|
|
667
|
-
}
|
|
668
|
-
}, I = async function() {
|
|
669
|
-
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(() => {
|
|
670
|
-
this.__internal__.serial.response.buffer && o(this, n, f).call(this, this.__internal__.serial.response.buffer), this.__internal__.serial.response.buffer = new Uint8Array(0);
|
|
671
|
-
}, this.__internal__.serial.free_timeout_ms || 50);
|
|
672
|
-
}, $ = async function() {
|
|
673
|
-
const e = this.__internal__.serial.response.length;
|
|
674
|
-
let t = this.__internal__.serial.response.buffer;
|
|
675
|
-
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)) {
|
|
676
|
-
for (; t.length >= e; ) {
|
|
677
|
-
const i = t.slice(0, e);
|
|
678
|
-
o(this, n, f).call(this, i), t = t.slice(e);
|
|
679
|
-
}
|
|
680
|
-
this.__internal__.serial.response.buffer = t, t.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
681
|
-
o(this, n, f).call(this, this.__internal__.serial.response.buffer, !0);
|
|
682
|
-
}, this.__internal__.serial.free_timeout_ms || 50));
|
|
683
|
-
}
|
|
684
|
-
}, R = async function() {
|
|
685
|
-
const {
|
|
686
|
-
limiter: e,
|
|
687
|
-
prefixLimiter: t = !1,
|
|
688
|
-
sufixLimiter: i = !0
|
|
689
|
-
} = this.__internal__.serial.response;
|
|
690
|
-
if (!e)
|
|
691
|
-
throw new Error("No limiter defined for delimited serial response");
|
|
692
|
-
const r = this.__internal__.serial.response.buffer;
|
|
693
|
-
if (!e || !r || r.length === 0) return;
|
|
694
|
-
this.__internal__.serial.time_until_send_bytes && (clearTimeout(this.__internal__.serial.time_until_send_bytes), this.__internal__.serial.time_until_send_bytes = 0);
|
|
695
|
-
let c = new TextDecoder().decode(r);
|
|
696
|
-
const b = [];
|
|
697
|
-
if (typeof e == "string") {
|
|
698
|
-
let u;
|
|
699
|
-
if (t && i)
|
|
700
|
-
u = new RegExp(`${e}([^${e}]+)${e}`, "g");
|
|
701
|
-
else if (t)
|
|
702
|
-
u = new RegExp(`${e}([^${e}]*)`, "g");
|
|
703
|
-
else if (i)
|
|
704
|
-
u = new RegExp(`([^${e}]+)${e}`, "g");
|
|
705
|
-
else
|
|
706
|
-
return;
|
|
707
|
-
let p, d = 0;
|
|
708
|
-
for (; (p = u.exec(c)) !== null; )
|
|
709
|
-
b.push(new TextEncoder().encode(p[1])), d = u.lastIndex;
|
|
710
|
-
c = c.slice(d);
|
|
711
|
-
} else if (e instanceof RegExp) {
|
|
712
|
-
let u, p = 0;
|
|
713
|
-
if (t && i) {
|
|
714
|
-
const d = new RegExp(`${e.source}(.*?)${e.source}`, "g");
|
|
715
|
-
for (; (u = d.exec(c)) !== null; )
|
|
716
|
-
b.push(new TextEncoder().encode(u[1])), p = d.lastIndex;
|
|
717
|
-
} else if (i)
|
|
718
|
-
for (; (u = e.exec(c)) !== null; ) {
|
|
719
|
-
const d = u.index, v = c.slice(p, d);
|
|
720
|
-
b.push(new TextEncoder().encode(v)), p = e.lastIndex;
|
|
721
|
-
}
|
|
722
|
-
else if (t) {
|
|
723
|
-
const d = c.split(e);
|
|
724
|
-
d.shift();
|
|
725
|
-
for (const v of d)
|
|
726
|
-
b.push(new TextEncoder().encode(v));
|
|
727
|
-
c = "";
|
|
728
|
-
}
|
|
729
|
-
c = c.slice(p);
|
|
730
|
-
}
|
|
731
|
-
for (const u of b)
|
|
732
|
-
o(this, n, f).call(this, u);
|
|
733
|
-
const T = new TextEncoder().encode(c);
|
|
734
|
-
this.__internal__.serial.response.buffer = T, T.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
735
|
-
o(this, n, f).call(this, this.__internal__.serial.response.buffer, !0), this.__internal__.serial.response.buffer = new Uint8Array(0);
|
|
736
|
-
}, this.__internal__.serial.free_timeout_ms ?? 50));
|
|
737
|
-
}, M = async function() {
|
|
738
|
-
const e = this.__internal__.serial.port;
|
|
739
|
-
if (!e || !e.readable) throw new Error("Port is not readable");
|
|
740
|
-
const t = e.readable.getReader();
|
|
741
|
-
this.__internal__.serial.reader = t;
|
|
742
|
-
try {
|
|
743
|
-
for (; this.__internal__.serial.keep_reading; ) {
|
|
744
|
-
const { value: i, done: r } = await t.read();
|
|
745
|
-
if (r) break;
|
|
746
|
-
o(this, n, U).call(this, i), this.__internal__.serial.response.delimited ? await o(this, n, R).call(this) : this.__internal__.serial.response.length === null ? await o(this, n, I).call(this) : await o(this, n, $).call(this);
|
|
747
|
-
}
|
|
748
|
-
} catch (i) {
|
|
749
|
-
this.serialErrors(i);
|
|
750
|
-
} finally {
|
|
751
|
-
t.releaseLock(), this.__internal__.serial.keep_reading = !0, this.__internal__.serial.port && await this.__internal__.serial.port.close();
|
|
752
|
-
}
|
|
753
|
-
}, m = function(e) {
|
|
754
|
-
e !== this.__internal__.serial.connecting && (this.__internal__.serial.connecting = e, e ? this.dispatch("serial:connecting", { active: !0 }) : this.dispatch("serial:connecting", { active: !1 }));
|
|
755
|
-
}, q = async function() {
|
|
756
|
-
return typeof window > "u" ? !1 : "serial" in navigator && "forget" in SerialPort.prototype && this.__internal__.serial.port ? (await this.__internal__.serial.port.forget(), !0) : !1;
|
|
757
|
-
}, N = function() {
|
|
758
|
-
[
|
|
759
|
-
"serial:connected",
|
|
760
|
-
"serial:connecting",
|
|
761
|
-
"serial:reconnect",
|
|
762
|
-
"serial:timeout",
|
|
763
|
-
"serial:disconnected",
|
|
764
|
-
"serial:sent",
|
|
765
|
-
"serial:soft-reload",
|
|
766
|
-
"serial:message",
|
|
767
|
-
"serial:corrupt-message",
|
|
768
|
-
"unknown",
|
|
769
|
-
"serial:need-permission",
|
|
770
|
-
"serial:lost",
|
|
771
|
-
"serial:unsupported",
|
|
772
|
-
"serial:error",
|
|
773
|
-
"debug"
|
|
774
|
-
].forEach((t) => {
|
|
775
|
-
this.serialRegisterAvailableListener(t);
|
|
776
|
-
});
|
|
777
|
-
}, O = function() {
|
|
778
|
-
const e = this;
|
|
779
|
-
this.on("internal:queue", async () => {
|
|
780
|
-
var t;
|
|
781
|
-
await o(t = e, n, H).call(t);
|
|
782
|
-
}), o(this, n, F).call(this);
|
|
783
|
-
}, F = function() {
|
|
784
|
-
const e = this;
|
|
785
|
-
navigator.serial.addEventListener("connect", async () => {
|
|
786
|
-
e.isDisconnected && await e.serialConnect().catch(() => {
|
|
787
|
-
});
|
|
788
|
-
});
|
|
789
|
-
}, H = async function() {
|
|
790
|
-
if (!o(this, n, y).call(this, this.__internal__.serial.port)) {
|
|
791
|
-
o(this, n, w).call(this, { error: "Port is closed, not readable or writable." }), await this.serialConnect();
|
|
792
|
-
return;
|
|
793
|
-
}
|
|
794
|
-
if (this.__internal__.timeout.until_response || this.__internal__.serial.queue.length === 0) return;
|
|
795
|
-
const e = this.__internal__.serial.queue[0];
|
|
796
|
-
let t = this.__internal__.time.response_general;
|
|
797
|
-
if (e.action === "connect" && (t = this.__internal__.time.response_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
|
|
798
|
-
await this.timeout(e.bytes, e.action);
|
|
799
|
-
}, t), this.__internal__.serial.last_action = e.action ?? "unknown", await o(this, n, x).call(this, e.bytes), this.dispatch("serial:sent", {
|
|
800
|
-
action: e.action,
|
|
801
|
-
bytes: e.bytes
|
|
802
|
-
}), this.__internal__.auto_response) {
|
|
803
|
-
let r = new Uint8Array(0);
|
|
804
|
-
try {
|
|
805
|
-
r = this.validateBytes(this.__internal__.serial.auto_response);
|
|
806
|
-
} catch (_) {
|
|
807
|
-
this.serialErrors(_);
|
|
808
|
-
}
|
|
809
|
-
o(this, n, f).call(this, r);
|
|
810
|
-
}
|
|
811
|
-
const i = [...this.__internal__.serial.queue];
|
|
812
|
-
this.__internal__.serial.queue = i.splice(1);
|
|
813
|
-
}, j = function(e = 1) {
|
|
814
|
-
this.__internal__.device_number = e, !this.__internal__.bypassSerialBytesConnection && (this.__internal__.serial.bytes_connection = this.serialSetConnectionConstant(e));
|
|
815
|
-
}, W = function() {
|
|
816
|
-
this.__internal__.last_error = {
|
|
817
|
-
message: null,
|
|
818
|
-
action: null,
|
|
819
|
-
code: null,
|
|
820
|
-
no_code: 0
|
|
821
|
-
};
|
|
822
|
-
};
|
|
823
834
|
export {
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
835
|
+
b as Core,
|
|
836
|
+
s as Devices,
|
|
837
|
+
y as Dispatcher
|
|
827
838
|
};
|
|
@@ -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 k=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)||k("Cannot "+d);var P=(l,_,d)=>_.has(l)?k("Cannot add the same private member more than once"):_ instanceof WeakSet?_.add(l):_.set(l,d);var o=(l,_,d)=>(K(l,_,"access private method"),d);var n,b,C,D,E,B,g,U,I,$,R,M,q,w,N,O,F,H,j,W,Q;class _ extends CustomEvent{constructor(s,e){super(s,e)}}class d extends EventTarget{constructor(){super(...arguments);m(this,"__listeners__",{debug:!1});m(this,"__debug__",!1);m(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__)this.removeEventListener(e.key,e.callback);this.__listenersCallbacks__=[],this.__listeners__={debug:!1}}}const a=class a extends d{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))}};m(a,"instance"),m(a,"devices",{});let u=a;u.instance||(u.instance=new u);function A(x=100){return new Promise(s=>setTimeout(()=>s(),x))}function V(){return"serial"in navigator}const T={baudRate:9600,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"};class z extends d{constructor({filters:e=null,config_port:t=T,no_device:i=1,device_listen_on_channel:r=1,bypassSerialBytesConnection:c=!1}={filters:null,config_port:T,no_device:1,device_listen_on_channel:1,bypassSerialBytesConnection:!1}){super();P(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:T,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&&o(this,n,W).call(this,i),r&&["number","string"].includes(typeof r)&&(this.listenOnChannel=r),o(this,n,O).call(this),o(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=o(this,n,b).call(this,this.__internal__.serial.port);return e&&!t&&o(this,n,C).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,b).call(this,this.__internal__.serial.port);return!e&&t&&(this.dispatch("serial:connected"),o(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(),o(this,n,C).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=o(this,n,D).bind(this);this.on("serial:connecting",i);const r=setInterval(()=>{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}))},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,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{o(this,n,w).call(this,!0);const e=await o(this,n,U).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 c;i.dispatch("serial:connected",r),o(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 o(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&&o(this,n,g).call(this,this.__internal__.serial.auto_response),await o(this,n,q).call(this)}catch(e){o(this,n,w).call(this,!1),this.serialErrors(e)}}async serialForget(){return await o(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,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,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(_,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(_=typeof globalThis<"u"?globalThis:_||self,h(_.WebSerialCore={}))})(this,function(_){"use strict";class h extends CustomEvent{constructor(e,t){super(e,t)}}class f extends EventTarget{__listeners__={debug:!1};__debug__=!1;__listenersCallbacks__=[];dispatch(e,t=null){const i=new h(e,{detail:t});this.dispatchEvent(i),this.__debug__&&this.dispatchEvent(new h("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.__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}}class s extends f{static instance;static devices={};constructor(){super(),["change"].forEach(t=>{this.serialRegisterAvailableListener(t)})}static $dispatchChange(e=null){e&&e.$checkAndDispatchConnection(),s.instance.dispatch("change",{devices:s.devices,dispatcher:e})}static typeError(e){const t=new Error;throw t.message=`Type ${e} is not supported`,t.name="DeviceTypeError",t}static registerType(e){typeof s.devices[e]>"u"&&(s.devices={...s.devices,[e]:{}})}static add(e){const t=e.typeDevice;typeof s.devices[t]>"u"&&s.registerType(t);const i=e.uuid;if(typeof s.devices[t]>"u"&&s.typeError(t),s.devices[t][i])throw new Error(`Device with id ${i} already exists`);return s.devices[t][i]=e,s.$dispatchChange(e),Object.keys(s.devices[t]).indexOf(i)}static get(e,t){return typeof s.devices[e]>"u"&&s.registerType(e),typeof s.devices[e]>"u"&&s.typeError(e),s.devices[e][t]}static getAll(e=null){return e===null?s.devices:(typeof s.devices[e]>"u"&&s.typeError(e),s.devices[e])}static getList(){return Object.values(s.devices).map(t=>Object.values(t)).flat()}static getByNumber(e,t){return typeof s.devices[e]>"u"&&s.typeError(e),Object.values(s.devices[e]).find(n=>n.deviceNumber===t)??null}static getCustom(e,t=1){return typeof s.devices[e]>"u"&&s.typeError(e),Object.values(s.devices[e]).find(n=>n.deviceNumber===t)??null}static async connectToAll(){const e=s.getList();for(const t of e)t.isConnected||await t.connect().catch(console.warn);return Promise.resolve(s.areAllConnected())}static async disconnectAll(){const e=s.getList();for(const t of e)t.isDisconnected||await t.disconnect().catch(console.warn);return Promise.resolve(s.areAllDisconnected())}static async areAllConnected(){const e=s.getList();for(const t of e)if(!t.isConnected)return Promise.resolve(!1);return Promise.resolve(!0)}static async areAllDisconnected(){const e=s.getList();for(const t of e)if(!t.isDisconnected)return Promise.resolve(!1);return Promise.resolve(!0)}static async getAllConnected(){const e=s.getList();return Promise.resolve(e.filter(t=>t.isConnected))}static async getAllDisconnected(){const e=s.getList();return Promise.resolve(e.filter(t=>t.isDisconnected))}}s.instance||(s.instance=new s);function y(d=100){return new Promise(e=>setTimeout(()=>e(),d))}function b(){return"serial"in navigator}const p={baudRate:9600,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"};class w extends f{__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:p,queue:[],running_queue:!1,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}};#t=null;constructor({filters:e=null,config_port:t=p,no_device:i=1,device_listen_on_channel:n=1,bypassSerialBytesConnection:a=!1}={filters:null,config_port:p,no_device:1,device_listen_on_channel:1,bypassSerialBytesConnection:!1}){if(super(),!("serial"in navigator))throw new Error("Web Serial not supported");e&&(this.serialFilters=e),t&&(this.serialConfigPort=t),a&&(this.__internal__.bypassSerialBytesConnection=a),i&&this.#b(i),n&&["number","string"].includes(typeof n)&&(this.listenOnChannel=n),this.#p(),this.#g()}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=this.#i(this.__internal__.serial.port);return e&&!t&&this.#s({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=this.#i(this.__internal__.serial.port);return!e&&t&&(this.dispatch("serial:connected"),this.#n(!1),s.$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}#i(e){return!!(e&&e.readable&&e.writable)}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",{}),s.$dispatchChange(this)):t==="connection:start"&&(await this.serialDisconnect(),this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector+=1,s.$dispatchChange(this),await this.serialConnect()),this.__internal__.serial.queue.length>0&&this.dispatch("internal:queue",{}),this.dispatch("serial:timeout",{...this.__internal__.last_error,bytes:e,action:t})}async disconnect(e=null){await this.serialDisconnect(),this.#s(e)}#s(e=null){this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector=0,this.dispatch("serial:disconnected",e),s.$dispatchChange(this)}#a(e){this.__internal__.serial.aux_connecting=e.detail.active?"connecting":"finished"}async connect(){return this.isConnected?!0:(this.__internal__.serial.aux_connecting="idle",new Promise((e,t)=>{b()||t("Web Serial not supported"),this.#t||(this.#t=this.#a.bind(this)),this.on("internal:connecting",this.#t);const i=setInterval(()=>{this.__internal__.serial.aux_connecting==="finished"?(clearInterval(i),this.__internal__.serial.aux_connecting="idle",this.#t!==null&&this.off("internal:connecting",this.#t),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(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,s.$dispatchChange(this)}}async#r(e){const t=this.__internal__.serial.port;if(!t||t&&(!t.readable||!t.writable))throw this.#s({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 this.#l(t,5e3),t.writable===null)return;const n=t.writable.getWriter();await n.write(i),n.releaseLock()}async#l(e,t=5e3){const i=Date.now();for(;;){if(Date.now()-i>t)throw new Error("Timeout waiting for clearToSend signal");const{clearToSend:n}=await e.getSignals();if(n)return;await y(100)}}#e(e=new Uint8Array([]),t=!1){if(e&&e.length>0){const i=this.__internal__.serial.connected;if(this.__internal__.serial.connected=this.#i(this.__internal__.serial.port),s.$dispatchChange(this),!i&&this.__internal__.serial.connected&&(this.dispatch("serial:connected"),this.#n(!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 n=this.parseUint8ArrayToString(e);if(this.__internal__.serial.response.limiter!==null){const a=n.split(this.__internal__.serial.response.limiter);for(const r in a)a[r]&&(t?this.serialCorruptMessage(a[r]):this.serialMessage(a[r]))}else t?this.serialCorruptMessage(n):this.serialMessage(n)}else{const n=this.stringToArrayBuffer(this.parseUint8ArrayToString(e));t?this.serialCorruptMessage(n):this.serialMessage(n)}}if(this.__internal__.serial.queue.length===0){this.__internal__.serial.running_queue=!1;return}this.dispatch("internal:queue",{})}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#o(){const e=this.serialFilters,t=await navigator.serial.getPorts({filters:e});return e.length===0?t:t.filter(n=>{const a=n.getInfo();return e.some(r=>a.usbProductId===r.usbProductId&&a.usbVendorId===r.usbVendorId)}).filter(n=>!this.#i(n))}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",{}),s.$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",{}),s.$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)}#_(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#c(){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&&this.#e(this.__internal__.serial.response.buffer),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms||50)}async#h(){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);this.#e(i),t=t.slice(e)}this.__internal__.serial.response.buffer=t,t.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{this.#e(this.__internal__.serial.response.buffer,!0)},this.__internal__.serial.free_timeout_ms||50))}}async#u(){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 n=this.__internal__.serial.response.buffer;if(!e||!n||n.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 r=new TextDecoder().decode(n);const u=[];if(typeof e=="string"){let l;if(t&&i)l=new RegExp(`${e}([^${e}]+)${e}`,"g");else if(t)l=new RegExp(`${e}([^${e}]*)`,"g");else if(i)l=new RegExp(`([^${e}]+)${e}`,"g");else return;let c,o=0;for(;(c=l.exec(r))!==null;)u.push(new TextEncoder().encode(c[1])),o=l.lastIndex;r=r.slice(o)}else if(e instanceof RegExp){let l,c=0;if(t&&i){const o=new RegExp(`${e.source}(.*?)${e.source}`,"g");for(;(l=o.exec(r))!==null;)u.push(new TextEncoder().encode(l[1])),c=o.lastIndex}else if(i)for(;(l=e.exec(r))!==null;){const o=l.index,g=r.slice(c,o);u.push(new TextEncoder().encode(g)),c=e.lastIndex}else if(t){const o=r.split(e);o.shift();for(const g of o)u.push(new TextEncoder().encode(g));r=""}r=r.slice(c)}for(const l of u)this.#e(l);const m=new TextEncoder().encode(r);this.__internal__.serial.response.buffer=m,m.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{this.#e(this.__internal__.serial.response.buffer,!0),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms??50))}async#d(){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:n}=await t.read();if(n)break;this.#_(i),this.__internal__.serial.response.delimited?await this.#u():this.__internal__.serial.response.length===null?await this.#c():await this.#h()}}catch(i){this.serialErrors(i)}finally{t.releaseLock(),this.__internal__.serial.keep_reading=!0,this.__internal__.serial.port&&await this.__internal__.serial.port.close()}}#n(e){e!==this.__internal__.serial.connecting&&(this.__internal__.serial.connecting=e,this.dispatch("serial:connecting",{active:e}),this.dispatch("internal:connecting",{active:e}))}async serialConnect(){try{this.#n(!0);const e=await this.#o();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=>{i.dispatch("serial:connected",n),i.#n(!1),s.$dispatchChange(this),i.__internal__.serial.queue.length>0?i.dispatch("internal:queue",{}):i.__internal__.serial.running_queue=!1},t.ondisconnect=async()=>{await i.disconnect()},await y(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 this.#r(this.__internal__.serial.bytes_connection??[]),this.dispatch("serial:sent",{action:"connect",bytes:this.__internal__.serial.bytes_connection}),this.__internal__.auto_response&&this.#e(this.__internal__.serial.auto_response),await this.#d()}catch(e){this.#n(!1),this.serialErrors(e)}}async#f(){return typeof window>"u"?!1:"serial"in navigator&&"forget"in SerialPort.prototype&&this.__internal__.serial.port?(await this.__internal__.serial.port.forget(),!0):!1}async serialForget(){return await this.#f()}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)))}#p(){["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)})}#g(){const e=this;this.on("internal:queue",async()=>{await e.#m()}),this.#y()}#y(){const e=this;navigator.serial.addEventListener("connect",async()=>{e.isDisconnected&&await e.serialConnect().catch(()=>{})})}async#m(){if(!this.#i(this.__internal__.serial.port)){this.#s({error:"Port is closed, not readable or writable."}),await this.serialConnect();return}if(this.__internal__.timeout.until_response)return;if(this.__internal__.serial.queue.length===0){this.__internal__.serial.running_queue=!1;return}this.__internal__.serial.running_queue=!0;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 this.#r(e.bytes),this.dispatch("serial:sent",{action:e.action,bytes:e.bytes}),this.__internal__.auto_response){let n=new Uint8Array(0);try{n=this.validateBytes(this.__internal__.serial.auto_response)}catch(a){this.serialErrors(a)}this.#e(n)}const i=[...this.__internal__.serial.queue];this.__internal__.serial.queue=i.splice(1),this.__internal__.serial.queue.length>0&&(this.__internal__.serial.running_queue=!0)}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",{})}#b(e=1){this.__internal__.device_number=e,!this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(e))}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'")}#w(){this.__internal__.last_error={message:null,action:null,code:null,no_code:0}}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(){this.#w(),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(n=>n.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 n=i.replace("0x","");t.push(parseInt(n,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(n=>parseInt(n,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 n=0;n<t.length;n+=2)i+=String.fromCharCode(parseInt(t.substring(n,2),16));return i}asciiToHex(e){const t=[];for(let i=0,n=e.length;i<n;i++){const a=Number(e.charCodeAt(i)).toString(16);t.push(a)}return t.join("")}$checkAndDispatchConnection(){return this.isConnected}}_.Core=w,_.Devices=s,_.Dispatcher=f,Object.defineProperty(_,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.12",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "danidoble",
|
|
@@ -45,14 +45,14 @@
|
|
|
45
45
|
"format": "prettier --write ./lib/**/*.ts"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@eslint/js": "^9.
|
|
48
|
+
"@eslint/js": "^9.34.0",
|
|
49
49
|
"@types/w3c-web-serial": "^1.0.8",
|
|
50
|
-
"eslint": "^9.
|
|
50
|
+
"eslint": "^9.34.0",
|
|
51
51
|
"globals": "^15.15.0",
|
|
52
52
|
"prettier": "3.4.2",
|
|
53
53
|
"typescript": "~5.7.3",
|
|
54
|
-
"typescript-eslint": "^8.
|
|
55
|
-
"vite": "^
|
|
54
|
+
"typescript-eslint": "^8.41.0",
|
|
55
|
+
"vite": "^7.1.3"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|