webserial-core 1.0.6 → 1.0.8
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/LICENSE +21 -0
- package/README.md +26 -6
- package/dist/Core.d.ts +55 -17
- package/dist/Core.d.ts.map +1 -1
- package/dist/Devices.d.ts.map +1 -1
- package/dist/Dispatcher.d.ts.map +1 -1
- package/dist/webserial-core.js +312 -189
- package/dist/webserial-core.umd.cjs +2 -2
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 danidoble
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
And easy way to connect to a serial port from a web page.
|
|
4
4
|
|
|
5
|
+
> [!NOTE]
|
|
6
|
+
> Since version 1.0.7 default response is an instance of Uint8Array.
|
|
7
|
+
> To change the response put this code inside your constructor to change the default response.
|
|
8
|
+
> `this.getResponseAsArrayBuffer()`
|
|
9
|
+
> `this.getResponseAsArrayHex()`
|
|
10
|
+
> `this.getResponseAsUint8Array()`
|
|
11
|
+
> `this.getResponseAsString()`
|
|
12
|
+
> Only choose one of them.
|
|
13
|
+
|
|
5
14
|
## Installation
|
|
6
15
|
|
|
7
16
|
```bash
|
|
@@ -10,6 +19,13 @@ npm install webserial-core
|
|
|
10
19
|
|
|
11
20
|
## Usage
|
|
12
21
|
|
|
22
|
+
> [!NOTE]
|
|
23
|
+
> If you are using Linux, you need to add your user to the `dialout` group to access the serial port.
|
|
24
|
+
> ```bash
|
|
25
|
+
> sudo usermod -a -G dialout $USER
|
|
26
|
+
> ```
|
|
27
|
+
> After that, you need to log out and log in again to apply the changes.
|
|
28
|
+
|
|
13
29
|
You need to create a new class to configure your device functions. In this example, we are going to create a class to
|
|
14
30
|
connect to an Arduino device.
|
|
15
31
|
|
|
@@ -81,12 +97,8 @@ export class Arduino extends Core {
|
|
|
81
97
|
this.__internal__.time.response_general = 2e3;
|
|
82
98
|
this.__internal__.serial.delay_first_connection = 1_000;
|
|
83
99
|
this.#registerAvailableListenersArduino();
|
|
84
|
-
this.#touch();
|
|
85
|
-
this.getResponseAsString();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
#touch() {
|
|
89
100
|
Devices.add(this);
|
|
101
|
+
this.getResponseAsString();
|
|
90
102
|
}
|
|
91
103
|
|
|
92
104
|
#registerAvailableListenersArduino() {
|
|
@@ -206,6 +218,7 @@ arduino.on('serial:disconnected', (event) => {
|
|
|
206
218
|
|
|
207
219
|
document.getElementById('disconnected').classList.remove('hidden');
|
|
208
220
|
document.getElementById('connect').classList.remove('hidden');
|
|
221
|
+
document.getElementById("disconnect")?.classList.add("hidden");
|
|
209
222
|
});
|
|
210
223
|
|
|
211
224
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -220,6 +233,7 @@ arduino.on('serial:connected', (event) => {
|
|
|
220
233
|
document.getElementById('disconnected').classList.add('hidden');
|
|
221
234
|
document.getElementById('need-permission').classList.add('hidden');
|
|
222
235
|
document.getElementById('connect').classList.add('hidden');
|
|
236
|
+
document.getElementById("disconnect")?.classList.remove("hidden");
|
|
223
237
|
});
|
|
224
238
|
|
|
225
239
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -227,6 +241,7 @@ arduino.on('serial:need-permission', (event) => {
|
|
|
227
241
|
document.getElementById('disconnected').classList.remove('hidden');
|
|
228
242
|
document.getElementById('need-permission').classList.remove('hidden');
|
|
229
243
|
document.getElementById('connect').classList.remove('hidden');
|
|
244
|
+
document.getElementById("disconnect")?.classList.add("hidden");
|
|
230
245
|
});
|
|
231
246
|
|
|
232
247
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -248,7 +263,11 @@ function tryConnect() {
|
|
|
248
263
|
|
|
249
264
|
document.addEventListener('DOMContentLoaded', () => {
|
|
250
265
|
tryConnect();
|
|
251
|
-
document.getElementById('connect')
|
|
266
|
+
document.getElementById('connect')?.addEventListener('click', tryConnect);
|
|
267
|
+
document.getElementById("disconnect")?.addEventListener("click", async () => {
|
|
268
|
+
await board.disconnect().catch(console.error);
|
|
269
|
+
document.getElementById('log')?.innerText += 'Disconnected by user\n\n';
|
|
270
|
+
});
|
|
252
271
|
});
|
|
253
272
|
|
|
254
273
|
```
|
|
@@ -271,6 +290,7 @@ But wait still need to create the HTML file.
|
|
|
271
290
|
<div class="webserial w-full max-w-xl mx-auto grid grid-cols-1 gap-y-4">
|
|
272
291
|
<div class="my-6"></div>
|
|
273
292
|
<button id="connect" class="hidden px-4 py-3 bg-gray-800 rounded-lg">Connect to serial</button>
|
|
293
|
+
<button id="disconnect" class="hidden px-4 py-3 bg-rose-800 rounded-lg">Disconnect device</button>
|
|
274
294
|
|
|
275
295
|
<div id="need-permission" class="hidden p-4 bg-rose-900 rounded-lg">
|
|
276
296
|
Woooah! It seems that you need to give permission to access the serial port.
|
package/dist/Core.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Dispatcher } from "./Dispatcher.ts";
|
|
|
2
2
|
interface LastError {
|
|
3
3
|
message: string | null;
|
|
4
4
|
action: string | null;
|
|
5
|
-
code:
|
|
5
|
+
code: string | Uint8Array | Array<string> | Array<number> | null | number;
|
|
6
6
|
no_code: number;
|
|
7
7
|
}
|
|
8
8
|
interface DeviceData {
|
|
@@ -17,9 +17,12 @@ interface SerialResponse {
|
|
|
17
17
|
as: SerialResponseAs;
|
|
18
18
|
replacer: RegExp | string;
|
|
19
19
|
limiter: null | string | RegExp;
|
|
20
|
+
prefixLimiter: boolean;
|
|
21
|
+
sufixLimiter: boolean;
|
|
22
|
+
delimited: boolean;
|
|
20
23
|
}
|
|
21
24
|
interface QueueData {
|
|
22
|
-
bytes: string
|
|
25
|
+
bytes: string | Uint8Array | Array<string> | Array<number>;
|
|
23
26
|
action: string;
|
|
24
27
|
}
|
|
25
28
|
type SerialData = {
|
|
@@ -35,11 +38,13 @@ type SerialData = {
|
|
|
35
38
|
keep_reading: boolean;
|
|
36
39
|
time_until_send_bytes: number | undefined | ReturnType<typeof setTimeout>;
|
|
37
40
|
delay_first_connection: number;
|
|
38
|
-
bytes_connection:
|
|
41
|
+
bytes_connection: string | Uint8Array | string[] | number[] | null;
|
|
39
42
|
filters: SerialPortFilter[];
|
|
40
43
|
config_port: SerialOptions;
|
|
41
44
|
queue: QueueData[];
|
|
42
45
|
auto_response: any;
|
|
46
|
+
free_timeout_ms: number;
|
|
47
|
+
useRTSCTS: boolean;
|
|
43
48
|
};
|
|
44
49
|
interface TimeResponse {
|
|
45
50
|
response_connection: number;
|
|
@@ -52,6 +57,7 @@ interface InternalIntervals {
|
|
|
52
57
|
reconnection: number;
|
|
53
58
|
}
|
|
54
59
|
export type Internal = {
|
|
60
|
+
bypassSerialBytesConnection: boolean;
|
|
55
61
|
auto_response: boolean;
|
|
56
62
|
device_number: number;
|
|
57
63
|
aux_port_connector: number;
|
|
@@ -67,9 +73,10 @@ interface CoreConstructorParams {
|
|
|
67
73
|
config_port?: SerialOptions;
|
|
68
74
|
no_device?: number;
|
|
69
75
|
device_listen_on_channel?: number | string;
|
|
76
|
+
bypassSerialBytesConnection?: boolean;
|
|
70
77
|
}
|
|
71
78
|
interface CustomCode {
|
|
72
|
-
code: Array<string>;
|
|
79
|
+
code: string | Uint8Array | Array<string> | Array<number>;
|
|
73
80
|
}
|
|
74
81
|
interface ICore {
|
|
75
82
|
lastAction: string | null;
|
|
@@ -80,10 +87,26 @@ interface ICore {
|
|
|
80
87
|
get serialConfigPort(): SerialOptions;
|
|
81
88
|
get isConnected(): boolean;
|
|
82
89
|
get isDisconnected(): boolean;
|
|
90
|
+
get useRTSCTS(): boolean;
|
|
91
|
+
set useRTSCTS(value: boolean);
|
|
83
92
|
get deviceNumber(): number;
|
|
84
93
|
get uuid(): string;
|
|
85
94
|
get typeDevice(): string;
|
|
86
95
|
get queue(): QueueData[];
|
|
96
|
+
get timeoutBeforeResponseBytes(): number;
|
|
97
|
+
set timeoutBeforeResponseBytes(value: number);
|
|
98
|
+
get fixedBytesMessage(): number | null;
|
|
99
|
+
set fixedBytesMessage(length: number | null);
|
|
100
|
+
get responseDelimited(): boolean;
|
|
101
|
+
set responseDelimited(value: boolean);
|
|
102
|
+
get responsePrefixLimited(): boolean;
|
|
103
|
+
set responsePrefixLimited(value: boolean);
|
|
104
|
+
get responseSufixLimited(): boolean;
|
|
105
|
+
set responseSufixLimited(value: boolean);
|
|
106
|
+
get responseLimiter(): string | RegExp | null;
|
|
107
|
+
set responseLimiter(limiter: string | RegExp | null);
|
|
108
|
+
get bypassSerialBytesConnection(): boolean;
|
|
109
|
+
set bypassSerialBytesConnection(value: boolean);
|
|
87
110
|
timeout(bytes: string[], event: string): Promise<void>;
|
|
88
111
|
disconnect(detail?: null): Promise<void>;
|
|
89
112
|
connect(): Promise<string>;
|
|
@@ -98,16 +121,14 @@ interface ICore {
|
|
|
98
121
|
add0x(bytes: string[]): string[];
|
|
99
122
|
bytesToHex(bytes: string[]): string[];
|
|
100
123
|
appendToQueue(arr: string[], action: string): Promise<void>;
|
|
101
|
-
serialSetConnectionConstant(listen_on_port?: number):
|
|
102
|
-
serialMessage(
|
|
103
|
-
serialCorruptMessage(
|
|
124
|
+
serialSetConnectionConstant(listen_on_port?: number): string | Uint8Array | string[] | number[] | null;
|
|
125
|
+
serialMessage(code: string[]): void;
|
|
126
|
+
serialCorruptMessage(data: Uint8Array | number[] | string[] | never | null | string | ArrayBuffer): void;
|
|
104
127
|
clearSerialQueue(): void;
|
|
105
128
|
sumHex(arr: string[]): string;
|
|
106
129
|
softReload(): void;
|
|
107
130
|
sendConnect(): Promise<void>;
|
|
108
|
-
sendCustomCode(
|
|
109
|
-
code: CustomCode;
|
|
110
|
-
}): Promise<void>;
|
|
131
|
+
sendCustomCode(customCode: CustomCode): Promise<void>;
|
|
111
132
|
stringToArrayHex(string: string): string[];
|
|
112
133
|
stringToArrayBuffer(string: string, end: string): ArrayBufferLike;
|
|
113
134
|
parseStringToBytes(string: string, end: string): string[];
|
|
@@ -126,7 +147,7 @@ interface ICore {
|
|
|
126
147
|
export declare class Core extends Dispatcher implements ICore {
|
|
127
148
|
#private;
|
|
128
149
|
protected __internal__: Internal;
|
|
129
|
-
constructor({ filters, config_port, no_device, device_listen_on_channel, }?: CoreConstructorParams);
|
|
150
|
+
constructor({ filters, config_port, no_device, device_listen_on_channel, bypassSerialBytesConnection, }?: CoreConstructorParams);
|
|
130
151
|
set listenOnChannel(channel: string | number);
|
|
131
152
|
get lastAction(): string | null;
|
|
132
153
|
get listenOnChannel(): number;
|
|
@@ -134,13 +155,29 @@ export declare class Core extends Dispatcher implements ICore {
|
|
|
134
155
|
get serialFilters(): SerialPortFilter[];
|
|
135
156
|
set serialConfigPort(config_port: SerialOptions);
|
|
136
157
|
get serialConfigPort(): SerialOptions;
|
|
158
|
+
get useRTSCTS(): boolean;
|
|
159
|
+
set useRTSCTS(value: boolean);
|
|
137
160
|
get isConnected(): boolean;
|
|
138
161
|
get isDisconnected(): boolean;
|
|
139
162
|
get deviceNumber(): number;
|
|
140
163
|
get uuid(): string;
|
|
141
164
|
get typeDevice(): string;
|
|
142
165
|
get queue(): QueueData[];
|
|
143
|
-
|
|
166
|
+
get responseDelimited(): boolean;
|
|
167
|
+
set responseDelimited(value: boolean);
|
|
168
|
+
get responsePrefixLimited(): boolean;
|
|
169
|
+
set responsePrefixLimited(value: boolean);
|
|
170
|
+
get responseSufixLimited(): boolean;
|
|
171
|
+
set responseSufixLimited(value: boolean);
|
|
172
|
+
get responseLimiter(): string | RegExp | null;
|
|
173
|
+
set responseLimiter(limiter: string | RegExp | null);
|
|
174
|
+
get fixedBytesMessage(): number | null;
|
|
175
|
+
set fixedBytesMessage(length: number | null);
|
|
176
|
+
get timeoutBeforeResponseBytes(): number;
|
|
177
|
+
set timeoutBeforeResponseBytes(value: number);
|
|
178
|
+
get bypassSerialBytesConnection(): boolean;
|
|
179
|
+
set bypassSerialBytesConnection(value: boolean);
|
|
180
|
+
timeout(bytes: string | Uint8Array | Array<string> | Array<number>, event: string): Promise<void>;
|
|
144
181
|
disconnect(detail?: null): Promise<void>;
|
|
145
182
|
connect(): Promise<string>;
|
|
146
183
|
serialDisconnect(): Promise<void>;
|
|
@@ -157,10 +194,11 @@ export declare class Core extends Dispatcher implements ICore {
|
|
|
157
194
|
hexMaker(val?: string, min?: number): string;
|
|
158
195
|
add0x(bytes: string[]): string[];
|
|
159
196
|
bytesToHex(bytes: string[]): string[];
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
197
|
+
validateBytes(data: string | Uint8Array | Array<string> | Array<number>): Uint8Array;
|
|
198
|
+
appendToQueue(arr: string | Uint8Array | string[] | number[], action: string): Promise<void>;
|
|
199
|
+
serialSetConnectionConstant(listen_on_port?: number): string | Uint8Array | string[] | number[] | null;
|
|
200
|
+
serialMessage(code: string[] | Uint8Array<ArrayBufferLike> | string | ArrayBuffer): void;
|
|
201
|
+
serialCorruptMessage(code: Uint8Array | number[] | string[] | never | null | string | ArrayBuffer): void;
|
|
164
202
|
clearSerialQueue(): void;
|
|
165
203
|
sumHex(arr: string[]): string;
|
|
166
204
|
toString(): string;
|
|
@@ -174,7 +212,7 @@ export declare class Core extends Dispatcher implements ICore {
|
|
|
174
212
|
parseUint8ToHex(array: Uint8Array): string[];
|
|
175
213
|
parseHexToUint8(array: string[]): Uint8Array;
|
|
176
214
|
stringArrayToUint8Array(strings: string[]): Uint8Array;
|
|
177
|
-
parseUint8ArrayToString(array: string[]): string;
|
|
215
|
+
parseUint8ArrayToString(array: Uint8Array | string[]): string;
|
|
178
216
|
hexToAscii(hex: string | number): string;
|
|
179
217
|
asciiToHex(asciiString: string): string;
|
|
180
218
|
$checkAndDispatchConnection(): boolean;
|
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,KAAK,CAAC,
|
|
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,GA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G,GAAE,MAAa,GAAG,eAAe;IAIxE,wBAAwB,CAAC,MAAM,GAAE,MAAW,EAAE,GAAG,GAAE,MAAa,GAAG,UAAU;IAM7E,kBAAkB,CAAC,MAAM,GAAE,MAAW,EAAE,GAAG,GAAE,MAAa,GAAG,MAAM,EAAE;IAKrE,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE;IAI5C,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU;IAI5C,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU;IAatD,uBAAuB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE,GAAG,MAAM;IAgB7D,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IASxC,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IASvC,2BAA2B,IAAI,OAAO;CAG9C"}
|
package/dist/Devices.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Devices.d.ts","sourceRoot":"","sources":["../lib/Devices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,UAAU,OAAO;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAED,UAAU,QAAQ;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,qBAAa,OAAQ,SAAQ,UAAU;IACrC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC;IACzB,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAM;;
|
|
1
|
+
{"version":3,"file":"Devices.d.ts","sourceRoot":"","sources":["../lib/Devices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CA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I,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;IAEhD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;IAEjD,+BAA+B,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpD,kBAAkB,EAAE,kBAAkB,CAAC;CACxC;AAED,UAAU,SAAS;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAEvB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,qBAAa,UAAW,SAAQ,WAAY,YAAW,WAAW;IAChE,aAAa,EAAE,SAAS,CAEtB;IACF,SAAS,EAAE,OAAO,CAAS;IAEpB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,QAAe;IAQ5C,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,OAAO,EAAE,EAAE,SAAM;IAQjD,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,kCAAkC;IAQ7D,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,kCAAkC;IAI9D,+BAA+B,CAAC,IAAI,EAAE,MAAM;IAMnD,IAAI,kBAAkB,IAAI,kBAAkB,CAQ3C;CACF"}
|
package/dist/webserial-core.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var j = Object.defineProperty;
|
|
2
|
+
var T = (l) => {
|
|
3
3
|
throw TypeError(l);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
class
|
|
10
|
-
constructor(
|
|
11
|
-
super(
|
|
5
|
+
var W = (l, s, e) => s in l ? j(l, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[s] = e;
|
|
6
|
+
var g = (l, s, e) => W(l, typeof s != "symbol" ? s + "" : s, e), Q = (l, s, e) => s.has(l) || T("Cannot " + e);
|
|
7
|
+
var E = (l, s, e) => s.has(l) ? T("Cannot add the same private member more than once") : s instanceof WeakSet ? s.add(l) : s.set(l, e);
|
|
8
|
+
var a = (l, s, e) => (Q(l, s, "access private method"), e);
|
|
9
|
+
class A extends CustomEvent {
|
|
10
|
+
constructor(s, e) {
|
|
11
|
+
super(s, e);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
class
|
|
14
|
+
class L extends EventTarget {
|
|
15
15
|
constructor() {
|
|
16
16
|
super(...arguments);
|
|
17
|
-
|
|
17
|
+
g(this, "__listeners__", {
|
|
18
18
|
debug: !1
|
|
19
19
|
});
|
|
20
|
-
|
|
20
|
+
g(this, "__debug__", !1);
|
|
21
21
|
}
|
|
22
22
|
dispatch(e, t = null) {
|
|
23
|
-
const i = new
|
|
24
|
-
this.dispatchEvent(i), this.__debug__ && this.dispatchEvent(new
|
|
23
|
+
const i = new A(e, { detail: t });
|
|
24
|
+
this.dispatchEvent(i), this.__debug__ && this.dispatchEvent(new A("debug", { detail: { type: e, data: t } }));
|
|
25
25
|
}
|
|
26
26
|
dispatchAsync(e, t = null, i = 100) {
|
|
27
27
|
const r = this;
|
|
@@ -45,58 +45,58 @@ class x extends EventTarget {
|
|
|
45
45
|
}));
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
const
|
|
48
|
+
const o = class o extends L {
|
|
49
49
|
constructor() {
|
|
50
50
|
super(), ["change"].forEach((e) => {
|
|
51
51
|
this.serialRegisterAvailableListener(e);
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
|
-
static $dispatchChange(
|
|
55
|
-
|
|
54
|
+
static $dispatchChange(s = null) {
|
|
55
|
+
s && s.$checkAndDispatchConnection(), o.instance.dispatch("change", { devices: o.devices, dispatcher: s });
|
|
56
56
|
}
|
|
57
|
-
static typeError(
|
|
57
|
+
static typeError(s) {
|
|
58
58
|
const e = new Error();
|
|
59
|
-
throw e.message = `Type ${
|
|
59
|
+
throw e.message = `Type ${s} is not supported`, e.name = "DeviceTypeError", e;
|
|
60
60
|
}
|
|
61
|
-
static registerType(
|
|
62
|
-
typeof
|
|
61
|
+
static registerType(s) {
|
|
62
|
+
typeof o.devices[s] > "u" && (o.devices[s] = {});
|
|
63
63
|
}
|
|
64
|
-
static add(
|
|
65
|
-
const e =
|
|
66
|
-
typeof
|
|
67
|
-
const t =
|
|
68
|
-
if (typeof
|
|
64
|
+
static add(s) {
|
|
65
|
+
const e = s.typeDevice;
|
|
66
|
+
typeof o.devices[e] > "u" && (o.devices[e] = {});
|
|
67
|
+
const t = s.uuid;
|
|
68
|
+
if (typeof o.devices[e] > "u" && o.typeError(e), o.devices[e][t])
|
|
69
69
|
throw new Error(`Device with id ${t} already exists`);
|
|
70
|
-
return
|
|
70
|
+
return o.devices[e][t] = s, o.$dispatchChange(s), Object.keys(o.devices[e]).indexOf(t);
|
|
71
71
|
}
|
|
72
|
-
static get(
|
|
73
|
-
return typeof
|
|
72
|
+
static get(s, e) {
|
|
73
|
+
return typeof o.devices[s] > "u" && (o.devices[s] = {}), typeof o.devices[s] > "u" && o.typeError(s), o.devices[s][e];
|
|
74
74
|
}
|
|
75
|
-
static getAll(
|
|
76
|
-
return
|
|
75
|
+
static getAll(s = null) {
|
|
76
|
+
return s === null ? o.devices : (typeof o.devices[s] > "u" && o.typeError(s), o.devices[s]);
|
|
77
77
|
}
|
|
78
78
|
static getList() {
|
|
79
|
-
return Object.values(
|
|
79
|
+
return Object.values(o.devices).map((e) => Object.values(e)).flat();
|
|
80
80
|
}
|
|
81
|
-
static getByNumber(
|
|
82
|
-
return typeof
|
|
81
|
+
static getByNumber(s, e) {
|
|
82
|
+
return typeof o.devices[s] > "u" && o.typeError(s), Object.values(o.devices[s]).find((i) => i.deviceNumber === e) ?? null;
|
|
83
83
|
}
|
|
84
|
-
static getCustom(
|
|
85
|
-
return typeof
|
|
84
|
+
static getCustom(s, e = 1) {
|
|
85
|
+
return typeof o.devices[s] > "u" && o.typeError(s), Object.values(o.devices[s]).find((i) => i.deviceNumber === e) ?? null;
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
|
-
|
|
89
|
-
let
|
|
90
|
-
|
|
88
|
+
g(o, "instance"), g(o, "devices", {});
|
|
89
|
+
let h = o;
|
|
90
|
+
h.instance || (h.instance = new h());
|
|
91
91
|
function C(l = 100) {
|
|
92
92
|
return new Promise(
|
|
93
|
-
(
|
|
93
|
+
(s) => setTimeout(() => s(), l)
|
|
94
94
|
);
|
|
95
95
|
}
|
|
96
|
-
function
|
|
96
|
+
function V() {
|
|
97
97
|
return "serial" in navigator;
|
|
98
98
|
}
|
|
99
|
-
const
|
|
99
|
+
const v = {
|
|
100
100
|
baudRate: 9600,
|
|
101
101
|
dataBits: 8,
|
|
102
102
|
stopBits: 1,
|
|
@@ -104,22 +104,25 @@ const g = {
|
|
|
104
104
|
bufferSize: 32768,
|
|
105
105
|
flowControl: "none"
|
|
106
106
|
};
|
|
107
|
-
var
|
|
108
|
-
class
|
|
107
|
+
var n, y, b, x, B, p, $, U, k, D, P, I, R, M, q, N, O, H, F;
|
|
108
|
+
class G extends L {
|
|
109
109
|
constructor({
|
|
110
110
|
filters: e = null,
|
|
111
|
-
config_port: t =
|
|
111
|
+
config_port: t = v,
|
|
112
112
|
no_device: i = 1,
|
|
113
|
-
device_listen_on_channel: r = 1
|
|
113
|
+
device_listen_on_channel: r = 1,
|
|
114
|
+
bypassSerialBytesConnection: c = !1
|
|
114
115
|
} = {
|
|
115
116
|
filters: null,
|
|
116
|
-
config_port:
|
|
117
|
+
config_port: v,
|
|
117
118
|
no_device: 1,
|
|
118
|
-
device_listen_on_channel: 1
|
|
119
|
+
device_listen_on_channel: 1,
|
|
120
|
+
bypassSerialBytesConnection: !1
|
|
119
121
|
}) {
|
|
120
122
|
super();
|
|
121
|
-
|
|
122
|
-
|
|
123
|
+
E(this, n);
|
|
124
|
+
g(this, "__internal__", {
|
|
125
|
+
bypassSerialBytesConnection: !1,
|
|
123
126
|
auto_response: !1,
|
|
124
127
|
device_number: 1,
|
|
125
128
|
aux_port_connector: 0,
|
|
@@ -136,9 +139,12 @@ class B extends x {
|
|
|
136
139
|
response: {
|
|
137
140
|
length: null,
|
|
138
141
|
buffer: new Uint8Array([]),
|
|
139
|
-
as: "
|
|
142
|
+
as: "uint8",
|
|
140
143
|
replacer: /[\n\r]+/g,
|
|
141
|
-
limiter: null
|
|
144
|
+
limiter: null,
|
|
145
|
+
prefixLimiter: !1,
|
|
146
|
+
sufixLimiter: !0,
|
|
147
|
+
delimited: !1
|
|
142
148
|
},
|
|
143
149
|
reader: null,
|
|
144
150
|
input_done: null,
|
|
@@ -150,9 +156,13 @@ class B extends x {
|
|
|
150
156
|
delay_first_connection: 200,
|
|
151
157
|
bytes_connection: null,
|
|
152
158
|
filters: [],
|
|
153
|
-
config_port:
|
|
159
|
+
config_port: v,
|
|
154
160
|
queue: [],
|
|
155
|
-
auto_response: ["DD", "DD"]
|
|
161
|
+
auto_response: ["DD", "DD"],
|
|
162
|
+
free_timeout_ms: 50,
|
|
163
|
+
// In previous versions 400 was used
|
|
164
|
+
useRTSCTS: !1
|
|
165
|
+
// Use RTS/CTS flow control
|
|
156
166
|
},
|
|
157
167
|
device: {
|
|
158
168
|
type: "unknown",
|
|
@@ -172,12 +182,12 @@ class B extends x {
|
|
|
172
182
|
});
|
|
173
183
|
if (!("serial" in navigator))
|
|
174
184
|
throw new Error("Web Serial not supported");
|
|
175
|
-
e && (this.serialFilters = e), t && (this.serialConfigPort = t), i &&
|
|
185
|
+
e && (this.serialFilters = e), t && (this.serialConfigPort = t), c && (this.__internal__.bypassSerialBytesConnection = c), i && a(this, n, H).call(this, i), r && ["number", "string"].includes(typeof r) && (this.listenOnChannel = r), a(this, n, M).call(this), a(this, n, q).call(this);
|
|
176
186
|
}
|
|
177
187
|
set listenOnChannel(e) {
|
|
178
188
|
if (typeof e == "string" && (e = parseInt(e)), isNaN(e) || e < 1 || e > 255)
|
|
179
189
|
throw new Error("Invalid port number");
|
|
180
|
-
this.__internal__.device.listen_on_port = e, this.__internal__.serial.bytes_connection = this.serialSetConnectionConstant(e);
|
|
190
|
+
this.__internal__.device.listen_on_port = e, !this.__internal__.bypassSerialBytesConnection && (this.__internal__.serial.bytes_connection = this.serialSetConnectionConstant(e));
|
|
181
191
|
}
|
|
182
192
|
get lastAction() {
|
|
183
193
|
return this.__internal__.serial.last_action;
|
|
@@ -186,24 +196,32 @@ class B extends x {
|
|
|
186
196
|
return this.__internal__.device.listen_on_port ?? 1;
|
|
187
197
|
}
|
|
188
198
|
set serialFilters(e) {
|
|
199
|
+
if (this.isConnected) throw new Error("Cannot change serial filters while connected");
|
|
189
200
|
this.__internal__.serial.filters = e;
|
|
190
201
|
}
|
|
191
202
|
get serialFilters() {
|
|
192
203
|
return this.__internal__.serial.filters;
|
|
193
204
|
}
|
|
194
205
|
set serialConfigPort(e) {
|
|
206
|
+
if (this.isConnected) throw new Error("Cannot change serial filters while connected");
|
|
195
207
|
this.__internal__.serial.config_port = e;
|
|
196
208
|
}
|
|
197
209
|
get serialConfigPort() {
|
|
198
210
|
return this.__internal__.serial.config_port;
|
|
199
211
|
}
|
|
212
|
+
get useRTSCTS() {
|
|
213
|
+
return this.__internal__.serial.useRTSCTS;
|
|
214
|
+
}
|
|
215
|
+
set useRTSCTS(e) {
|
|
216
|
+
this.__internal__.serial.useRTSCTS = e;
|
|
217
|
+
}
|
|
200
218
|
get isConnected() {
|
|
201
|
-
const e = this.__internal__.serial.connected, t =
|
|
202
|
-
return e && !t &&
|
|
219
|
+
const e = this.__internal__.serial.connected, t = a(this, n, y).call(this, this.__internal__.serial.port);
|
|
220
|
+
return e && !t && a(this, n, b).call(this, { error: "Port is closed, not readable or writable." }), this.__internal__.serial.connected = t, this.__internal__.serial.connected;
|
|
203
221
|
}
|
|
204
222
|
get isDisconnected() {
|
|
205
|
-
const e = this.__internal__.serial.connected, t =
|
|
206
|
-
return !e && t && (this.dispatch("serial:connected"),
|
|
223
|
+
const e = this.__internal__.serial.connected, t = a(this, n, y).call(this, this.__internal__.serial.port);
|
|
224
|
+
return !e && t && (this.dispatch("serial:connected"), h.$dispatchChange(this)), this.__internal__.serial.connected = t, !this.__internal__.serial.connected;
|
|
207
225
|
}
|
|
208
226
|
get deviceNumber() {
|
|
209
227
|
return this.__internal__.device_number;
|
|
@@ -217,19 +235,75 @@ class B extends x {
|
|
|
217
235
|
get queue() {
|
|
218
236
|
return this.__internal__.serial.queue;
|
|
219
237
|
}
|
|
238
|
+
get responseDelimited() {
|
|
239
|
+
return this.__internal__.serial.response.delimited;
|
|
240
|
+
}
|
|
241
|
+
set responseDelimited(e) {
|
|
242
|
+
if (typeof e != "boolean")
|
|
243
|
+
throw new Error("responseDelimited must be a boolean");
|
|
244
|
+
this.__internal__.serial.response.delimited = e;
|
|
245
|
+
}
|
|
246
|
+
get responsePrefixLimited() {
|
|
247
|
+
return this.__internal__.serial.response.prefixLimiter;
|
|
248
|
+
}
|
|
249
|
+
set responsePrefixLimited(e) {
|
|
250
|
+
if (typeof e != "boolean")
|
|
251
|
+
throw new Error("responsePrefixLimited must be a boolean");
|
|
252
|
+
this.__internal__.serial.response.prefixLimiter = e;
|
|
253
|
+
}
|
|
254
|
+
get responseSufixLimited() {
|
|
255
|
+
return this.__internal__.serial.response.sufixLimiter;
|
|
256
|
+
}
|
|
257
|
+
set responseSufixLimited(e) {
|
|
258
|
+
if (typeof e != "boolean")
|
|
259
|
+
throw new Error("responseSufixLimited must be a boolean");
|
|
260
|
+
this.__internal__.serial.response.sufixLimiter = e;
|
|
261
|
+
}
|
|
262
|
+
get responseLimiter() {
|
|
263
|
+
return this.__internal__.serial.response.limiter;
|
|
264
|
+
}
|
|
265
|
+
set responseLimiter(e) {
|
|
266
|
+
if (typeof e != "string" && !(e instanceof RegExp))
|
|
267
|
+
throw new Error("responseLimiter must be a string or a RegExp");
|
|
268
|
+
this.__internal__.serial.response.limiter = e;
|
|
269
|
+
}
|
|
270
|
+
get fixedBytesMessage() {
|
|
271
|
+
return this.__internal__.serial.response.length;
|
|
272
|
+
}
|
|
273
|
+
set fixedBytesMessage(e) {
|
|
274
|
+
if (e !== null && (typeof e != "number" || e < 1))
|
|
275
|
+
throw new Error("Invalid length for fixed bytes message");
|
|
276
|
+
this.__internal__.serial.response.length = e;
|
|
277
|
+
}
|
|
278
|
+
get timeoutBeforeResponseBytes() {
|
|
279
|
+
return this.__internal__.serial.free_timeout_ms || 50;
|
|
280
|
+
}
|
|
281
|
+
set timeoutBeforeResponseBytes(e) {
|
|
282
|
+
if (e !== void 0 && (typeof e != "number" || e < 1))
|
|
283
|
+
throw new Error("Invalid timeout for response bytes");
|
|
284
|
+
this.__internal__.serial.free_timeout_ms = e ?? 50;
|
|
285
|
+
}
|
|
286
|
+
get bypassSerialBytesConnection() {
|
|
287
|
+
return this.__internal__.bypassSerialBytesConnection;
|
|
288
|
+
}
|
|
289
|
+
set bypassSerialBytesConnection(e) {
|
|
290
|
+
if (typeof e != "boolean")
|
|
291
|
+
throw new Error("bypassSerialBytesConnection must be a boolean");
|
|
292
|
+
this.__internal__.bypassSerialBytesConnection = e;
|
|
293
|
+
}
|
|
220
294
|
async timeout(e, t) {
|
|
221
|
-
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", {}),
|
|
295
|
+
this.__internal__.last_error.message = "Operation response timed out.", this.__internal__.last_error.action = t, this.__internal__.last_error.code = e, this.__internal__.timeout.until_response && (clearTimeout(this.__internal__.timeout.until_response), this.__internal__.timeout.until_response = 0), t === "connect" ? (this.__internal__.serial.connected = !1, this.dispatch("serial:reconnect", {}), h.$dispatchChange(this)) : t === "connection:start" && (await this.serialDisconnect(), this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector += 1, h.$dispatchChange(this), await this.serialConnect()), this.dispatch("serial:timeout", {
|
|
222
296
|
...this.__internal__.last_error,
|
|
223
297
|
bytes: e,
|
|
224
298
|
action: t
|
|
225
299
|
});
|
|
226
300
|
}
|
|
227
301
|
async disconnect(e = null) {
|
|
228
|
-
await this.serialDisconnect(),
|
|
302
|
+
await this.serialDisconnect(), a(this, n, b).call(this, e);
|
|
229
303
|
}
|
|
230
304
|
async connect() {
|
|
231
|
-
return new Promise((e, t) => {
|
|
232
|
-
|
|
305
|
+
return this.isConnected ? `${this.typeDevice} device ${this.deviceNumber} already connected` : new Promise((e, t) => {
|
|
306
|
+
V() || t("Web Serial not supported"), setTimeout(async () => {
|
|
233
307
|
await C(499), await this.serialConnect(), this.isConnected ? e(`${this.typeDevice} device ${this.deviceNumber} connected`) : t(`${this.typeDevice} device ${this.deviceNumber} not connected`);
|
|
234
308
|
}, 1);
|
|
235
309
|
});
|
|
@@ -241,7 +315,7 @@ class B extends x {
|
|
|
241
315
|
} catch (e) {
|
|
242
316
|
this.serialErrors(e);
|
|
243
317
|
} finally {
|
|
244
|
-
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,
|
|
318
|
+
this.__internal__.serial.reader = null, this.__internal__.serial.input_done = null, this.__internal__.serial.output_stream = null, this.__internal__.serial.output_done = null, this.__internal__.serial.connected = !1, this.__internal__.serial.port = null, h.$dispatchChange(this);
|
|
245
319
|
}
|
|
246
320
|
}
|
|
247
321
|
getResponseAsArrayBuffer() {
|
|
@@ -281,7 +355,7 @@ class B extends x {
|
|
|
281
355
|
case t.includes(
|
|
282
356
|
"this readable stream reader has been released and cannot be used to cancel its previous owner stream"
|
|
283
357
|
):
|
|
284
|
-
this.dispatch("serial:need-permission", {}),
|
|
358
|
+
this.dispatch("serial:need-permission", {}), h.$dispatchChange(this);
|
|
285
359
|
break;
|
|
286
360
|
case t.includes("the port is already open."):
|
|
287
361
|
case t.includes("failed to open serial port"):
|
|
@@ -304,7 +378,7 @@ class B extends x {
|
|
|
304
378
|
case t.includes("the port is already closed."):
|
|
305
379
|
break;
|
|
306
380
|
case t.includes("the device has been lost"):
|
|
307
|
-
this.dispatch("serial:lost", {}),
|
|
381
|
+
this.dispatch("serial:lost", {}), h.$dispatchChange(this);
|
|
308
382
|
break;
|
|
309
383
|
case t.includes("navigator.serial is undefined"):
|
|
310
384
|
this.dispatch("serial:unsupported", {});
|
|
@@ -318,7 +392,7 @@ class B extends x {
|
|
|
318
392
|
async serialConnect() {
|
|
319
393
|
try {
|
|
320
394
|
this.dispatch("serial:connecting", {});
|
|
321
|
-
const e = await
|
|
395
|
+
const e = await a(this, n, $).call(this);
|
|
322
396
|
if (e.length > 0)
|
|
323
397
|
await this.serialPortsSaved(e);
|
|
324
398
|
else {
|
|
@@ -333,21 +407,21 @@ class B extends x {
|
|
|
333
407
|
await t.open(this.serialConfigPort);
|
|
334
408
|
const i = this;
|
|
335
409
|
t.onconnect = (r) => {
|
|
336
|
-
console.log(r), i.dispatch("serial:connected", r),
|
|
410
|
+
console.log(r), i.dispatch("serial:connected", r), h.$dispatchChange(this), i.__internal__.serial.queue.length > 0 && i.dispatch("internal:queue", {});
|
|
337
411
|
}, t.ondisconnect = async () => {
|
|
338
412
|
await i.disconnect();
|
|
339
413
|
}, await C(this.__internal__.serial.delay_first_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
|
|
340
414
|
await i.timeout(i.__internal__.serial.bytes_connection ?? [], "connection:start");
|
|
341
|
-
}, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await
|
|
415
|
+
}, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await a(this, n, x).call(this, this.__internal__.serial.bytes_connection ?? []), this.dispatch("serial:sent", {
|
|
342
416
|
action: "connect",
|
|
343
417
|
bytes: this.__internal__.serial.bytes_connection
|
|
344
|
-
}), this.__internal__.auto_response &&
|
|
418
|
+
}), this.__internal__.auto_response && a(this, n, p).call(this, this.__internal__.serial.auto_response), await a(this, n, I).call(this);
|
|
345
419
|
} catch (e) {
|
|
346
420
|
this.serialErrors(e);
|
|
347
421
|
}
|
|
348
422
|
}
|
|
349
423
|
async serialForget() {
|
|
350
|
-
return await
|
|
424
|
+
return await a(this, n, R).call(this);
|
|
351
425
|
}
|
|
352
426
|
decToHex(e) {
|
|
353
427
|
return typeof e == "string" && (e = parseInt(e, 10)), e.toString(16);
|
|
@@ -367,8 +441,22 @@ class B extends x {
|
|
|
367
441
|
bytesToHex(e) {
|
|
368
442
|
return this.add0x(Array.from(e, (t) => this.hexMaker(t)));
|
|
369
443
|
}
|
|
444
|
+
validateBytes(e) {
|
|
445
|
+
let t = new Uint8Array(0);
|
|
446
|
+
if (e instanceof Uint8Array)
|
|
447
|
+
t = e;
|
|
448
|
+
else if (typeof e == "string")
|
|
449
|
+
t = this.parseStringToTextEncoder(e);
|
|
450
|
+
else if (Array.isArray(e) && typeof e[0] == "string")
|
|
451
|
+
t = this.stringArrayToUint8Array(e);
|
|
452
|
+
else if (Array.isArray(e) && typeof e[0] == "number")
|
|
453
|
+
t = new Uint8Array(e);
|
|
454
|
+
else
|
|
455
|
+
throw new Error("Invalid data type");
|
|
456
|
+
return t;
|
|
457
|
+
}
|
|
370
458
|
async appendToQueue(e, t) {
|
|
371
|
-
const i = this.
|
|
459
|
+
const i = this.validateBytes(e);
|
|
372
460
|
if (["connect", "connection:start"].includes(t)) {
|
|
373
461
|
if (this.__internal__.serial.connected) return;
|
|
374
462
|
await this.serialConnect();
|
|
@@ -377,13 +465,14 @@ class B extends x {
|
|
|
377
465
|
this.__internal__.serial.queue.push({ bytes: i, action: t }), this.dispatch("internal:queue", {});
|
|
378
466
|
}
|
|
379
467
|
serialSetConnectionConstant(e = 1) {
|
|
380
|
-
|
|
468
|
+
if (this.__internal__.bypassSerialBytesConnection) return this.__internal__.serial.bytes_connection;
|
|
469
|
+
throw console.warn("wtf?", this.bypassSerialBytesConnection), new Error(`Method not implemented 'serialSetConnectionConstant' to listen on channel ${e}`);
|
|
381
470
|
}
|
|
382
471
|
serialMessage(e) {
|
|
383
|
-
throw console.log(e), new Error("Method not implemented 'serialMessage'");
|
|
472
|
+
throw console.log(e), this.dispatch("serial:message", { code: e }), new Error("Method not implemented 'serialMessage'");
|
|
384
473
|
}
|
|
385
|
-
serialCorruptMessage(e
|
|
386
|
-
throw console.log(e,
|
|
474
|
+
serialCorruptMessage(e) {
|
|
475
|
+
throw console.log(e), this.dispatch("serial:corrupt-message", { code: e }), new Error("Method not implemented 'serialCorruptMessage'");
|
|
387
476
|
}
|
|
388
477
|
clearSerialQueue() {
|
|
389
478
|
this.__internal__.serial.queue = [];
|
|
@@ -404,18 +493,17 @@ class B extends x {
|
|
|
404
493
|
});
|
|
405
494
|
}
|
|
406
495
|
softReload() {
|
|
407
|
-
|
|
496
|
+
a(this, n, F).call(this), this.dispatch("serial:soft-reload", {});
|
|
408
497
|
}
|
|
409
498
|
async sendConnect() {
|
|
410
499
|
if (!this.__internal__.serial.bytes_connection)
|
|
411
500
|
throw new Error("No connection bytes defined");
|
|
412
501
|
await this.appendToQueue(this.__internal__.serial.bytes_connection, "connect");
|
|
413
502
|
}
|
|
414
|
-
// @ts-expect-error code is required but can be empty
|
|
415
503
|
async sendCustomCode({ code: e = [] } = { code: [] }) {
|
|
416
|
-
if (e
|
|
504
|
+
if (!e)
|
|
417
505
|
throw new Error("No data to send");
|
|
418
|
-
await this.appendToQueue(e, "custom");
|
|
506
|
+
this.__internal__.bypassSerialBytesConnection && (this.__internal__.serial.bytes_connection = this.validateBytes(e)), await this.appendToQueue(e, "custom");
|
|
419
507
|
}
|
|
420
508
|
stringToArrayHex(e) {
|
|
421
509
|
return Array.from(e).map((t) => t.charCodeAt(0).toString(16));
|
|
@@ -442,14 +530,14 @@ class B extends x {
|
|
|
442
530
|
}
|
|
443
531
|
stringArrayToUint8Array(e) {
|
|
444
532
|
const t = [];
|
|
445
|
-
return e.forEach((i) => {
|
|
533
|
+
return typeof e == "string" ? this.parseStringToTextEncoder(e).buffer : (e.forEach((i) => {
|
|
446
534
|
const r = i.replace("0x", "");
|
|
447
535
|
t.push(parseInt(r, 16));
|
|
448
|
-
}), new Uint8Array(t);
|
|
536
|
+
}), new Uint8Array(t));
|
|
449
537
|
}
|
|
450
538
|
parseUint8ArrayToString(e) {
|
|
451
|
-
|
|
452
|
-
e = this.parseUint8ToHex(t);
|
|
539
|
+
let t = new Uint8Array(0);
|
|
540
|
+
e instanceof Uint8Array ? t = e : t = this.stringArrayToUint8Array(e), e = this.parseUint8ToHex(t);
|
|
453
541
|
const i = e.map((r) => parseInt(r, 16));
|
|
454
542
|
return this.__internal__.serial.response.replacer ? String.fromCharCode(...i).replace(this.__internal__.serial.response.replacer, "") : String.fromCharCode(...i);
|
|
455
543
|
}
|
|
@@ -472,121 +560,147 @@ class B extends x {
|
|
|
472
560
|
return this.isConnected;
|
|
473
561
|
}
|
|
474
562
|
}
|
|
475
|
-
|
|
563
|
+
n = new WeakSet(), y = function(e) {
|
|
476
564
|
return !!(e && e.readable && e.writable);
|
|
477
|
-
},
|
|
478
|
-
this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector = 0, this.dispatch("serial:disconnected", e),
|
|
479
|
-
},
|
|
565
|
+
}, b = function(e = null) {
|
|
566
|
+
this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector = 0, this.dispatch("serial:disconnected", e), h.$dispatchChange(this);
|
|
567
|
+
}, x = async function(e) {
|
|
480
568
|
const t = this.__internal__.serial.port;
|
|
481
569
|
if (!t || t && (!t.readable || !t.writable))
|
|
482
|
-
throw
|
|
483
|
-
const i = this.
|
|
484
|
-
if (t.writable === null) return;
|
|
570
|
+
throw a(this, n, b).call(this, { error: "Port is closed, not readable or writable." }), new Error("The port is closed or is not readable/writable");
|
|
571
|
+
const i = this.validateBytes(e);
|
|
572
|
+
if (this.useRTSCTS && await a(this, n, B).call(this, t, 5e3), t.writable === null) return;
|
|
485
573
|
const r = t.writable.getWriter();
|
|
486
574
|
await r.write(i), r.releaseLock();
|
|
487
|
-
},
|
|
575
|
+
}, B = async function(e, t = 5e3) {
|
|
576
|
+
const i = Date.now();
|
|
577
|
+
for (; ; ) {
|
|
578
|
+
if (Date.now() - i > t)
|
|
579
|
+
throw new Error("Timeout waiting for clearToSend signal");
|
|
580
|
+
const { clearToSend: r } = await e.getSignals();
|
|
581
|
+
if (r) return;
|
|
582
|
+
await C(100);
|
|
583
|
+
}
|
|
584
|
+
}, p = function(e = new Uint8Array([]), t = !1) {
|
|
488
585
|
if (e && e.length > 0) {
|
|
489
586
|
const i = this.__internal__.serial.connected;
|
|
490
|
-
this.__internal__.serial.connected =
|
|
491
|
-
|
|
492
|
-
for (const c in e)
|
|
493
|
-
r.push(e[c].toString().padStart(2, "0").toLowerCase());
|
|
494
|
-
if (this.__internal__.serial.response.as === "hex")
|
|
495
|
-
this.serialMessage(r);
|
|
587
|
+
if (this.__internal__.serial.connected = a(this, n, y).call(this, this.__internal__.serial.port), h.$dispatchChange(this), !i && this.__internal__.serial.connected && this.dispatch("serial:connected"), this.__internal__.interval.reconnection && (clearInterval(this.__internal__.interval.reconnection), this.__internal__.interval.reconnection = 0), this.__internal__.timeout.until_response && (clearTimeout(this.__internal__.timeout.until_response), this.__internal__.timeout.until_response = 0), this.__internal__.serial.response.as === "hex")
|
|
588
|
+
t ? this.serialCorruptMessage(this.parseUint8ToHex(e)) : this.serialMessage(this.parseUint8ToHex(e));
|
|
496
589
|
else if (this.__internal__.serial.response.as === "uint8")
|
|
497
|
-
this.
|
|
498
|
-
else if (this.__internal__.serial.response.as === "string")
|
|
590
|
+
t ? this.serialCorruptMessage(e) : this.serialMessage(e);
|
|
591
|
+
else if (this.__internal__.serial.response.as === "string") {
|
|
592
|
+
const r = this.parseUint8ArrayToString(e);
|
|
499
593
|
if (this.__internal__.serial.response.limiter !== null) {
|
|
500
|
-
const
|
|
501
|
-
for (const
|
|
502
|
-
|
|
594
|
+
const c = r.split(this.__internal__.serial.response.limiter);
|
|
595
|
+
for (const _ in c)
|
|
596
|
+
c[_] && (t ? this.serialCorruptMessage(c[_]) : this.serialMessage(c[_]));
|
|
503
597
|
} else
|
|
504
|
-
this.
|
|
505
|
-
else {
|
|
506
|
-
const
|
|
507
|
-
|
|
508
|
-
);
|
|
509
|
-
this.serialMessage(c);
|
|
598
|
+
t ? this.serialCorruptMessage(r) : this.serialMessage(r);
|
|
599
|
+
} else {
|
|
600
|
+
const r = this.stringToArrayBuffer(this.parseUint8ArrayToString(e));
|
|
601
|
+
t ? this.serialCorruptMessage(r) : this.serialMessage(r);
|
|
510
602
|
}
|
|
511
|
-
}
|
|
512
|
-
this.serialCorruptMessage(e, t);
|
|
603
|
+
}
|
|
513
604
|
this.__internal__.serial.queue.length !== 0 && this.dispatch("internal:queue", {});
|
|
514
|
-
},
|
|
605
|
+
}, $ = async function() {
|
|
515
606
|
const e = this.serialFilters, t = await navigator.serial.getPorts({ filters: e });
|
|
516
607
|
return e.length === 0 ? t : t.filter((r) => {
|
|
517
608
|
const c = r.getInfo();
|
|
518
|
-
return e.some((
|
|
519
|
-
}).filter((r) => !
|
|
520
|
-
},
|
|
609
|
+
return e.some((_) => c.usbProductId === _.usbProductId && c.usbVendorId === _.usbVendorId);
|
|
610
|
+
}).filter((r) => !a(this, n, y).call(this, r));
|
|
611
|
+
}, U = function(e) {
|
|
521
612
|
if (e) {
|
|
522
613
|
const t = this.__internal__.serial.response.buffer, i = new Uint8Array(t.length + e.byteLength);
|
|
523
614
|
i.set(t, 0), i.set(new Uint8Array(e), t.length), this.__internal__.serial.response.buffer = i;
|
|
524
615
|
}
|
|
525
|
-
},
|
|
616
|
+
}, k = async function() {
|
|
526
617
|
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(() => {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
618
|
+
this.__internal__.serial.response.buffer && a(this, n, p).call(this, this.__internal__.serial.response.buffer), this.__internal__.serial.response.buffer = new Uint8Array(0);
|
|
619
|
+
}, this.__internal__.serial.free_timeout_ms || 50);
|
|
620
|
+
}, D = async function() {
|
|
621
|
+
const e = this.__internal__.serial.response.length;
|
|
622
|
+
let t = this.__internal__.serial.response.buffer;
|
|
623
|
+
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)) {
|
|
624
|
+
for (; t.length >= e; ) {
|
|
625
|
+
const i = t.slice(0, e);
|
|
626
|
+
a(this, n, p).call(this, i), t = t.slice(e);
|
|
627
|
+
}
|
|
628
|
+
this.__internal__.serial.response.buffer = t, t.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
629
|
+
a(this, n, p).call(this, this.__internal__.serial.response.buffer, !0);
|
|
630
|
+
}, this.__internal__.serial.free_timeout_ms || 50));
|
|
631
|
+
}
|
|
632
|
+
}, P = async function() {
|
|
633
|
+
const {
|
|
634
|
+
limiter: e,
|
|
635
|
+
prefixLimiter: t = !1,
|
|
636
|
+
sufixLimiter: i = !0
|
|
637
|
+
} = this.__internal__.serial.response;
|
|
638
|
+
if (!e)
|
|
639
|
+
throw new Error("No limiter defined for delimited serial response");
|
|
640
|
+
const r = this.__internal__.serial.response.buffer;
|
|
641
|
+
if (!e || !r || r.length === 0) return;
|
|
642
|
+
this.__internal__.serial.time_until_send_bytes && (clearTimeout(this.__internal__.serial.time_until_send_bytes), this.__internal__.serial.time_until_send_bytes = 0);
|
|
643
|
+
let _ = new TextDecoder().decode(r);
|
|
644
|
+
const m = [];
|
|
645
|
+
if (typeof e == "string") {
|
|
646
|
+
let u;
|
|
647
|
+
if (t && i)
|
|
648
|
+
u = new RegExp(`${e}([^${e}]+)${e}`, "g");
|
|
649
|
+
else if (t)
|
|
650
|
+
u = new RegExp(`${e}([^${e}]*)`, "g");
|
|
651
|
+
else if (i)
|
|
652
|
+
u = new RegExp(`([^${e}]+)${e}`, "g");
|
|
653
|
+
else
|
|
654
|
+
return;
|
|
655
|
+
let f, d = 0;
|
|
656
|
+
for (; (f = u.exec(_)) !== null; )
|
|
657
|
+
m.push(new TextEncoder().encode(f[1])), d = u.lastIndex;
|
|
658
|
+
_ = _.slice(d);
|
|
659
|
+
} else if (e instanceof RegExp) {
|
|
660
|
+
let u, f = 0;
|
|
661
|
+
if (t && i) {
|
|
662
|
+
const d = new RegExp(`${e.source}(.*?)${e.source}`, "g");
|
|
663
|
+
for (; (u = d.exec(_)) !== null; )
|
|
664
|
+
m.push(new TextEncoder().encode(u[1])), f = d.lastIndex;
|
|
665
|
+
} else if (i)
|
|
666
|
+
for (; (u = e.exec(_)) !== null; ) {
|
|
667
|
+
const d = u.index, w = _.slice(f, d);
|
|
668
|
+
m.push(new TextEncoder().encode(w)), f = e.lastIndex;
|
|
561
669
|
}
|
|
670
|
+
else if (t) {
|
|
671
|
+
const d = _.split(e);
|
|
672
|
+
d.shift();
|
|
673
|
+
for (const w of d)
|
|
674
|
+
m.push(new TextEncoder().encode(w));
|
|
675
|
+
_ = "";
|
|
562
676
|
}
|
|
563
|
-
|
|
564
|
-
}
|
|
677
|
+
_ = _.slice(f);
|
|
678
|
+
}
|
|
679
|
+
for (const u of m)
|
|
680
|
+
a(this, n, p).call(this, u);
|
|
681
|
+
const S = new TextEncoder().encode(_);
|
|
682
|
+
this.__internal__.serial.response.buffer = S, S.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
683
|
+
a(this, n, p).call(this, this.__internal__.serial.response.buffer, !0), this.__internal__.serial.response.buffer = new Uint8Array(0);
|
|
684
|
+
}, this.__internal__.serial.free_timeout_ms ?? 50));
|
|
685
|
+
}, I = async function() {
|
|
565
686
|
const e = this.__internal__.serial.port;
|
|
566
687
|
if (!e || !e.readable) throw new Error("Port is not readable");
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
if (c) {
|
|
575
|
-
t.releaseLock(), this.__internal__.serial.keep_reading = !1, i = !1;
|
|
576
|
-
break;
|
|
577
|
-
}
|
|
578
|
-
o(this, s, A).call(this, r), this.__internal__.serial.response.length === null ? await o(this, s, E).call(this) : await o(this, s, T).call(this);
|
|
579
|
-
}
|
|
580
|
-
} catch (i) {
|
|
581
|
-
this.serialErrors(i);
|
|
582
|
-
} finally {
|
|
583
|
-
t.releaseLock();
|
|
688
|
+
const t = e.readable.getReader();
|
|
689
|
+
this.__internal__.serial.reader = t;
|
|
690
|
+
try {
|
|
691
|
+
for (; this.__internal__.serial.keep_reading; ) {
|
|
692
|
+
const { value: i, done: r } = await t.read();
|
|
693
|
+
if (r) break;
|
|
694
|
+
a(this, n, U).call(this, i), this.__internal__.serial.response.delimited ? await a(this, n, P).call(this) : this.__internal__.serial.response.length === null ? await a(this, n, k).call(this) : await a(this, n, D).call(this);
|
|
584
695
|
}
|
|
696
|
+
} catch (i) {
|
|
697
|
+
this.serialErrors(i);
|
|
698
|
+
} finally {
|
|
699
|
+
t.releaseLock(), this.__internal__.serial.keep_reading = !0, this.__internal__.serial.port && await this.__internal__.serial.port.close();
|
|
585
700
|
}
|
|
586
|
-
|
|
587
|
-
}, U = async function() {
|
|
701
|
+
}, R = async function() {
|
|
588
702
|
return typeof window > "u" ? !1 : "serial" in navigator && "forget" in SerialPort.prototype && this.__internal__.serial.port ? (await this.__internal__.serial.port.forget(), !0) : !1;
|
|
589
|
-
},
|
|
703
|
+
}, M = function() {
|
|
590
704
|
[
|
|
591
705
|
"serial:connected",
|
|
592
706
|
"serial:connecting",
|
|
@@ -596,6 +710,7 @@ s = new WeakSet(), p = function(e) {
|
|
|
596
710
|
"serial:sent",
|
|
597
711
|
"serial:soft-reload",
|
|
598
712
|
"serial:message",
|
|
713
|
+
"serial:corrupt-message",
|
|
599
714
|
"unknown",
|
|
600
715
|
"serial:need-permission",
|
|
601
716
|
"serial:lost",
|
|
@@ -605,37 +720,45 @@ s = new WeakSet(), p = function(e) {
|
|
|
605
720
|
].forEach((t) => {
|
|
606
721
|
this.serialRegisterAvailableListener(t);
|
|
607
722
|
});
|
|
608
|
-
},
|
|
723
|
+
}, q = function() {
|
|
609
724
|
const e = this;
|
|
610
725
|
this.on("internal:queue", async () => {
|
|
611
726
|
var t;
|
|
612
|
-
await
|
|
613
|
-
}),
|
|
614
|
-
},
|
|
727
|
+
await a(t = e, n, O).call(t);
|
|
728
|
+
}), a(this, n, N).call(this);
|
|
729
|
+
}, N = function() {
|
|
615
730
|
const e = this;
|
|
616
731
|
navigator.serial.addEventListener("connect", async () => {
|
|
617
732
|
e.isDisconnected && await e.serialConnect().catch(() => {
|
|
618
733
|
});
|
|
619
734
|
});
|
|
620
|
-
},
|
|
621
|
-
if (!
|
|
622
|
-
|
|
735
|
+
}, O = async function() {
|
|
736
|
+
if (!a(this, n, y).call(this, this.__internal__.serial.port)) {
|
|
737
|
+
a(this, n, b).call(this, { error: "Port is closed, not readable or writable." }), await this.serialConnect();
|
|
623
738
|
return;
|
|
624
739
|
}
|
|
625
740
|
if (this.__internal__.timeout.until_response || this.__internal__.serial.queue.length === 0) return;
|
|
626
741
|
const e = this.__internal__.serial.queue[0];
|
|
627
742
|
let t = this.__internal__.time.response_general;
|
|
628
|
-
e.action === "connect" && (t = this.__internal__.time.response_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
|
|
743
|
+
if (e.action === "connect" && (t = this.__internal__.time.response_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
|
|
629
744
|
await this.timeout(e.bytes, e.action);
|
|
630
|
-
}, t), this.__internal__.serial.last_action = e.action ?? "unknown", await
|
|
745
|
+
}, t), this.__internal__.serial.last_action = e.action ?? "unknown", await a(this, n, x).call(this, e.bytes), this.dispatch("serial:sent", {
|
|
631
746
|
action: e.action,
|
|
632
747
|
bytes: e.bytes
|
|
633
|
-
}), this.__internal__.auto_response
|
|
748
|
+
}), this.__internal__.auto_response) {
|
|
749
|
+
let r = new Uint8Array(0);
|
|
750
|
+
try {
|
|
751
|
+
r = this.validateBytes(this.__internal__.serial.auto_response);
|
|
752
|
+
} catch (c) {
|
|
753
|
+
this.serialErrors(c);
|
|
754
|
+
}
|
|
755
|
+
a(this, n, p).call(this, r);
|
|
756
|
+
}
|
|
634
757
|
const i = [...this.__internal__.serial.queue];
|
|
635
758
|
this.__internal__.serial.queue = i.splice(1);
|
|
636
|
-
},
|
|
637
|
-
this.__internal__.device_number = e, this.__internal__.serial.bytes_connection = this.serialSetConnectionConstant(e);
|
|
638
|
-
},
|
|
759
|
+
}, H = function(e = 1) {
|
|
760
|
+
this.__internal__.device_number = e, !this.__internal__.bypassSerialBytesConnection && (this.__internal__.serial.bytes_connection = this.serialSetConnectionConstant(e));
|
|
761
|
+
}, F = function() {
|
|
639
762
|
this.__internal__.last_error = {
|
|
640
763
|
message: null,
|
|
641
764
|
action: null,
|
|
@@ -644,7 +767,7 @@ s = new WeakSet(), p = function(e) {
|
|
|
644
767
|
};
|
|
645
768
|
};
|
|
646
769
|
export {
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
770
|
+
G as Core,
|
|
771
|
+
h as Devices,
|
|
772
|
+
L as Dispatcher
|
|
650
773
|
};
|
|
@@ -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 H=Object.defineProperty;var x=l=>{throw TypeError(l)};var R=(l,_,h)=>_ in l?H(l,_,{enumerable:!0,configurable:!0,writable:!0,value:h}):l[_]=h;var f=(l,_,h)=>R(l,typeof _!="symbol"?_+"":_,h),j=(l,_,h)=>_.has(l)||x("Cannot "+h);var S=(l,_,h)=>_.has(l)?x("Cannot add the same private member more than once"):_ instanceof WeakSet?_.add(l):_.set(l,h);var o=(l,_,h)=>(j(l,_,"access private method"),h);var n,g,b,m,d,A,T,E,k,U,P,L,D,$,q,I,M;class _ extends CustomEvent{constructor(r,e){super(r,e)}}class h extends EventTarget{constructor(){super(...arguments);f(this,"__listeners__",{debug:!1});f(this,"__debug__",!1)}dispatch(e,t=null){const i=new _(e,{detail:t});this.dispatchEvent(i),this.__debug__&&this.dispatchEvent(new _("debug",{detail:{type:e,data:t}}))}dispatchAsync(e,t=null,i=100){const s=this;setTimeout(()=>{s.dispatch(e,t)},i)}on(e,t){typeof this.__listeners__[e]<"u"&&!this.__listeners__[e]&&(this.__listeners__[e]=!0),this.addEventListener(e,t)}off(e,t){this.removeEventListener(e,t)}serialRegisterAvailableListener(e){this.__listeners__[e]||(this.__listeners__[e]=!1)}get availableListeners(){return Object.keys(this.__listeners__).sort().map(t=>({type:t,listening:this.__listeners__[t]}))}}const a=class a extends h{constructor(){super(),["change"].forEach(e=>{this.serialRegisterAvailableListener(e)})}static $dispatchChange(r=null){r&&r.$checkAndDispatchConnection(),a.instance.dispatch("change",{devices:a.devices,dispatcher:r})}static typeError(r){const e=new Error;throw e.message=`Type ${r} is not supported`,e.name="DeviceTypeError",e}static registerType(r){typeof a.devices[r]>"u"&&(a.devices[r]={})}static add(r){const e=r.typeDevice;typeof a.devices[e]>"u"&&(a.devices[e]={});const t=r.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]=r,a.$dispatchChange(r),Object.keys(a.devices[e]).indexOf(t)}static get(r,e){return typeof a.devices[r]>"u"&&(a.devices[r]={}),typeof a.devices[r]>"u"&&a.typeError(r),a.devices[r][e]}static getAll(r=null){return r===null?a.devices:(typeof a.devices[r]>"u"&&a.typeError(r),a.devices[r])}static getList(){return Object.values(a.devices).map(e=>Object.values(e)).flat()}static getByNumber(r,e){return typeof a.devices[r]>"u"&&a.typeError(r),Object.values(a.devices[r]).find(i=>i.deviceNumber===e)??null}static getCustom(r,e=1){return typeof a.devices[r]>"u"&&a.typeError(r),Object.values(a.devices[r]).find(i=>i.deviceNumber===e)??null}};f(a,"instance"),f(a,"devices",{});let c=a;c.instance||(c.instance=new c);function v(y=100){return new Promise(r=>setTimeout(()=>r(),y))}function N(){return"serial"in navigator}const w={baudRate:9600,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"};class O extends h{constructor({filters:e=null,config_port:t=w,no_device:i=1,device_listen_on_channel:s=1}={filters:null,config_port:w,no_device:1,device_listen_on_channel:1}){super();S(this,n);f(this,"__internal__",{auto_response:!1,device_number:1,aux_port_connector:0,last_error:{message:null,action:null,code:null,no_code:0},serial:{connected:!1,port:null,last_action:null,response:{length:null,buffer:new Uint8Array([]),as:"hex",replacer:/[\n\r]+/g,limiter:null},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:w,queue:[],auto_response:["DD","DD"]},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),i&&o(this,n,I).call(this,i),s&&["number","string"].includes(typeof s)&&(this.listenOnChannel=s),o(this,n,L).call(this),o(this,n,D).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__.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){this.__internal__.serial.filters=e}get serialFilters(){return this.__internal__.serial.filters}set serialConfigPort(e){this.__internal__.serial.config_port=e}get serialConfigPort(){return this.__internal__.serial.config_port}get isConnected(){const e=this.__internal__.serial.connected,t=o(this,n,g).call(this,this.__internal__.serial.port);return e&&!t&&o(this,n,b).call(this,{error:"Port is closed, not readable or writable."}),this.__internal__.serial.connected=t,this.__internal__.serial.connected}get isDisconnected(){const e=this.__internal__.serial.connected,t=o(this,n,g).call(this,this.__internal__.serial.port);return!e&&t&&(this.dispatch("serial:connected"),c.$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}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",{}),c.$dispatchChange(this)):t==="connection:start"&&(await this.serialDisconnect(),this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector+=1,c.$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,b).call(this,e)}async connect(){return new Promise((e,t)=>{N()||t("Web Serial not supported"),setTimeout(async()=>{await v(499),await this.serialConnect(),this.isConnected?e(`${this.typeDevice} device ${this.deviceNumber} connected`):t(`${this.typeDevice} device ${this.deviceNumber} not connected`)},1)})}async serialDisconnect(){try{const e=this.__internal__.serial.reader,t=this.__internal__.serial.output_stream;e&&(await e.cancel().catch(s=>this.serialErrors(s)),await this.__internal__.serial.input_done),t&&(await t.getWriter().close(),await this.__internal__.serial.output_done),this.__internal__.serial.connected&&this.__internal__.serial&&this.__internal__.serial.port&&await this.__internal__.serial.port.close()}catch(e){this.serialErrors(e)}finally{this.__internal__.serial.reader=null,this.__internal__.serial.input_done=null,this.__internal__.serial.output_stream=null,this.__internal__.serial.output_done=null,this.__internal__.serial.connected=!1,this.__internal__.serial.port=null,c.$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",{}),c.$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",{}),c.$dispatchChange(this);break;case t.includes("navigator.serial is undefined"):this.dispatch("serial:unsupported",{});break;default:console.error(e);break}this.dispatch("serial:error",e)}async serialConnect(){try{this.dispatch("serial:connecting",{});const e=await o(this,n,A).call(this);if(e.length>0)await this.serialPortsSaved(e);else{const s=this.serialFilters;this.__internal__.serial.port=await navigator.serial.requestPort({filters:s})}const t=this.__internal__.serial.port;if(!t)throw new Error("No port selected by the user");await t.open(this.serialConfigPort);const i=this;t.onconnect=s=>{console.log(s),i.dispatch("serial:connected",s),c.$dispatchChange(this),i.__internal__.serial.queue.length>0&&i.dispatch("internal:queue",{})},t.ondisconnect=async()=>{await i.disconnect()},await v(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,m).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,d).call(this,this.__internal__.serial.auto_response,null),await o(this,n,U).call(this)}catch(e){this.serialErrors(e)}}async serialForget(){return await o(this,n,P).call(this)}decToHex(e){return typeof e=="string"&&(e=parseInt(e,10)),e.toString(16)}hexToDec(e){return parseInt(e,16)}hexMaker(e="00",t=2){return e.toString().padStart(t,"0").toLowerCase()}add0x(e){const t=[];return e.forEach((i,s)=>{t[s]="0x"+i}),t}bytesToHex(e){return this.add0x(Array.from(e,t=>this.hexMaker(t)))}async appendToQueue(e,t){const i=this.bytesToHex(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){throw new Error(`Method not implemented 'serialSetConnectionConstant' to listen on channel ${e}`)}serialMessage(e){throw console.log(e),new Error("Method not implemented 'serialMessage'")}serialCorruptMessage(e,t){throw console.log(e,t),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,M).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===null||e.length===0)throw new Error("No data to send");await this.appendToQueue(e,"custom")}stringToArrayHex(e){return Array.from(e).map(t=>t.charCodeAt(0).toString(16))}stringToArrayBuffer(e,t=`
|
|
1
|
+
(function(l,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(l=typeof globalThis<"u"?globalThis:l||self,_(l.WebSerialCore={}))})(this,function(l){"use strict";var V=Object.defineProperty;var L=l=>{throw TypeError(l)};var z=(l,_,d)=>_ in l?V(l,_,{enumerable:!0,configurable:!0,writable:!0,value:d}):l[_]=d;var m=(l,_,d)=>z(l,typeof _!="symbol"?_+"":_,d),G=(l,_,d)=>_.has(l)||L("Cannot "+d);var B=(l,_,d)=>_.has(l)?L("Cannot add the same private member more than once"):_ instanceof WeakSet?_.add(l):_.set(l,d);var a=(l,_,d)=>(G(l,_,"access private method"),d);var s,b,C,E,$,g,D,U,k,P,I,R,M,q,N,O,H,F,j;class _ extends CustomEvent{constructor(r,e){super(r,e)}}class d extends EventTarget{constructor(){super(...arguments);m(this,"__listeners__",{debug:!1});m(this,"__debug__",!1)}dispatch(e,t=null){const i=new _(e,{detail:t});this.dispatchEvent(i),this.__debug__&&this.dispatchEvent(new _("debug",{detail:{type:e,data:t}}))}dispatchAsync(e,t=null,i=100){const n=this;setTimeout(()=>{n.dispatch(e,t)},i)}on(e,t){typeof this.__listeners__[e]<"u"&&!this.__listeners__[e]&&(this.__listeners__[e]=!0),this.addEventListener(e,t)}off(e,t){this.removeEventListener(e,t)}serialRegisterAvailableListener(e){this.__listeners__[e]||(this.__listeners__[e]=!1)}get availableListeners(){return Object.keys(this.__listeners__).sort().map(t=>({type:t,listening:this.__listeners__[t]}))}}const o=class o extends d{constructor(){super(),["change"].forEach(e=>{this.serialRegisterAvailableListener(e)})}static $dispatchChange(r=null){r&&r.$checkAndDispatchConnection(),o.instance.dispatch("change",{devices:o.devices,dispatcher:r})}static typeError(r){const e=new Error;throw e.message=`Type ${r} is not supported`,e.name="DeviceTypeError",e}static registerType(r){typeof o.devices[r]>"u"&&(o.devices[r]={})}static add(r){const e=r.typeDevice;typeof o.devices[e]>"u"&&(o.devices[e]={});const t=r.uuid;if(typeof o.devices[e]>"u"&&o.typeError(e),o.devices[e][t])throw new Error(`Device with id ${t} already exists`);return o.devices[e][t]=r,o.$dispatchChange(r),Object.keys(o.devices[e]).indexOf(t)}static get(r,e){return typeof o.devices[r]>"u"&&(o.devices[r]={}),typeof o.devices[r]>"u"&&o.typeError(r),o.devices[r][e]}static getAll(r=null){return r===null?o.devices:(typeof o.devices[r]>"u"&&o.typeError(r),o.devices[r])}static getList(){return Object.values(o.devices).map(e=>Object.values(e)).flat()}static getByNumber(r,e){return typeof o.devices[r]>"u"&&o.typeError(r),Object.values(o.devices[r]).find(i=>i.deviceNumber===e)??null}static getCustom(r,e=1){return typeof o.devices[r]>"u"&&o.typeError(r),Object.values(o.devices[r]).find(i=>i.deviceNumber===e)??null}};m(o,"instance"),m(o,"devices",{});let h=o;h.instance||(h.instance=new h);function x(v=100){return new Promise(r=>setTimeout(()=>r(),v))}function W(){return"serial"in navigator}const S={baudRate:9600,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"};class Q extends d{constructor({filters:e=null,config_port:t=S,no_device:i=1,device_listen_on_channel:n=1,bypassSerialBytesConnection:u=!1}={filters:null,config_port:S,no_device:1,device_listen_on_channel:1,bypassSerialBytesConnection:!1}){super();B(this,s);m(this,"__internal__",{bypassSerialBytesConnection:!1,auto_response:!1,device_number:1,aux_port_connector:0,last_error:{message:null,action:null,code:null,no_code:0},serial:{connected:!1,port:null,last_action:null,response:{length:null,buffer:new Uint8Array([]),as:"uint8",replacer:/[\n\r]+/g,limiter:null,prefixLimiter:!1,sufixLimiter:!0,delimited:!1},reader:null,input_done:null,output_done:null,input_stream:null,output_stream:null,keep_reading:!0,time_until_send_bytes:void 0,delay_first_connection:200,bytes_connection:null,filters:[],config_port:S,queue:[],auto_response:["DD","DD"],free_timeout_ms:50,useRTSCTS:!1},device:{type:"unknown",id:window.crypto.randomUUID(),listen_on_port:null},time:{response_connection:500,response_general:2e3},timeout:{until_response:0},interval:{reconnection:0}});if(!("serial"in navigator))throw new Error("Web Serial not supported");e&&(this.serialFilters=e),t&&(this.serialConfigPort=t),u&&(this.__internal__.bypassSerialBytesConnection=u),i&&a(this,s,F).call(this,i),n&&["number","string"].includes(typeof n)&&(this.listenOnChannel=n),a(this,s,q).call(this),a(this,s,N).call(this)}set listenOnChannel(e){if(typeof e=="string"&&(e=parseInt(e)),isNaN(e)||e<1||e>255)throw new Error("Invalid port number");this.__internal__.device.listen_on_port=e,!this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(e))}get lastAction(){return this.__internal__.serial.last_action}get listenOnChannel(){return this.__internal__.device.listen_on_port??1}set serialFilters(e){if(this.isConnected)throw new Error("Cannot change serial filters while connected");this.__internal__.serial.filters=e}get serialFilters(){return this.__internal__.serial.filters}set serialConfigPort(e){if(this.isConnected)throw new Error("Cannot change serial filters while connected");this.__internal__.serial.config_port=e}get serialConfigPort(){return this.__internal__.serial.config_port}get useRTSCTS(){return this.__internal__.serial.useRTSCTS}set useRTSCTS(e){this.__internal__.serial.useRTSCTS=e}get isConnected(){const e=this.__internal__.serial.connected,t=a(this,s,b).call(this,this.__internal__.serial.port);return e&&!t&&a(this,s,C).call(this,{error:"Port is closed, not readable or writable."}),this.__internal__.serial.connected=t,this.__internal__.serial.connected}get isDisconnected(){const e=this.__internal__.serial.connected,t=a(this,s,b).call(this,this.__internal__.serial.port);return!e&&t&&(this.dispatch("serial:connected"),h.$dispatchChange(this)),this.__internal__.serial.connected=t,!this.__internal__.serial.connected}get deviceNumber(){return this.__internal__.device_number}get uuid(){return this.__internal__.device.id}get typeDevice(){return this.__internal__.device.type}get queue(){return this.__internal__.serial.queue}get responseDelimited(){return this.__internal__.serial.response.delimited}set responseDelimited(e){if(typeof e!="boolean")throw new Error("responseDelimited must be a boolean");this.__internal__.serial.response.delimited=e}get responsePrefixLimited(){return this.__internal__.serial.response.prefixLimiter}set responsePrefixLimited(e){if(typeof e!="boolean")throw new Error("responsePrefixLimited must be a boolean");this.__internal__.serial.response.prefixLimiter=e}get responseSufixLimited(){return this.__internal__.serial.response.sufixLimiter}set responseSufixLimited(e){if(typeof e!="boolean")throw new Error("responseSufixLimited must be a boolean");this.__internal__.serial.response.sufixLimiter=e}get responseLimiter(){return this.__internal__.serial.response.limiter}set responseLimiter(e){if(typeof e!="string"&&!(e instanceof RegExp))throw new Error("responseLimiter must be a string or a RegExp");this.__internal__.serial.response.limiter=e}get fixedBytesMessage(){return this.__internal__.serial.response.length}set fixedBytesMessage(e){if(e!==null&&(typeof e!="number"||e<1))throw new Error("Invalid length for fixed bytes message");this.__internal__.serial.response.length=e}get timeoutBeforeResponseBytes(){return this.__internal__.serial.free_timeout_ms||50}set timeoutBeforeResponseBytes(e){if(e!==void 0&&(typeof e!="number"||e<1))throw new Error("Invalid timeout for response bytes");this.__internal__.serial.free_timeout_ms=e??50}get bypassSerialBytesConnection(){return this.__internal__.bypassSerialBytesConnection}set bypassSerialBytesConnection(e){if(typeof e!="boolean")throw new Error("bypassSerialBytesConnection must be a boolean");this.__internal__.bypassSerialBytesConnection=e}async timeout(e,t){this.__internal__.last_error.message="Operation response timed out.",this.__internal__.last_error.action=t,this.__internal__.last_error.code=e,this.__internal__.timeout.until_response&&(clearTimeout(this.__internal__.timeout.until_response),this.__internal__.timeout.until_response=0),t==="connect"?(this.__internal__.serial.connected=!1,this.dispatch("serial:reconnect",{}),h.$dispatchChange(this)):t==="connection:start"&&(await this.serialDisconnect(),this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector+=1,h.$dispatchChange(this),await this.serialConnect()),this.dispatch("serial:timeout",{...this.__internal__.last_error,bytes:e,action:t})}async disconnect(e=null){await this.serialDisconnect(),a(this,s,C).call(this,e)}async connect(){return this.isConnected?`${this.typeDevice} device ${this.deviceNumber} already connected`:new Promise((e,t)=>{W()||t("Web Serial not supported"),setTimeout(async()=>{await x(499),await this.serialConnect(),this.isConnected?e(`${this.typeDevice} device ${this.deviceNumber} connected`):t(`${this.typeDevice} device ${this.deviceNumber} not connected`)},1)})}async serialDisconnect(){try{const e=this.__internal__.serial.reader,t=this.__internal__.serial.output_stream;e&&(await e.cancel().catch(n=>this.serialErrors(n)),await this.__internal__.serial.input_done),t&&(await t.getWriter().close(),await this.__internal__.serial.output_done),this.__internal__.serial.connected&&this.__internal__.serial&&this.__internal__.serial.port&&await this.__internal__.serial.port.close()}catch(e){this.serialErrors(e)}finally{this.__internal__.serial.reader=null,this.__internal__.serial.input_done=null,this.__internal__.serial.output_stream=null,this.__internal__.serial.output_done=null,this.__internal__.serial.connected=!1,this.__internal__.serial.port=null,h.$dispatchChange(this)}}getResponseAsArrayBuffer(){this.__internal__.serial.response.as="arraybuffer"}getResponseAsArrayHex(){this.__internal__.serial.response.as="hex"}getResponseAsUint8Array(){this.__internal__.serial.response.as="uint8"}getResponseAsString(){this.__internal__.serial.response.as="string"}async serialPortsSaved(e){const t=this.serialFilters;if(this.__internal__.aux_port_connector<e.length){const i=this.__internal__.aux_port_connector;this.__internal__.serial.port=e[i]}else this.__internal__.aux_port_connector=0,this.__internal__.serial.port=await navigator.serial.requestPort({filters:t});if(!this.__internal__.serial.port)throw new Error("Select another port please")}serialErrors(e){const t=e.toString().toLowerCase();switch(!0){case t.includes("must be handling a user gesture to show a permission request"):case t.includes("the port is closed."):case t.includes("the port is closed or is not writable"):case t.includes("the port is closed or is not readable"):case t.includes("the port is closed or is not readable/writable"):case t.includes("select another port please"):case t.includes("no port selected by the user"):case t.includes("this readable stream reader has been released and cannot be used to cancel its previous owner stream"):this.dispatch("serial:need-permission",{}),h.$dispatchChange(this);break;case t.includes("the port is already open."):case t.includes("failed to open serial port"):this.serialDisconnect().then(async()=>{this.__internal__.aux_port_connector+=1,await this.serialConnect()});break;case t.includes("cannot read properties of undefined (reading 'writable')"):case t.includes("cannot read properties of null (reading 'writable')"):case t.includes("cannot read property 'writable' of null"):case t.includes("cannot read property 'writable' of undefined"):this.serialDisconnect().then(async()=>{await this.serialConnect()});break;case t.includes("'close' on 'serialport': a call to close() is already in progress."):break;case t.includes("failed to execute 'open' on 'serialport': a call to open() is already in progress."):break;case t.includes("the port is already closed."):break;case t.includes("the device has been lost"):this.dispatch("serial:lost",{}),h.$dispatchChange(this);break;case t.includes("navigator.serial is undefined"):this.dispatch("serial:unsupported",{});break;default:console.error(e);break}this.dispatch("serial:error",e)}async serialConnect(){try{this.dispatch("serial:connecting",{});const e=await a(this,s,D).call(this);if(e.length>0)await this.serialPortsSaved(e);else{const n=this.serialFilters;this.__internal__.serial.port=await navigator.serial.requestPort({filters:n})}const t=this.__internal__.serial.port;if(!t)throw new Error("No port selected by the user");await t.open(this.serialConfigPort);const i=this;t.onconnect=n=>{console.log(n),i.dispatch("serial:connected",n),h.$dispatchChange(this),i.__internal__.serial.queue.length>0&&i.dispatch("internal:queue",{})},t.ondisconnect=async()=>{await i.disconnect()},await x(this.__internal__.serial.delay_first_connection),this.__internal__.timeout.until_response=setTimeout(async()=>{await i.timeout(i.__internal__.serial.bytes_connection??[],"connection:start")},this.__internal__.time.response_connection),this.__internal__.serial.last_action="connect",await a(this,s,E).call(this,this.__internal__.serial.bytes_connection??[]),this.dispatch("serial:sent",{action:"connect",bytes:this.__internal__.serial.bytes_connection}),this.__internal__.auto_response&&a(this,s,g).call(this,this.__internal__.serial.auto_response),await a(this,s,R).call(this)}catch(e){this.serialErrors(e)}}async serialForget(){return await a(this,s,M).call(this)}decToHex(e){return typeof e=="string"&&(e=parseInt(e,10)),e.toString(16)}hexToDec(e){return parseInt(e,16)}hexMaker(e="00",t=2){return e.toString().padStart(t,"0").toLowerCase()}add0x(e){const t=[];return e.forEach((i,n)=>{t[n]="0x"+i}),t}bytesToHex(e){return this.add0x(Array.from(e,t=>this.hexMaker(t)))}validateBytes(e){let t=new Uint8Array(0);if(e instanceof Uint8Array)t=e;else if(typeof e=="string")t=this.parseStringToTextEncoder(e);else if(Array.isArray(e)&&typeof e[0]=="string")t=this.stringArrayToUint8Array(e);else if(Array.isArray(e)&&typeof e[0]=="number")t=new Uint8Array(e);else throw new Error("Invalid data type");return t}async appendToQueue(e,t){const i=this.validateBytes(e);if(["connect","connection:start"].includes(t)){if(this.__internal__.serial.connected)return;await this.serialConnect();return}this.__internal__.serial.queue.push({bytes:i,action:t}),this.dispatch("internal:queue",{})}serialSetConnectionConstant(e=1){if(this.__internal__.bypassSerialBytesConnection)return this.__internal__.serial.bytes_connection;throw console.warn("wtf?",this.bypassSerialBytesConnection),new Error(`Method not implemented 'serialSetConnectionConstant' to listen on channel ${e}`)}serialMessage(e){throw console.log(e),this.dispatch("serial:message",{code:e}),new Error("Method not implemented 'serialMessage'")}serialCorruptMessage(e){throw console.log(e),this.dispatch("serial:corrupt-message",{code:e}),new Error("Method not implemented 'serialCorruptMessage'")}clearSerialQueue(){this.__internal__.serial.queue=[]}sumHex(e){let t=0;return e.forEach(i=>{t+=parseInt(i,16)}),t.toString(16)}toString(){return JSON.stringify({__class:this.typeDevice,device_number:this.deviceNumber,uuid:this.uuid,connected:this.isConnected,connection:this.__internal__.serial.bytes_connection})}softReload(){a(this,s,j).call(this),this.dispatch("serial:soft-reload",{})}async sendConnect(){if(!this.__internal__.serial.bytes_connection)throw new Error("No connection bytes defined");await this.appendToQueue(this.__internal__.serial.bytes_connection,"connect")}async sendCustomCode({code:e=[]}={code:[]}){if(!e)throw new Error("No data to send");this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.validateBytes(e)),await this.appendToQueue(e,"custom")}stringToArrayHex(e){return Array.from(e).map(t=>t.charCodeAt(0).toString(16))}stringToArrayBuffer(e,t=`
|
|
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 u=Number(e.charCodeAt(i)).toString(16);t.push(u)}return t.join("")}$checkAndDispatchConnection(){return this.isConnected}}s=new WeakSet,b=function(e){return!!(e&&e.readable&&e.writable)},C=function(e=null){this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector=0,this.dispatch("serial:disconnected",e),h.$dispatchChange(this)},E=async function(e){const t=this.__internal__.serial.port;if(!t||t&&(!t.readable||!t.writable))throw a(this,s,C).call(this,{error:"Port is closed, not readable or writable."}),new Error("The port is closed or is not readable/writable");const i=this.validateBytes(e);if(this.useRTSCTS&&await a(this,s,$).call(this,t,5e3),t.writable===null)return;const n=t.writable.getWriter();await n.write(i),n.releaseLock()},$=async function(e,t=5e3){const i=Date.now();for(;;){if(Date.now()-i>t)throw new Error("Timeout waiting for clearToSend signal");const{clearToSend:n}=await e.getSignals();if(n)return;await x(100)}},g=function(e=new Uint8Array([]),t=!1){if(e&&e.length>0){const i=this.__internal__.serial.connected;if(this.__internal__.serial.connected=a(this,s,b).call(this,this.__internal__.serial.port),h.$dispatchChange(this),!i&&this.__internal__.serial.connected&&this.dispatch("serial:connected"),this.__internal__.interval.reconnection&&(clearInterval(this.__internal__.interval.reconnection),this.__internal__.interval.reconnection=0),this.__internal__.timeout.until_response&&(clearTimeout(this.__internal__.timeout.until_response),this.__internal__.timeout.until_response=0),this.__internal__.serial.response.as==="hex")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 u=n.split(this.__internal__.serial.response.limiter);for(const c in u)u[c]&&(t?this.serialCorruptMessage(u[c]):this.serialMessage(u[c]))}else t?this.serialCorruptMessage(n):this.serialMessage(n)}else{const n=this.stringToArrayBuffer(this.parseUint8ArrayToString(e));t?this.serialCorruptMessage(n):this.serialMessage(n)}}this.__internal__.serial.queue.length!==0&&this.dispatch("internal:queue",{})},D=async function(){const e=this.serialFilters,t=await navigator.serial.getPorts({filters:e});return e.length===0?t:t.filter(n=>{const u=n.getInfo();return e.some(c=>u.usbProductId===c.usbProductId&&u.usbVendorId===c.usbVendorId)}).filter(n=>!a(this,s,b).call(this,n))},U=function(e){if(e){const t=this.__internal__.serial.response.buffer,i=new Uint8Array(t.length+e.byteLength);i.set(t,0),i.set(new Uint8Array(e),t.length),this.__internal__.serial.response.buffer=i}},k=async function(){this.__internal__.serial.time_until_send_bytes&&(clearTimeout(this.__internal__.serial.time_until_send_bytes),this.__internal__.serial.time_until_send_bytes=0),this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{this.__internal__.serial.response.buffer&&a(this,s,g).call(this,this.__internal__.serial.response.buffer),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms||50)},P=async function(){const e=this.__internal__.serial.response.length;let t=this.__internal__.serial.response.buffer;if(this.__internal__.serial.time_until_send_bytes&&(clearTimeout(this.__internal__.serial.time_until_send_bytes),this.__internal__.serial.time_until_send_bytes=0),!(e===null||!t||t.length===0)){for(;t.length>=e;){const i=t.slice(0,e);a(this,s,g).call(this,i),t=t.slice(e)}this.__internal__.serial.response.buffer=t,t.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{a(this,s,g).call(this,this.__internal__.serial.response.buffer,!0)},this.__internal__.serial.free_timeout_ms||50))}},I=async function(){const{limiter:e,prefixLimiter:t=!1,sufixLimiter:i=!0}=this.__internal__.serial.response;if(!e)throw new Error("No limiter defined for delimited serial response");const 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 c=new TextDecoder().decode(n);const w=[];if(typeof e=="string"){let p;if(t&&i)p=new RegExp(`${e}([^${e}]+)${e}`,"g");else if(t)p=new RegExp(`${e}([^${e}]*)`,"g");else if(i)p=new RegExp(`([^${e}]+)${e}`,"g");else return;let y,f=0;for(;(y=p.exec(c))!==null;)w.push(new TextEncoder().encode(y[1])),f=p.lastIndex;c=c.slice(f)}else if(e instanceof RegExp){let p,y=0;if(t&&i){const f=new RegExp(`${e.source}(.*?)${e.source}`,"g");for(;(p=f.exec(c))!==null;)w.push(new TextEncoder().encode(p[1])),y=f.lastIndex}else if(i)for(;(p=e.exec(c))!==null;){const f=p.index,T=c.slice(y,f);w.push(new TextEncoder().encode(T)),y=e.lastIndex}else if(t){const f=c.split(e);f.shift();for(const T of f)w.push(new TextEncoder().encode(T));c=""}c=c.slice(y)}for(const p of w)a(this,s,g).call(this,p);const A=new TextEncoder().encode(c);this.__internal__.serial.response.buffer=A,A.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{a(this,s,g).call(this,this.__internal__.serial.response.buffer,!0),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms??50))},R=async function(){const e=this.__internal__.serial.port;if(!e||!e.readable)throw new Error("Port is not readable");const t=e.readable.getReader();this.__internal__.serial.reader=t;try{for(;this.__internal__.serial.keep_reading;){const{value:i,done:n}=await t.read();if(n)break;a(this,s,U).call(this,i),this.__internal__.serial.response.delimited?await a(this,s,I).call(this):this.__internal__.serial.response.length===null?await a(this,s,k).call(this):await a(this,s,P).call(this)}}catch(i){this.serialErrors(i)}finally{t.releaseLock(),this.__internal__.serial.keep_reading=!0,this.__internal__.serial.port&&await this.__internal__.serial.port.close()}},M=async function(){return typeof window>"u"?!1:"serial"in navigator&&"forget"in SerialPort.prototype&&this.__internal__.serial.port?(await this.__internal__.serial.port.forget(),!0):!1},q=function(){["serial:connected","serial:connecting","serial:reconnect","serial:timeout","serial:disconnected","serial:sent","serial:soft-reload","serial:message","serial:corrupt-message","unknown","serial:need-permission","serial:lost","serial:unsupported","serial:error","debug"].forEach(t=>{this.serialRegisterAvailableListener(t)})},N=function(){const e=this;this.on("internal:queue",async()=>{var t;await a(t=e,s,H).call(t)}),a(this,s,O).call(this)},O=function(){const e=this;navigator.serial.addEventListener("connect",async()=>{e.isDisconnected&&await e.serialConnect().catch(()=>{})})},H=async function(){if(!a(this,s,b).call(this,this.__internal__.serial.port)){a(this,s,C).call(this,{error:"Port is closed, not readable or writable."}),await this.serialConnect();return}if(this.__internal__.timeout.until_response||this.__internal__.serial.queue.length===0)return;const e=this.__internal__.serial.queue[0];let t=this.__internal__.time.response_general;if(e.action==="connect"&&(t=this.__internal__.time.response_connection),this.__internal__.timeout.until_response=setTimeout(async()=>{await this.timeout(e.bytes,e.action)},t),this.__internal__.serial.last_action=e.action??"unknown",await a(this,s,E).call(this,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(u){this.serialErrors(u)}a(this,s,g).call(this,n)}const i=[...this.__internal__.serial.queue];this.__internal__.serial.queue=i.splice(1)},F=function(e=1){this.__internal__.device_number=e,!this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(e))},j=function(){this.__internal__.last_error={message:null,action:null,code:null,no_code:0}},l.Core=Q,l.Devices=h,l.Dispatcher=d,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|