@myshkouski/web-serial-polyfill 2.0.0
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/.eslintrc.cjs +32 -0
- package/.github/workflows/node.js.yml +30 -0
- package/.github/workflows/npm_publish.yml +24 -0
- package/CONTRIBUTING.md +28 -0
- package/LICENSE +202 -0
- package/README.md +18 -0
- package/dist/serial.d.ts +155 -0
- package/dist/serial.js +506 -0
- package/dist/serial.js.map +1 -0
- package/package.json +29 -0
- package/serial.ts +602 -0
- package/tsconfig.json +12 -0
package/dist/serial.js
ADDED
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2019 Google LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the
|
|
5
|
+
* "License"); you may not use this file except in
|
|
6
|
+
* compliance with the License. You may obtain a copy of
|
|
7
|
+
* the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in
|
|
12
|
+
* writing, software distributed under the License is
|
|
13
|
+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
|
|
14
|
+
* OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing
|
|
16
|
+
* permissions and limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
'use strict';
|
|
19
|
+
export var SerialPolyfillProtocol;
|
|
20
|
+
(function (SerialPolyfillProtocol) {
|
|
21
|
+
SerialPolyfillProtocol[SerialPolyfillProtocol["UsbCdcAcm"] = 0] = "UsbCdcAcm";
|
|
22
|
+
})(SerialPolyfillProtocol || (SerialPolyfillProtocol = {}));
|
|
23
|
+
const kSetLineCoding = 0x20;
|
|
24
|
+
const kSetControlLineState = 0x22;
|
|
25
|
+
const kSendBreak = 0x23;
|
|
26
|
+
const kDefaultBufferSize = 255;
|
|
27
|
+
const kDefaultDataBits = 8;
|
|
28
|
+
const kDefaultParity = 'none';
|
|
29
|
+
const kDefaultStopBits = 1;
|
|
30
|
+
const kAcceptableDataBits = [16, 8, 7, 6, 5];
|
|
31
|
+
const kAcceptableStopBits = [1, 2];
|
|
32
|
+
const kAcceptableParity = ['none', 'even', 'odd'];
|
|
33
|
+
const kParityIndexMapping = ['none', 'odd', 'even'];
|
|
34
|
+
const kStopBitsIndexMapping = [1, 1.5, 2];
|
|
35
|
+
const kDefaultPolyfillOptions = {
|
|
36
|
+
protocol: SerialPolyfillProtocol.UsbCdcAcm,
|
|
37
|
+
usbControlInterfaceClass: 2,
|
|
38
|
+
usbTransferInterfaceClass: 10,
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Utility function to get the interface implementing a desired class.
|
|
42
|
+
* @param {USBDevice} device The USB device.
|
|
43
|
+
* @param {number} classCode The desired interface class.
|
|
44
|
+
* @return {USBInterface} The first interface found that implements the desired
|
|
45
|
+
* class.
|
|
46
|
+
* @throws TypeError if no interface is found.
|
|
47
|
+
*/
|
|
48
|
+
function findInterface(device, classCode) {
|
|
49
|
+
const configuration = device.configurations[0];
|
|
50
|
+
for (const iface of configuration.interfaces) {
|
|
51
|
+
const alternate = iface.alternates[0];
|
|
52
|
+
if (alternate.interfaceClass === classCode) {
|
|
53
|
+
return iface;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
throw new TypeError(`Unable to find interface with class ${classCode}.`);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Utility function to get an endpoint with a particular direction.
|
|
60
|
+
* @param {USBInterface} iface The interface to search.
|
|
61
|
+
* @param {USBDirection} direction The desired transfer direction.
|
|
62
|
+
* @return {USBEndpoint} The first endpoint with the desired transfer direction.
|
|
63
|
+
* @throws TypeError if no endpoint is found.
|
|
64
|
+
*/
|
|
65
|
+
function findEndpoint(iface, direction) {
|
|
66
|
+
const alternate = iface.alternates[0];
|
|
67
|
+
for (const endpoint of alternate.endpoints) {
|
|
68
|
+
if (endpoint.direction == direction) {
|
|
69
|
+
return endpoint;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
throw new TypeError(`Interface ${iface.interfaceNumber} does not have an ` +
|
|
73
|
+
`${direction} endpoint.`);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Implementation of the underlying source API[1] which reads data from a USB
|
|
77
|
+
* endpoint. This can be used to construct a ReadableStream.
|
|
78
|
+
*
|
|
79
|
+
* [1]: https://streams.spec.whatwg.org/#underlying-source-api
|
|
80
|
+
*/
|
|
81
|
+
class UsbEndpointUnderlyingSource {
|
|
82
|
+
/**
|
|
83
|
+
* Constructs a new UnderlyingSource that will pull data from the specified
|
|
84
|
+
* endpoint on the given USB device.
|
|
85
|
+
*
|
|
86
|
+
* @param {USBDevice} device
|
|
87
|
+
* @param {USBEndpoint} endpoint
|
|
88
|
+
* @param {function} onError function to be called on error
|
|
89
|
+
*/
|
|
90
|
+
constructor(device, endpoint, onError) {
|
|
91
|
+
this.type = 'bytes';
|
|
92
|
+
this.device_ = device;
|
|
93
|
+
this.endpoint_ = endpoint;
|
|
94
|
+
this.onError_ = onError;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Reads a chunk of data from the device.
|
|
98
|
+
*
|
|
99
|
+
* @param {ReadableByteStreamController} controller
|
|
100
|
+
*/
|
|
101
|
+
pull(controller) {
|
|
102
|
+
(async () => {
|
|
103
|
+
var _a;
|
|
104
|
+
let chunkSize;
|
|
105
|
+
if (controller.desiredSize) {
|
|
106
|
+
const d = controller.desiredSize / this.endpoint_.packetSize;
|
|
107
|
+
chunkSize = Math.ceil(d) * this.endpoint_.packetSize;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
chunkSize = this.endpoint_.packetSize;
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
const result = await this.device_.transferIn(this.endpoint_.endpointNumber, chunkSize);
|
|
114
|
+
if (result.status != 'ok') {
|
|
115
|
+
controller.error(`USB error: ${result.status}`);
|
|
116
|
+
this.onError_();
|
|
117
|
+
}
|
|
118
|
+
if ((_a = result.data) === null || _a === void 0 ? void 0 : _a.buffer) {
|
|
119
|
+
const chunk = new Uint8Array(result.data.buffer, result.data.byteOffset, result.data.byteLength);
|
|
120
|
+
controller.enqueue(chunk);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
controller.error(error.toString());
|
|
125
|
+
this.onError_();
|
|
126
|
+
}
|
|
127
|
+
})();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Implementation of the underlying sink API[2] which writes data to a USB
|
|
132
|
+
* endpoint. This can be used to construct a WritableStream.
|
|
133
|
+
*
|
|
134
|
+
* [2]: https://streams.spec.whatwg.org/#underlying-sink-api
|
|
135
|
+
*/
|
|
136
|
+
class UsbEndpointUnderlyingSink {
|
|
137
|
+
/**
|
|
138
|
+
* Constructs a new UnderlyingSink that will write data to the specified
|
|
139
|
+
* endpoint on the given USB device.
|
|
140
|
+
*
|
|
141
|
+
* @param {USBDevice} device
|
|
142
|
+
* @param {USBEndpoint} endpoint
|
|
143
|
+
* @param {function} onError function to be called on error
|
|
144
|
+
*/
|
|
145
|
+
constructor(device, endpoint, onError) {
|
|
146
|
+
this.device_ = device;
|
|
147
|
+
this.endpoint_ = endpoint;
|
|
148
|
+
this.onError_ = onError;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Writes a chunk to the device.
|
|
152
|
+
*
|
|
153
|
+
* @param {Uint8Array} chunk
|
|
154
|
+
* @param {WritableStreamDefaultController} controller
|
|
155
|
+
*/
|
|
156
|
+
async write(chunk, controller) {
|
|
157
|
+
try {
|
|
158
|
+
const result = await this.device_.transferOut(this.endpoint_.endpointNumber, chunk);
|
|
159
|
+
if (result.status != 'ok') {
|
|
160
|
+
controller.error(result.status);
|
|
161
|
+
this.onError_();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
controller.error(error.toString());
|
|
166
|
+
this.onError_();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/** a class used to control serial devices over WebUSB */
|
|
171
|
+
export class SerialPort {
|
|
172
|
+
/**
|
|
173
|
+
* constructor taking a WebUSB device that creates a SerialPort instance.
|
|
174
|
+
* @param {USBDevice} device A device acquired from the WebUSB API
|
|
175
|
+
* @param {SerialPolyfillOptions} polyfillOptions Optional options to
|
|
176
|
+
* configure the polyfill.
|
|
177
|
+
*/
|
|
178
|
+
constructor(device, polyfillOptions) {
|
|
179
|
+
this.polyfillOptions_ = Object.assign(Object.assign({}, kDefaultPolyfillOptions), polyfillOptions);
|
|
180
|
+
this.outputSignals_ = {
|
|
181
|
+
dataTerminalReady: false,
|
|
182
|
+
requestToSend: false,
|
|
183
|
+
break: false,
|
|
184
|
+
};
|
|
185
|
+
this.device_ = device;
|
|
186
|
+
this.controlInterface_ = findInterface(this.device_, this.polyfillOptions_.usbControlInterfaceClass);
|
|
187
|
+
this.transferInterface_ = findInterface(this.device_, this.polyfillOptions_.usbTransferInterfaceClass);
|
|
188
|
+
this.inEndpoint_ = findEndpoint(this.transferInterface_, 'in');
|
|
189
|
+
this.outEndpoint_ = findEndpoint(this.transferInterface_, 'out');
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Getter for the readable attribute. Constructs a new ReadableStream as
|
|
193
|
+
* necessary.
|
|
194
|
+
* @return {ReadableStream} the current readable stream
|
|
195
|
+
*/
|
|
196
|
+
get readable() {
|
|
197
|
+
var _a;
|
|
198
|
+
if (!this.readable_ && this.device_.opened) {
|
|
199
|
+
this.readable_ = new ReadableStream(new UsbEndpointUnderlyingSource(this.device_, this.inEndpoint_, () => {
|
|
200
|
+
this.readable_ = null;
|
|
201
|
+
}), {
|
|
202
|
+
highWaterMark: (_a = this.serialOptions_.bufferSize) !== null && _a !== void 0 ? _a : kDefaultBufferSize,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
return this.readable_;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Getter for the writable attribute. Constructs a new WritableStream as
|
|
209
|
+
* necessary.
|
|
210
|
+
* @return {WritableStream} the current writable stream
|
|
211
|
+
*/
|
|
212
|
+
get writable() {
|
|
213
|
+
var _a;
|
|
214
|
+
if (!this.writable_ && this.device_.opened) {
|
|
215
|
+
this.writable_ = new WritableStream(new UsbEndpointUnderlyingSink(this.device_, this.outEndpoint_, () => {
|
|
216
|
+
this.writable_ = null;
|
|
217
|
+
}), new ByteLengthQueuingStrategy({
|
|
218
|
+
highWaterMark: (_a = this.serialOptions_.bufferSize) !== null && _a !== void 0 ? _a : kDefaultBufferSize,
|
|
219
|
+
}));
|
|
220
|
+
}
|
|
221
|
+
return this.writable_;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* a function that opens the device and claims all interfaces needed to
|
|
225
|
+
* control and communicate to and from the serial device
|
|
226
|
+
* @param {SerialOptions} options Object containing serial options
|
|
227
|
+
* @return {Promise<void>} A promise that will resolve when device is ready
|
|
228
|
+
* for communication
|
|
229
|
+
*/
|
|
230
|
+
async open(options) {
|
|
231
|
+
this.serialOptions_ = options;
|
|
232
|
+
this.validateOptions();
|
|
233
|
+
try {
|
|
234
|
+
await this.device_.open();
|
|
235
|
+
if (this.device_.configuration === null) {
|
|
236
|
+
await this.device_.selectConfiguration(1);
|
|
237
|
+
}
|
|
238
|
+
await this.device_.claimInterface(this.controlInterface_.interfaceNumber);
|
|
239
|
+
if (this.controlInterface_ !== this.transferInterface_) {
|
|
240
|
+
await this.device_.claimInterface(this.transferInterface_.interfaceNumber);
|
|
241
|
+
}
|
|
242
|
+
await this.setLineCoding();
|
|
243
|
+
await this.setSignals({ dataTerminalReady: true });
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
if (this.device_.opened) {
|
|
247
|
+
await this.device_.close();
|
|
248
|
+
}
|
|
249
|
+
throw new Error('Error setting up device: ' + error.toString());
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Closes the port.
|
|
254
|
+
*
|
|
255
|
+
* @return {Promise<void>} A promise that will resolve when the port is
|
|
256
|
+
* closed.
|
|
257
|
+
*/
|
|
258
|
+
async close() {
|
|
259
|
+
const promises = [];
|
|
260
|
+
if (this.readable_) {
|
|
261
|
+
promises.push(this.readable_.cancel());
|
|
262
|
+
}
|
|
263
|
+
if (this.writable_) {
|
|
264
|
+
promises.push(this.writable_.abort());
|
|
265
|
+
}
|
|
266
|
+
await Promise.all(promises);
|
|
267
|
+
this.readable_ = null;
|
|
268
|
+
this.writable_ = null;
|
|
269
|
+
if (this.device_.opened) {
|
|
270
|
+
await this.setSignals({ dataTerminalReady: false, requestToSend: false });
|
|
271
|
+
await this.device_.close();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Forgets the port.
|
|
276
|
+
*
|
|
277
|
+
* @return {Promise<void>} A promise that will resolve when the port is
|
|
278
|
+
* forgotten.
|
|
279
|
+
*/
|
|
280
|
+
async forget() {
|
|
281
|
+
return this.device_.forget();
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* A function that returns properties of the device.
|
|
285
|
+
* @return {SerialPortInfo} Device properties.
|
|
286
|
+
*/
|
|
287
|
+
getInfo() {
|
|
288
|
+
return {
|
|
289
|
+
usbVendorId: this.device_.vendorId,
|
|
290
|
+
usbProductId: this.device_.productId,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* A function used to change the serial settings of the device
|
|
295
|
+
* @param {object} options the object which carries serial settings data
|
|
296
|
+
* @return {Promise<void>} A promise that will resolve when the options are
|
|
297
|
+
* set
|
|
298
|
+
*/
|
|
299
|
+
reconfigure(options) {
|
|
300
|
+
this.serialOptions_ = Object.assign(Object.assign({}, this.serialOptions_), options);
|
|
301
|
+
this.validateOptions();
|
|
302
|
+
return this.setLineCoding();
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Sets control signal state for the port.
|
|
306
|
+
* @param {SerialOutputSignals} signals The signals to enable or disable.
|
|
307
|
+
* @return {Promise<void>} a promise that is resolved when the signal state
|
|
308
|
+
* has been changed.
|
|
309
|
+
*/
|
|
310
|
+
async setSignals(signals) {
|
|
311
|
+
this.outputSignals_ = Object.assign(Object.assign({}, this.outputSignals_), signals);
|
|
312
|
+
if (signals.dataTerminalReady !== undefined ||
|
|
313
|
+
signals.requestToSend !== undefined) {
|
|
314
|
+
// The Set_Control_Line_State command expects a bitmap containing the
|
|
315
|
+
// values of all output signals that should be enabled or disabled.
|
|
316
|
+
//
|
|
317
|
+
// Ref: USB CDC specification version 1.1 §6.2.14.
|
|
318
|
+
const value = (this.outputSignals_.dataTerminalReady ? 1 << 0 : 0) |
|
|
319
|
+
(this.outputSignals_.requestToSend ? 1 << 1 : 0);
|
|
320
|
+
await this.device_.controlTransferOut({
|
|
321
|
+
'requestType': 'class',
|
|
322
|
+
'recipient': 'interface',
|
|
323
|
+
'request': kSetControlLineState,
|
|
324
|
+
'value': value,
|
|
325
|
+
'index': this.controlInterface_.interfaceNumber,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
if (signals.break !== undefined) {
|
|
329
|
+
// The SendBreak command expects to be given a duration for how long the
|
|
330
|
+
// break signal should be asserted. Passing 0xFFFF enables the signal
|
|
331
|
+
// until 0x0000 is send.
|
|
332
|
+
//
|
|
333
|
+
// Ref: USB CDC specification version 1.1 §6.2.15.
|
|
334
|
+
const value = this.outputSignals_.break ? 0xFFFF : 0x0000;
|
|
335
|
+
await this.device_.controlTransferOut({
|
|
336
|
+
'requestType': 'class',
|
|
337
|
+
'recipient': 'interface',
|
|
338
|
+
'request': kSendBreak,
|
|
339
|
+
'value': value,
|
|
340
|
+
'index': this.controlInterface_.interfaceNumber,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Checks the serial options for validity and throws an error if it is
|
|
346
|
+
* not valid
|
|
347
|
+
*/
|
|
348
|
+
validateOptions() {
|
|
349
|
+
if (!this.isValidBaudRate(this.serialOptions_.baudRate)) {
|
|
350
|
+
throw new RangeError('invalid Baud Rate ' + this.serialOptions_.baudRate);
|
|
351
|
+
}
|
|
352
|
+
if (!this.isValidDataBits(this.serialOptions_.dataBits)) {
|
|
353
|
+
throw new RangeError('invalid dataBits ' + this.serialOptions_.dataBits);
|
|
354
|
+
}
|
|
355
|
+
if (!this.isValidStopBits(this.serialOptions_.stopBits)) {
|
|
356
|
+
throw new RangeError('invalid stopBits ' + this.serialOptions_.stopBits);
|
|
357
|
+
}
|
|
358
|
+
if (!this.isValidParity(this.serialOptions_.parity)) {
|
|
359
|
+
throw new RangeError('invalid parity ' + this.serialOptions_.parity);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Checks the baud rate for validity
|
|
364
|
+
* @param {number} baudRate the baud rate to check
|
|
365
|
+
* @return {boolean} A boolean that reflects whether the baud rate is valid
|
|
366
|
+
*/
|
|
367
|
+
isValidBaudRate(baudRate) {
|
|
368
|
+
return baudRate % 1 === 0;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Checks the data bits for validity
|
|
372
|
+
* @param {number} dataBits the data bits to check
|
|
373
|
+
* @return {boolean} A boolean that reflects whether the data bits setting is
|
|
374
|
+
* valid
|
|
375
|
+
*/
|
|
376
|
+
isValidDataBits(dataBits) {
|
|
377
|
+
if (typeof dataBits === 'undefined') {
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
return kAcceptableDataBits.includes(dataBits);
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Checks the stop bits for validity
|
|
384
|
+
* @param {number} stopBits the stop bits to check
|
|
385
|
+
* @return {boolean} A boolean that reflects whether the stop bits setting is
|
|
386
|
+
* valid
|
|
387
|
+
*/
|
|
388
|
+
isValidStopBits(stopBits) {
|
|
389
|
+
if (typeof stopBits === 'undefined') {
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
return kAcceptableStopBits.includes(stopBits);
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Checks the parity for validity
|
|
396
|
+
* @param {string} parity the parity to check
|
|
397
|
+
* @return {boolean} A boolean that reflects whether the parity is valid
|
|
398
|
+
*/
|
|
399
|
+
isValidParity(parity) {
|
|
400
|
+
if (typeof parity === 'undefined') {
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
return kAcceptableParity.includes(parity);
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* sends the options alog the control interface to set them on the device
|
|
407
|
+
* @return {Promise} a promise that will resolve when the options are set
|
|
408
|
+
*/
|
|
409
|
+
async setLineCoding() {
|
|
410
|
+
var _a, _b, _c;
|
|
411
|
+
// Ref: USB CDC specification version 1.1 §6.2.12.
|
|
412
|
+
const buffer = new ArrayBuffer(7);
|
|
413
|
+
const view = new DataView(buffer);
|
|
414
|
+
view.setUint32(0, this.serialOptions_.baudRate, true);
|
|
415
|
+
view.setUint8(4, kStopBitsIndexMapping.indexOf((_a = this.serialOptions_.stopBits) !== null && _a !== void 0 ? _a : kDefaultStopBits));
|
|
416
|
+
view.setUint8(5, kParityIndexMapping.indexOf((_b = this.serialOptions_.parity) !== null && _b !== void 0 ? _b : kDefaultParity));
|
|
417
|
+
view.setUint8(6, (_c = this.serialOptions_.dataBits) !== null && _c !== void 0 ? _c : kDefaultDataBits);
|
|
418
|
+
const result = await this.device_.controlTransferOut({
|
|
419
|
+
'requestType': 'class',
|
|
420
|
+
'recipient': 'interface',
|
|
421
|
+
'request': kSetLineCoding,
|
|
422
|
+
'value': 0x00,
|
|
423
|
+
'index': this.controlInterface_.interfaceNumber,
|
|
424
|
+
}, buffer);
|
|
425
|
+
if (result.status != 'ok') {
|
|
426
|
+
throw new DOMException('NetworkError', 'Failed to set line coding.');
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
/** generic implementation of navigator.serial object */
|
|
431
|
+
export class BaseSerial {
|
|
432
|
+
/**
|
|
433
|
+
* @param {USB} usb Instance of navigator.usb object
|
|
434
|
+
*/
|
|
435
|
+
constructor(usb) {
|
|
436
|
+
this.usb = usb;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Requests permission to access a new port.
|
|
440
|
+
*
|
|
441
|
+
* @param {SerialPortRequestOptions} options
|
|
442
|
+
* @param {SerialPolyfillOptions} polyfillOptions
|
|
443
|
+
* @return {Promise<SerialPort>}
|
|
444
|
+
*/
|
|
445
|
+
async requestPort(options, polyfillOptions) {
|
|
446
|
+
polyfillOptions = Object.assign(Object.assign({}, kDefaultPolyfillOptions), polyfillOptions);
|
|
447
|
+
const usbFilters = [];
|
|
448
|
+
if (options && options.filters) {
|
|
449
|
+
for (const filter of options.filters) {
|
|
450
|
+
const usbFilter = {
|
|
451
|
+
classCode: polyfillOptions.usbControlInterfaceClass,
|
|
452
|
+
};
|
|
453
|
+
if (filter.usbVendorId !== undefined) {
|
|
454
|
+
usbFilter.vendorId = filter.usbVendorId;
|
|
455
|
+
}
|
|
456
|
+
if (filter.usbProductId !== undefined) {
|
|
457
|
+
usbFilter.productId = filter.usbProductId;
|
|
458
|
+
}
|
|
459
|
+
usbFilters.push(usbFilter);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (usbFilters.length === 0) {
|
|
463
|
+
usbFilters.push({
|
|
464
|
+
classCode: polyfillOptions.usbControlInterfaceClass,
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
const device = await this.usb.requestDevice({ 'filters': usbFilters });
|
|
468
|
+
const port = this.createPort(device, polyfillOptions);
|
|
469
|
+
return port;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Get the set of currently available ports.
|
|
473
|
+
*
|
|
474
|
+
* @param {SerialPolyfillOptions} polyfillOptions Polyfill configuration that
|
|
475
|
+
* should be applied to these ports.
|
|
476
|
+
* @return {Promise<SerialPort[]>} a promise that is resolved with a list of
|
|
477
|
+
* ports.
|
|
478
|
+
*/
|
|
479
|
+
async getPorts(polyfillOptions) {
|
|
480
|
+
polyfillOptions = Object.assign(Object.assign({}, kDefaultPolyfillOptions), polyfillOptions);
|
|
481
|
+
const devices = await this.usb.getDevices();
|
|
482
|
+
const ports = [];
|
|
483
|
+
devices.forEach((device) => {
|
|
484
|
+
try {
|
|
485
|
+
const port = this.createPort(device, polyfillOptions);
|
|
486
|
+
ports.push(port);
|
|
487
|
+
}
|
|
488
|
+
catch (e) {
|
|
489
|
+
// Skip unrecognized port.
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
return ports;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
/** default implementation of the global navigator.serial object */
|
|
496
|
+
export class Serial extends BaseSerial {
|
|
497
|
+
/**
|
|
498
|
+
* @param {USBDevice} device
|
|
499
|
+
* @param {SerialPolyfillOptions} options
|
|
500
|
+
* @return {SerialPort} Default serial port implementation
|
|
501
|
+
*/
|
|
502
|
+
createPort(device, options) {
|
|
503
|
+
return new SerialPort(device, options);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
//# sourceMappingURL=serial.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serial.js","sourceRoot":"","sources":["../serial.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,YAAY,CAAC;AAEb,MAAM,CAAN,IAAY,sBAEX;AAFD,WAAY,sBAAsB;IAChC,6EAAS,CAAA;AACX,CAAC,EAFW,sBAAsB,KAAtB,sBAAsB,QAEjC;AAQD,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAClC,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,gBAA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C,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YACzB,IAAI;gBACF,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;gBACtD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAClB;YAAC,OAAO,CAAC,EAAE;gBACV,0BAA0B;aAC3B;QACH,CAAC,CAAC,CAAC;QACH,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,mEAAmE;AACnE,MAAM,OAAO,MAAO,SAAQ,UAAsB;IAChD;;;;OAIG;IACO,UAAU,CAAC,MAAiB,EAClC,OAA+B;QACjC,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@myshkouski/web-serial-polyfill",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "An implementation of the [Serial API](https://wicg.github.io/serial) on top of the [WebUSB API](https://wicg.github.io/webusb) for use with USB-to-serial adapters. Use of this library is limited to hardware and platforms where the device is accessible via the WebUSB API because it has not been claimed by a built-in device driver. This project will be used to prototype the design of the Serial API.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/serial.js",
|
|
7
|
+
"types": "./dist/serial.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"lint": "eslint serial.ts",
|
|
10
|
+
"build": "tsc -d",
|
|
11
|
+
"prepublish": "tsc -d"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/google/web-serial-polyfill.git"
|
|
16
|
+
},
|
|
17
|
+
"author": "James C Hollyer",
|
|
18
|
+
"license": "Apache",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/w3c-web-serial": "^1.0.3",
|
|
21
|
+
"@types/w3c-web-usb": "^1.0.6",
|
|
22
|
+
"@types/web": "^0.0.71",
|
|
23
|
+
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
|
24
|
+
"@typescript-eslint/parser": "^5.33.0",
|
|
25
|
+
"eslint": "^8.21.0",
|
|
26
|
+
"eslint-config-google": "^0.14.0",
|
|
27
|
+
"typescript": "^4.7.4"
|
|
28
|
+
}
|
|
29
|
+
}
|