webserial-core 1.0.7 → 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/README.md CHANGED
@@ -218,6 +218,7 @@ arduino.on('serial:disconnected', (event) => {
218
218
 
219
219
  document.getElementById('disconnected').classList.remove('hidden');
220
220
  document.getElementById('connect').classList.remove('hidden');
221
+ document.getElementById("disconnect")?.classList.add("hidden");
221
222
  });
222
223
 
223
224
  // eslint-disable-next-line no-unused-vars
@@ -232,6 +233,7 @@ arduino.on('serial:connected', (event) => {
232
233
  document.getElementById('disconnected').classList.add('hidden');
233
234
  document.getElementById('need-permission').classList.add('hidden');
234
235
  document.getElementById('connect').classList.add('hidden');
236
+ document.getElementById("disconnect")?.classList.remove("hidden");
235
237
  });
236
238
 
237
239
  // eslint-disable-next-line no-unused-vars
@@ -239,6 +241,7 @@ arduino.on('serial:need-permission', (event) => {
239
241
  document.getElementById('disconnected').classList.remove('hidden');
240
242
  document.getElementById('need-permission').classList.remove('hidden');
241
243
  document.getElementById('connect').classList.remove('hidden');
244
+ document.getElementById("disconnect")?.classList.add("hidden");
242
245
  });
243
246
 
244
247
  // eslint-disable-next-line no-unused-vars
@@ -260,7 +263,11 @@ function tryConnect() {
260
263
 
261
264
  document.addEventListener('DOMContentLoaded', () => {
262
265
  tryConnect();
263
- document.getElementById('connect').addEventListener('click', tryConnect);
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
+ });
264
271
  });
265
272
 
266
273
  ```
@@ -283,6 +290,7 @@ But wait still need to create the HTML file.
283
290
  <div class="webserial w-full max-w-xl mx-auto grid grid-cols-1 gap-y-4">
284
291
  <div class="my-6"></div>
285
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>
286
294
 
287
295
  <div id="need-permission" class="hidden p-4 bg-rose-900 rounded-lg">
288
296
  Woooah! It seems that you need to give permission to access the serial port.
package/dist/Core.d.ts CHANGED
@@ -17,6 +17,9 @@ 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
25
  bytes: string | Uint8Array | Array<string> | Array<number>;
@@ -40,6 +43,8 @@ type SerialData = {
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>;
@@ -99,15 +122,13 @@ interface ICore {
99
122
  bytesToHex(bytes: string[]): string[];
100
123
  appendToQueue(arr: string[], action: string): Promise<void>;
101
124
  serialSetConnectionConstant(listen_on_port?: number): string | Uint8Array | string[] | number[] | null;
102
- serialMessage(hex: string[]): void;
103
- serialCorruptMessage(code: string[], data: never | null): void;
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({ code }: {
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,12 +155,28 @@ 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[];
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);
143
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>;
@@ -160,8 +197,8 @@ export declare class Core extends Dispatcher implements ICore {
160
197
  validateBytes(data: string | Uint8Array | Array<string> | Array<number>): Uint8Array;
161
198
  appendToQueue(arr: string | Uint8Array | string[] | number[], action: string): Promise<void>;
162
199
  serialSetConnectionConstant(listen_on_port?: number): string | Uint8Array | string[] | number[] | null;
163
- serialMessage(hex: string[] | Uint8Array<ArrayBufferLike> | string | ArrayBuffer): void;
164
- serialCorruptMessage(code: Uint8Array | number[] | string[], data: never | null): void;
200
+ serialMessage(code: string[] | Uint8Array<ArrayBufferLike> | string | ArrayBuffer): void;
201
+ serialCorruptMessage(code: Uint8Array | number[] | string[] | never | null | string | ArrayBuffer): void;
165
202
  clearSerialQueue(): void;
166
203
  sumHex(arr: string[]): string;
167
204
  toString(): string;
@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U,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,KAAK,GAAG,IAAI,GAAG,MAAM,GAAG,WAAW,GAAG,IAAI;IAgBxG,gBAAgB,IAAI,IAAI;IAIxB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM;IAQ7B,QAAQ,IAAI,MAAM;IAUlB,UAAU,IAAI,IAAI;IAKZ,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B,cAAc,CAAC,EAAE,IAAS,EAAE,GAAE,UAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAY7E,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;IAI1C,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,GAAE,MAAa,GAAG,eAAe;IAIxE,wBAAwB,CAAC,MAAM,GAAE,MAAW,EAAE,GAAG,GAAE,MAAa,GAAG,UAAU;IAM7E,kBAAkB,CAAC,MAAM,GAAE,MAAW,EAAE,GAAG,GAAE,MAAa,GAAG,MAAM,EAAE;IAKrE,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE;IAI5C,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU;IAI5C,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU;IAatD,uBAAuB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE,GAAG,MAAM;IAgB7D,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IASxC,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IASvC,2BAA2B,IAAI,OAAO;CAG9C"}
@@ -1,32 +1,32 @@
1
- var I = Object.defineProperty;
2
- var b = (o) => {
3
- throw TypeError(o);
1
+ var j = Object.defineProperty;
2
+ var T = (l) => {
3
+ throw TypeError(l);
4
4
  };
5
- var M = (o, n, e) => n in o ? I(o, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[n] = e;
6
- var u = (o, n, e) => M(o, typeof n != "symbol" ? n + "" : n, e), N = (o, n, e) => n.has(o) || b("Cannot " + e);
7
- var w = (o, n, e) => n.has(o) ? b("Cannot add the same private member more than once") : n instanceof WeakSet ? n.add(o) : n.set(o, e);
8
- var l = (o, n, e) => (N(o, n, "access private method"), e);
9
- class m extends CustomEvent {
10
- constructor(n, e) {
11
- super(n, e);
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 C extends EventTarget {
14
+ class L extends EventTarget {
15
15
  constructor() {
16
16
  super(...arguments);
17
- u(this, "__listeners__", {
17
+ g(this, "__listeners__", {
18
18
  debug: !1
19
19
  });
20
- u(this, "__debug__", !1);
20
+ g(this, "__debug__", !1);
21
21
  }
22
22
  dispatch(e, t = null) {
23
- const i = new m(e, { detail: t });
24
- this.dispatchEvent(i), this.__debug__ && this.dispatchEvent(new m("debug", { detail: { type: e, data: t } }));
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
- const s = this;
27
+ const r = this;
28
28
  setTimeout(() => {
29
- s.dispatch(e, t);
29
+ r.dispatch(e, t);
30
30
  }, i);
31
31
  }
32
32
  on(e, t) {
@@ -45,58 +45,58 @@ class C extends EventTarget {
45
45
  }));
46
46
  }
47
47
  }
48
- const a = class a extends C {
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(n = null) {
55
- n && n.$checkAndDispatchConnection(), a.instance.dispatch("change", { devices: a.devices, dispatcher: n });
54
+ static $dispatchChange(s = null) {
55
+ s && s.$checkAndDispatchConnection(), o.instance.dispatch("change", { devices: o.devices, dispatcher: s });
56
56
  }
57
- static typeError(n) {
57
+ static typeError(s) {
58
58
  const e = new Error();
59
- throw e.message = `Type ${n} is not supported`, e.name = "DeviceTypeError", e;
59
+ throw e.message = `Type ${s} is not supported`, e.name = "DeviceTypeError", e;
60
60
  }
61
- static registerType(n) {
62
- typeof a.devices[n] > "u" && (a.devices[n] = {});
61
+ static registerType(s) {
62
+ typeof o.devices[s] > "u" && (o.devices[s] = {});
63
63
  }
64
- static add(n) {
65
- const e = n.typeDevice;
66
- typeof a.devices[e] > "u" && (a.devices[e] = {});
67
- const t = n.uuid;
68
- if (typeof a.devices[e] > "u" && a.typeError(e), a.devices[e][t])
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 a.devices[e][t] = n, a.$dispatchChange(n), Object.keys(a.devices[e]).indexOf(t);
70
+ return o.devices[e][t] = s, o.$dispatchChange(s), Object.keys(o.devices[e]).indexOf(t);
71
71
  }
72
- static get(n, e) {
73
- return typeof a.devices[n] > "u" && (a.devices[n] = {}), typeof a.devices[n] > "u" && a.typeError(n), a.devices[n][e];
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(n = null) {
76
- return n === null ? a.devices : (typeof a.devices[n] > "u" && a.typeError(n), a.devices[n]);
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(a.devices).map((e) => Object.values(e)).flat();
79
+ return Object.values(o.devices).map((e) => Object.values(e)).flat();
80
80
  }
81
- static getByNumber(n, e) {
82
- return typeof a.devices[n] > "u" && a.typeError(n), Object.values(a.devices[n]).find((i) => i.deviceNumber === e) ?? null;
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(n, e = 1) {
85
- return typeof a.devices[n] > "u" && a.typeError(n), Object.values(a.devices[n]).find((i) => i.deviceNumber === e) ?? null;
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
- u(a, "instance"), u(a, "devices", {});
89
- let _ = a;
90
- _.instance || (_.instance = new _());
91
- function v(o = 100) {
88
+ g(o, "instance"), g(o, "devices", {});
89
+ let h = o;
90
+ h.instance || (h.instance = new h());
91
+ function C(l = 100) {
92
92
  return new Promise(
93
- (n) => setTimeout(() => n(), o)
93
+ (s) => setTimeout(() => s(), l)
94
94
  );
95
95
  }
96
- function B() {
96
+ function V() {
97
97
  return "serial" in navigator;
98
98
  }
99
- const g = {
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 r, d, f, y, h, A, E, x, T, S, U, k, P, L, D, $, q;
108
- class R extends C {
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 = g,
111
+ config_port: t = v,
112
112
  no_device: i = 1,
113
- device_listen_on_channel: s = 1
113
+ device_listen_on_channel: r = 1,
114
+ bypassSerialBytesConnection: c = !1
114
115
  } = {
115
116
  filters: null,
116
- config_port: g,
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
- w(this, r);
122
- u(this, "__internal__", {
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,
@@ -138,7 +141,10 @@ class R extends C {
138
141
  buffer: new Uint8Array([]),
139
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 R extends C {
150
156
  delay_first_connection: 200,
151
157
  bytes_connection: null,
152
158
  filters: [],
153
- config_port: g,
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 R extends C {
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 && l(this, r, $).call(this, i), s && ["number", "string"].includes(typeof s) && (this.listenOnChannel = s), l(this, r, k).call(this), l(this, r, P).call(this);
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 R extends C {
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 = l(this, r, d).call(this, this.__internal__.serial.port);
202
- return e && !t && l(this, r, f).call(this, { error: "Port is closed, not readable or writable." }), this.__internal__.serial.connected = t, this.__internal__.serial.connected;
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 = l(this, r, d).call(this, this.__internal__.serial.port);
206
- return !e && t && (this.dispatch("serial:connected"), _.$dispatchChange(this)), this.__internal__.serial.connected = t, !this.__internal__.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,31 +235,87 @@ class R extends C {
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", {}), _.$dispatchChange(this)) : t === "connection:start" && (await this.serialDisconnect(), this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector += 1, _.$dispatchChange(this), await this.serialConnect()), this.dispatch("serial:timeout", {
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(), l(this, r, f).call(this, e);
302
+ await this.serialDisconnect(), a(this, n, b).call(this, e);
229
303
  }
230
304
  async connect() {
231
- return new Promise((e, t) => {
232
- B() || t("Web Serial not supported"), setTimeout(async () => {
233
- await v(499), await this.serialConnect(), this.isConnected ? e(`${this.typeDevice} device ${this.deviceNumber} connected`) : t(`${this.typeDevice} device ${this.deviceNumber} not connected`);
305
+ return this.isConnected ? `${this.typeDevice} device ${this.deviceNumber} already connected` : new Promise((e, t) => {
306
+ V() || t("Web Serial not supported"), setTimeout(async () => {
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
  });
236
310
  }
237
311
  async serialDisconnect() {
238
312
  try {
239
313
  const e = this.__internal__.serial.reader, t = this.__internal__.serial.output_stream;
240
- 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();
314
+ 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();
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, _.$dispatchChange(this);
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 R extends C {
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", {}), _.$dispatchChange(this);
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 R extends C {
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", {}), _.$dispatchChange(this);
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,13 +392,13 @@ class R extends C {
318
392
  async serialConnect() {
319
393
  try {
320
394
  this.dispatch("serial:connecting", {});
321
- const e = await l(this, r, A).call(this);
395
+ const e = await a(this, n, $).call(this);
322
396
  if (e.length > 0)
323
397
  await this.serialPortsSaved(e);
324
398
  else {
325
- const s = this.serialFilters;
399
+ const r = this.serialFilters;
326
400
  this.__internal__.serial.port = await navigator.serial.requestPort({
327
- filters: s
401
+ filters: r
328
402
  });
329
403
  }
330
404
  const t = this.__internal__.serial.port;
@@ -332,22 +406,22 @@ class R extends C {
332
406
  throw new Error("No port selected by the user");
333
407
  await t.open(this.serialConfigPort);
334
408
  const i = this;
335
- t.onconnect = (s) => {
336
- console.log(s), i.dispatch("serial:connected", s), _.$dispatchChange(this), i.__internal__.serial.queue.length > 0 && i.dispatch("internal:queue", {});
409
+ t.onconnect = (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
- }, await v(this.__internal__.serial.delay_first_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
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 l(this, r, y).call(this, this.__internal__.serial.bytes_connection ?? []), this.dispatch("serial:sent", {
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 && l(this, r, h).call(this, this.__internal__.serial.auto_response, null), await l(this, r, S).call(this);
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 l(this, r, U).call(this);
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);
@@ -360,8 +434,8 @@ class R extends C {
360
434
  }
361
435
  add0x(e) {
362
436
  const t = [];
363
- return e.forEach((i, s) => {
364
- t[s] = "0x" + i;
437
+ return e.forEach((i, r) => {
438
+ t[r] = "0x" + i;
365
439
  }), t;
366
440
  }
367
441
  bytesToHex(e) {
@@ -391,13 +465,14 @@ class R extends C {
391
465
  this.__internal__.serial.queue.push({ bytes: i, action: t }), this.dispatch("internal:queue", {});
392
466
  }
393
467
  serialSetConnectionConstant(e = 1) {
394
- throw new Error(`Method not implemented 'serialSetConnectionConstant' to listen on channel ${e}`);
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}`);
395
470
  }
396
471
  serialMessage(e) {
397
- 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'");
398
473
  }
399
- serialCorruptMessage(e, t) {
400
- throw console.log(e, t), new Error("Method not implemented 'serialCorruptMessage'");
474
+ serialCorruptMessage(e) {
475
+ throw console.log(e), this.dispatch("serial:corrupt-message", { code: e }), new Error("Method not implemented 'serialCorruptMessage'");
401
476
  }
402
477
  clearSerialQueue() {
403
478
  this.__internal__.serial.queue = [];
@@ -418,18 +493,17 @@ class R extends C {
418
493
  });
419
494
  }
420
495
  softReload() {
421
- l(this, r, q).call(this), this.dispatch("serial:soft-reload", {});
496
+ a(this, n, F).call(this), this.dispatch("serial:soft-reload", {});
422
497
  }
423
498
  async sendConnect() {
424
499
  if (!this.__internal__.serial.bytes_connection)
425
500
  throw new Error("No connection bytes defined");
426
501
  await this.appendToQueue(this.__internal__.serial.bytes_connection, "connect");
427
502
  }
428
- // @ts-expect-error code is required but can be empty
429
503
  async sendCustomCode({ code: e = [] } = { code: [] }) {
430
- if (e === null || e.length === 0)
504
+ if (!e)
431
505
  throw new Error("No data to send");
432
- await this.appendToQueue(e, "custom");
506
+ this.__internal__.bypassSerialBytesConnection && (this.__internal__.serial.bytes_connection = this.validateBytes(e)), await this.appendToQueue(e, "custom");
433
507
  }
434
508
  stringToArrayHex(e) {
435
509
  return Array.from(e).map((t) => t.charCodeAt(0).toString(16));
@@ -446,7 +520,7 @@ class R extends C {
446
520
  parseStringToBytes(e = "", t = `
447
521
  `) {
448
522
  const i = this.parseStringToTextEncoder(e, t);
449
- return Array.from(i).map((s) => s.toString(16));
523
+ return Array.from(i).map((r) => r.toString(16));
450
524
  }
451
525
  parseUint8ToHex(e) {
452
526
  return Array.from(e).map((t) => t.toString(16));
@@ -456,27 +530,27 @@ class R extends C {
456
530
  }
457
531
  stringArrayToUint8Array(e) {
458
532
  const t = [];
459
- return e.forEach((i) => {
460
- const s = i.replace("0x", "");
461
- t.push(parseInt(s, 16));
462
- }), new Uint8Array(t);
533
+ return typeof e == "string" ? this.parseStringToTextEncoder(e).buffer : (e.forEach((i) => {
534
+ const r = i.replace("0x", "");
535
+ t.push(parseInt(r, 16));
536
+ }), new Uint8Array(t));
463
537
  }
464
538
  parseUint8ArrayToString(e) {
465
539
  let t = new Uint8Array(0);
466
540
  e instanceof Uint8Array ? t = e : t = this.stringArrayToUint8Array(e), e = this.parseUint8ToHex(t);
467
- const i = e.map((s) => parseInt(s, 16));
541
+ const i = e.map((r) => parseInt(r, 16));
468
542
  return this.__internal__.serial.response.replacer ? String.fromCharCode(...i).replace(this.__internal__.serial.response.replacer, "") : String.fromCharCode(...i);
469
543
  }
470
544
  hexToAscii(e) {
471
545
  const t = e.toString();
472
546
  let i = "";
473
- for (let s = 0; s < t.length; s += 2)
474
- i += String.fromCharCode(parseInt(t.substring(s, 2), 16));
547
+ for (let r = 0; r < t.length; r += 2)
548
+ i += String.fromCharCode(parseInt(t.substring(r, 2), 16));
475
549
  return i;
476
550
  }
477
551
  asciiToHex(e) {
478
552
  const t = [];
479
- for (let i = 0, s = e.length; i < s; i++) {
553
+ for (let i = 0, r = e.length; i < r; i++) {
480
554
  const c = Number(e.charCodeAt(i)).toString(16);
481
555
  t.push(c);
482
556
  }
@@ -486,102 +560,147 @@ class R extends C {
486
560
  return this.isConnected;
487
561
  }
488
562
  }
489
- r = new WeakSet(), d = function(e) {
563
+ n = new WeakSet(), y = function(e) {
490
564
  return !!(e && e.readable && e.writable);
491
- }, f = function(e = null) {
492
- this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector = 0, this.dispatch("serial:disconnected", e), _.$dispatchChange(this);
493
- }, y = async function(e) {
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) {
494
568
  const t = this.__internal__.serial.port;
495
569
  if (!t || t && (!t.readable || !t.writable))
496
- throw l(this, r, f).call(this, { error: "Port is closed, not readable or writable." }), new Error("The port is closed or is not readable/writable");
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");
497
571
  const i = this.validateBytes(e);
498
- if (t.writable === null) return;
499
- const s = t.writable.getWriter();
500
- await s.write(i), s.releaseLock();
501
- }, h = function(e = new Uint8Array([]), t = null) {
572
+ if (this.useRTSCTS && await a(this, n, B).call(this, t, 5e3), t.writable === null) return;
573
+ const r = t.writable.getWriter();
574
+ await r.write(i), r.releaseLock();
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) {
502
585
  if (e && e.length > 0) {
503
586
  const i = this.__internal__.serial.connected;
504
- if (this.__internal__.serial.connected = l(this, r, d).call(this, this.__internal__.serial.port), _.$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")
505
- this.serialMessage(this.parseUint8ToHex(e));
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));
506
589
  else if (this.__internal__.serial.response.as === "uint8")
507
- this.serialMessage(e);
590
+ t ? this.serialCorruptMessage(e) : this.serialMessage(e);
508
591
  else if (this.__internal__.serial.response.as === "string") {
509
- const s = this.parseUint8ArrayToString(e);
592
+ const r = this.parseUint8ArrayToString(e);
510
593
  if (this.__internal__.serial.response.limiter !== null) {
511
- const c = s.split(this.__internal__.serial.response.limiter);
512
- for (const p in c)
513
- c[p] && this.serialMessage(c[p]);
594
+ const c = r.split(this.__internal__.serial.response.limiter);
595
+ for (const _ in c)
596
+ c[_] && (t ? this.serialCorruptMessage(c[_]) : this.serialMessage(c[_]));
514
597
  } else
515
- this.serialMessage(s);
598
+ t ? this.serialCorruptMessage(r) : this.serialMessage(r);
516
599
  } else {
517
- const s = this.stringToArrayBuffer(this.parseUint8ArrayToString(e));
518
- this.serialMessage(s);
600
+ const r = this.stringToArrayBuffer(this.parseUint8ArrayToString(e));
601
+ t ? this.serialCorruptMessage(r) : this.serialMessage(r);
519
602
  }
520
- } else
521
- this.serialCorruptMessage(e, t);
603
+ }
522
604
  this.__internal__.serial.queue.length !== 0 && this.dispatch("internal:queue", {});
523
- }, A = async function() {
605
+ }, $ = async function() {
524
606
  const e = this.serialFilters, t = await navigator.serial.getPorts({ filters: e });
525
- return e.length === 0 ? t : t.filter((s) => {
526
- const c = s.getInfo();
527
- return e.some((p) => c.usbProductId === p.usbProductId && c.usbVendorId === p.usbVendorId);
528
- }).filter((s) => !l(this, r, d).call(this, s));
529
- }, E = function(e) {
607
+ return e.length === 0 ? t : t.filter((r) => {
608
+ const c = r.getInfo();
609
+ return e.some((_) => c.usbProductId === _.usbProductId && c.usbVendorId === _.usbVendorId);
610
+ }).filter((r) => !a(this, n, y).call(this, r));
611
+ }, U = function(e) {
530
612
  if (e) {
531
613
  const t = this.__internal__.serial.response.buffer, i = new Uint8Array(t.length + e.byteLength);
532
614
  i.set(t, 0), i.set(new Uint8Array(e), t.length), this.__internal__.serial.response.buffer = i;
533
615
  }
534
- }, x = async function() {
616
+ }, k = async function() {
535
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(() => {
536
- this.__internal__.serial.response.buffer && l(this, r, h).call(this, this.__internal__.serial.response.buffer), this.__internal__.serial.response.buffer = new Uint8Array(0);
537
- }, 400);
538
- }, T = async function() {
539
- if (this.__internal__.serial.response.length !== null) {
540
- if (this.__internal__.serial.response.length === this.__internal__.serial.response.buffer.length)
541
- l(this, r, h).call(this, this.__internal__.serial.response.buffer), this.__internal__.serial.response.buffer = new Uint8Array(0);
542
- else if (this.__internal__.serial.response.length < this.__internal__.serial.response.buffer.length) {
543
- let e = new Uint8Array(0);
544
- for (let i = 0; i < this.__internal__.serial.response.length; i++)
545
- e[i] = this.__internal__.serial.response.buffer[i];
546
- if (e.length === this.__internal__.serial.response.length) {
547
- l(this, r, h).call(this, e), this.__internal__.serial.response.buffer = new Uint8Array(0);
548
- return;
549
- }
550
- e = new Uint8Array(0);
551
- const t = this.__internal__.serial.response.length * 2;
552
- if (this.__internal__.serial.response.buffer.length === t) {
553
- for (let i = 14; i < t; i++)
554
- e[i - this.__internal__.serial.response.length] = this.__internal__.serial.response.buffer[i];
555
- e.length === this.__internal__.serial.response.length && (l(this, r, h).call(this, e), this.__internal__.serial.response.buffer = new Uint8Array(0));
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;
556
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
+ _ = "";
557
676
  }
558
- }
559
- }, S = async function() {
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() {
560
686
  const e = this.__internal__.serial.port;
561
687
  if (!e || !e.readable) throw new Error("Port is not readable");
562
- for (; e.readable && this.__internal__.serial.keep_reading; ) {
563
- const t = e.readable.getReader();
564
- this.__internal__.serial.reader = t;
565
- try {
566
- let i = !0;
567
- for (; i; ) {
568
- const { value: s, done: c } = await t.read();
569
- if (c) {
570
- t.releaseLock(), this.__internal__.serial.keep_reading = !1, i = !1;
571
- break;
572
- }
573
- l(this, r, E).call(this, s), this.__internal__.serial.response.length === null ? await l(this, r, x).call(this) : await l(this, r, T).call(this);
574
- }
575
- } catch (i) {
576
- this.serialErrors(i);
577
- } finally {
578
- 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);
579
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();
580
700
  }
581
- this.__internal__.serial.keep_reading = !0, this.__internal__.serial.port && await this.__internal__.serial.port.close();
582
- }, U = async function() {
701
+ }, R = async function() {
583
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;
584
- }, k = function() {
703
+ }, M = function() {
585
704
  [
586
705
  "serial:connected",
587
706
  "serial:connecting",
@@ -591,6 +710,7 @@ r = new WeakSet(), d = function(e) {
591
710
  "serial:sent",
592
711
  "serial:soft-reload",
593
712
  "serial:message",
713
+ "serial:corrupt-message",
594
714
  "unknown",
595
715
  "serial:need-permission",
596
716
  "serial:lost",
@@ -600,21 +720,21 @@ r = new WeakSet(), d = function(e) {
600
720
  ].forEach((t) => {
601
721
  this.serialRegisterAvailableListener(t);
602
722
  });
603
- }, P = function() {
723
+ }, q = function() {
604
724
  const e = this;
605
725
  this.on("internal:queue", async () => {
606
726
  var t;
607
- await l(t = e, r, D).call(t);
608
- }), l(this, r, L).call(this);
609
- }, L = function() {
727
+ await a(t = e, n, O).call(t);
728
+ }), a(this, n, N).call(this);
729
+ }, N = function() {
610
730
  const e = this;
611
731
  navigator.serial.addEventListener("connect", async () => {
612
732
  e.isDisconnected && await e.serialConnect().catch(() => {
613
733
  });
614
734
  });
615
- }, D = async function() {
616
- if (!l(this, r, d).call(this, this.__internal__.serial.port)) {
617
- l(this, r, f).call(this, { error: "Port is closed, not readable or writable." }), await this.serialConnect();
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();
618
738
  return;
619
739
  }
620
740
  if (this.__internal__.timeout.until_response || this.__internal__.serial.queue.length === 0) return;
@@ -622,23 +742,23 @@ r = new WeakSet(), d = function(e) {
622
742
  let t = this.__internal__.time.response_general;
623
743
  if (e.action === "connect" && (t = this.__internal__.time.response_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
624
744
  await this.timeout(e.bytes, e.action);
625
- }, t), this.__internal__.serial.last_action = e.action ?? "unknown", await l(this, r, y).call(this, e.bytes), this.dispatch("serial:sent", {
745
+ }, t), this.__internal__.serial.last_action = e.action ?? "unknown", await a(this, n, x).call(this, e.bytes), this.dispatch("serial:sent", {
626
746
  action: e.action,
627
747
  bytes: e.bytes
628
748
  }), this.__internal__.auto_response) {
629
- let s = new Uint8Array(0);
749
+ let r = new Uint8Array(0);
630
750
  try {
631
- s = this.validateBytes(this.__internal__.serial.auto_response);
751
+ r = this.validateBytes(this.__internal__.serial.auto_response);
632
752
  } catch (c) {
633
753
  this.serialErrors(c);
634
754
  }
635
- l(this, r, h).call(this, s, null);
755
+ a(this, n, p).call(this, r);
636
756
  }
637
757
  const i = [...this.__internal__.serial.queue];
638
758
  this.__internal__.serial.queue = i.splice(1);
639
- }, $ = function(e = 1) {
640
- this.__internal__.device_number = e, this.__internal__.serial.bytes_connection = this.serialSetConnectionConstant(e);
641
- }, q = function() {
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() {
642
762
  this.__internal__.last_error = {
643
763
  message: null,
644
764
  action: null,
@@ -647,7 +767,7 @@ r = new WeakSet(), d = function(e) {
647
767
  };
648
768
  };
649
769
  export {
650
- R as Core,
651
- _ as Devices,
652
- C as Dispatcher
770
+ G as Core,
771
+ h as Devices,
772
+ L as Dispatcher
653
773
  };
@@ -1,4 +1,4 @@
1
- (function(o,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(o=typeof globalThis<"u"?globalThis:o||self,_(o.WebSerialCore={}))})(this,function(o){"use strict";var O=Object.defineProperty;var C=o=>{throw TypeError(o)};var B=(o,_,h)=>_ in o?O(o,_,{enumerable:!0,configurable:!0,writable:!0,value:h}):o[_]=h;var p=(o,_,h)=>B(o,typeof _!="symbol"?_+"":_,h),R=(o,_,h)=>_.has(o)||C("Cannot "+h);var A=(o,_,h)=>_.has(o)?C("Cannot add the same private member more than once"):_ instanceof WeakSet?_.add(o):_.set(o,h);var l=(o,_,h)=>(R(o,_,"access private method"),h);var n,f,y,m,d,E,T,S,x,U,k,P,D,L,$,q,I;class _ extends CustomEvent{constructor(r,e){super(r,e)}}class h extends EventTarget{constructor(){super(...arguments);p(this,"__listeners__",{debug:!1});p(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}};p(a,"instance"),p(a,"devices",{});let c=a;c.instance||(c.instance=new c);function v(b=100){return new Promise(r=>setTimeout(()=>r(),b))}function M(){return"serial"in navigator}const w={baudRate:9600,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"};class N 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();A(this,n);p(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:"uint8",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&&l(this,n,q).call(this,i),s&&["number","string"].includes(typeof s)&&(this.listenOnChannel=s),l(this,n,P).call(this),l(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=l(this,n,f).call(this,this.__internal__.serial.port);return e&&!t&&l(this,n,y).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=l(this,n,f).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(),l(this,n,y).call(this,e)}async connect(){return new Promise((e,t)=>{M()||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 l(this,n,E).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 l(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&&l(this,n,d).call(this,this.__internal__.serial.auto_response,null),await l(this,n,U).call(this)}catch(e){this.serialErrors(e)}}async serialForget(){return await l(this,n,k).call(this)}decToHex(e){return typeof e=="string"&&(e=parseInt(e,10)),e.toString(16)}hexToDec(e){return parseInt(e,16)}hexMaker(e="00",t=2){return e.toString().padStart(t,"0").toLowerCase()}add0x(e){const t=[];return e.forEach((i,s)=>{t[s]="0x"+i}),t}bytesToHex(e){return this.add0x(Array.from(e,t=>this.hexMaker(t)))}validateBytes(e){let t=new Uint8Array(0);if(e instanceof Uint8Array)t=e;else if(typeof e=="string")t=this.parseStringToTextEncoder(e);else if(Array.isArray(e)&&typeof e[0]=="string")t=this.stringArrayToUint8Array(e);else if(Array.isArray(e)&&typeof e[0]=="number")t=new Uint8Array(e);else throw new Error("Invalid data type");return t}async appendToQueue(e,t){const i=this.validateBytes(e);if(["connect","connection:start"].includes(t)){if(this.__internal__.serial.connected)return;await this.serialConnect();return}this.__internal__.serial.queue.push({bytes:i,action:t}),this.dispatch("internal:queue",{})}serialSetConnectionConstant(e=1){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(){l(this,n,I).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(s=>s.toString(16))}parseUint8ToHex(e){return Array.from(e).map(t=>t.toString(16))}parseHexToUint8(e){return new Uint8Array(e.map(t=>parseInt(t,16)))}stringArrayToUint8Array(e){const t=[];return e.forEach(i=>{const s=i.replace("0x","");t.push(parseInt(s,16))}),new Uint8Array(t)}parseUint8ArrayToString(e){let t=new Uint8Array(0);e instanceof Uint8Array?t=e:t=this.stringArrayToUint8Array(e),e=this.parseUint8ToHex(t);const i=e.map(s=>parseInt(s,16));return this.__internal__.serial.response.replacer?String.fromCharCode(...i).replace(this.__internal__.serial.response.replacer,""):String.fromCharCode(...i)}hexToAscii(e){const t=e.toString();let i="";for(let s=0;s<t.length;s+=2)i+=String.fromCharCode(parseInt(t.substring(s,2),16));return i}asciiToHex(e){const t=[];for(let i=0,s=e.length;i<s;i++){const u=Number(e.charCodeAt(i)).toString(16);t.push(u)}return t.join("")}$checkAndDispatchConnection(){return this.isConnected}}n=new WeakSet,f=function(e){return!!(e&&e.readable&&e.writable)},y=function(e=null){this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector=0,this.dispatch("serial:disconnected",e),c.$dispatchChange(this)},m=async function(e){const t=this.__internal__.serial.port;if(!t||t&&(!t.readable||!t.writable))throw l(this,n,y).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(t.writable===null)return;const s=t.writable.getWriter();await s.write(i),s.releaseLock()},d=function(e=new Uint8Array([]),t=null){if(e&&e.length>0){const i=this.__internal__.serial.connected;if(this.__internal__.serial.connected=l(this,n,f).call(this,this.__internal__.serial.port),c.$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")this.serialMessage(this.parseUint8ToHex(e));else if(this.__internal__.serial.response.as==="uint8")this.serialMessage(e);else if(this.__internal__.serial.response.as==="string"){const s=this.parseUint8ArrayToString(e);if(this.__internal__.serial.response.limiter!==null){const u=s.split(this.__internal__.serial.response.limiter);for(const g in u)u[g]&&this.serialMessage(u[g])}else this.serialMessage(s)}else{const s=this.stringToArrayBuffer(this.parseUint8ArrayToString(e));this.serialMessage(s)}}else this.serialCorruptMessage(e,t);this.__internal__.serial.queue.length!==0&&this.dispatch("internal:queue",{})},E=async function(){const e=this.serialFilters,t=await navigator.serial.getPorts({filters:e});return e.length===0?t:t.filter(s=>{const u=s.getInfo();return e.some(g=>u.usbProductId===g.usbProductId&&u.usbVendorId===g.usbVendorId)}).filter(s=>!l(this,n,f).call(this,s))},T=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}},S=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&&l(this,n,d).call(this,this.__internal__.serial.response.buffer),this.__internal__.serial.response.buffer=new Uint8Array(0)},400)},x=async function(){if(this.__internal__.serial.response.length!==null){if(this.__internal__.serial.response.length===this.__internal__.serial.response.buffer.length)l(this,n,d).call(this,this.__internal__.serial.response.buffer),this.__internal__.serial.response.buffer=new Uint8Array(0);else if(this.__internal__.serial.response.length<this.__internal__.serial.response.buffer.length){let e=new Uint8Array(0);for(let i=0;i<this.__internal__.serial.response.length;i++)e[i]=this.__internal__.serial.response.buffer[i];if(e.length===this.__internal__.serial.response.length){l(this,n,d).call(this,e),this.__internal__.serial.response.buffer=new Uint8Array(0);return}e=new Uint8Array(0);const t=this.__internal__.serial.response.length*2;if(this.__internal__.serial.response.buffer.length===t){for(let i=14;i<t;i++)e[i-this.__internal__.serial.response.length]=this.__internal__.serial.response.buffer[i];e.length===this.__internal__.serial.response.length&&(l(this,n,d).call(this,e),this.__internal__.serial.response.buffer=new Uint8Array(0))}}}},U=async function(){const e=this.__internal__.serial.port;if(!e||!e.readable)throw new Error("Port is not readable");for(;e.readable&&this.__internal__.serial.keep_reading;){const t=e.readable.getReader();this.__internal__.serial.reader=t;try{let i=!0;for(;i;){const{value:s,done:u}=await t.read();if(u){t.releaseLock(),this.__internal__.serial.keep_reading=!1,i=!1;break}l(this,n,T).call(this,s),this.__internal__.serial.response.length===null?await l(this,n,S).call(this):await l(this,n,x).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()},k=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},P=function(){["serial:connected","serial:connecting","serial:reconnect","serial:timeout","serial:disconnected","serial:sent","serial:soft-reload","serial:message","unknown","serial:need-permission","serial:lost","serial:unsupported","serial:error","debug"].forEach(t=>{this.serialRegisterAvailableListener(t)})},D=function(){const e=this;this.on("internal:queue",async()=>{var t;await l(t=e,n,$).call(t)}),l(this,n,L).call(this)},L=function(){const e=this;navigator.serial.addEventListener("connect",async()=>{e.isDisconnected&&await e.serialConnect().catch(()=>{})})},$=async function(){if(!l(this,n,f).call(this,this.__internal__.serial.port)){l(this,n,y).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 l(this,n,m).call(this,e.bytes),this.dispatch("serial:sent",{action:e.action,bytes:e.bytes}),this.__internal__.auto_response){let s=new Uint8Array(0);try{s=this.validateBytes(this.__internal__.serial.auto_response)}catch(u){this.serialErrors(u)}l(this,n,d).call(this,s,null)}const i=[...this.__internal__.serial.queue];this.__internal__.serial.queue=i.splice(1)},q=function(e=1){this.__internal__.device_number=e,this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(e)},I=function(){this.__internal__.last_error={message:null,action:null,code:null,no_code:0}},o.Core=N,o.Devices=c,o.Dispatcher=h,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
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"})});
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.7",
4
+ "version": "1.0.8",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": "danidoble",