usb 1.9.1 → 2.0.1

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.
Files changed (69) hide show
  1. package/.eslintignore +4 -0
  2. package/.eslintrc.json +87 -0
  3. package/.gitattributes +1 -0
  4. package/.vscode/launch.json +15 -0
  5. package/.vscode/tasks.json +23 -0
  6. package/CHANGELOG.md +13 -0
  7. package/README.md +400 -175
  8. package/dist/index.d.ts +17 -0
  9. package/dist/index.js +133 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/usb/bindings.d.ts +253 -0
  12. package/dist/usb/bindings.js +10 -0
  13. package/dist/usb/bindings.js.map +1 -0
  14. package/dist/usb/capability.d.ts +14 -0
  15. package/dist/usb/capability.js +18 -0
  16. package/dist/usb/capability.js.map +1 -0
  17. package/dist/usb/descriptors.d.ts +129 -0
  18. package/dist/usb/descriptors.js +3 -0
  19. package/dist/usb/descriptors.js.map +1 -0
  20. package/dist/usb/device.d.ts +94 -0
  21. package/dist/usb/device.js +300 -0
  22. package/dist/usb/device.js.map +1 -0
  23. package/dist/usb/endpoint.d.ts +91 -0
  24. package/dist/usb/endpoint.js +236 -0
  25. package/dist/usb/endpoint.js.map +1 -0
  26. package/dist/usb/index.d.ts +25 -0
  27. package/dist/usb/index.js +116 -0
  28. package/dist/usb/index.js.map +1 -0
  29. package/dist/usb/interface.d.ts +78 -0
  30. package/dist/usb/interface.js +137 -0
  31. package/dist/usb/interface.js.map +1 -0
  32. package/dist/webusb/index.d.ts +56 -0
  33. package/dist/webusb/index.js +412 -0
  34. package/dist/webusb/index.js.map +1 -0
  35. package/dist/webusb/mutex.d.ts +22 -0
  36. package/dist/webusb/mutex.js +89 -0
  37. package/dist/webusb/mutex.js.map +1 -0
  38. package/dist/webusb/webusb-device.d.ts +49 -0
  39. package/dist/webusb/webusb-device.js +888 -0
  40. package/dist/webusb/webusb-device.js.map +1 -0
  41. package/package.json +28 -15
  42. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  43. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  44. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  45. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  46. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  47. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  48. package/prebuilds/linux-ia32/node.napi.node +0 -0
  49. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  50. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  51. package/prebuilds/win32-ia32/node.napi.node +0 -0
  52. package/prebuilds/win32-x64/node.napi.node +0 -0
  53. package/src/device.cc +6 -6
  54. package/test/usb.coffee +13 -7
  55. package/test/webusb.coffee +189 -0
  56. package/tsc/index.ts +67 -0
  57. package/tsc/usb/bindings.ts +304 -0
  58. package/tsc/usb/capability.ts +22 -0
  59. package/tsc/usb/descriptors.ts +180 -0
  60. package/tsc/usb/device.ts +325 -0
  61. package/tsc/usb/endpoint.ts +228 -0
  62. package/tsc/usb/index.ts +111 -0
  63. package/tsc/usb/interface.ts +172 -0
  64. package/tsc/webusb/index.ts +363 -0
  65. package/tsc/webusb/mutex.ts +38 -0
  66. package/tsc/webusb/webusb-device.ts +534 -0
  67. package/tsconfig.json +17 -0
  68. package/typedoc.json +9 -0
  69. package/usb.js +0 -573
package/README.md CHANGED
@@ -1,112 +1,340 @@
1
- USB Library for Node.JS
2
- ===============================
1
+ # USB Library for Node.JS
3
2
 
4
3
  [![Build Status](https://github.com/node-usb/node-usb/workflows/prebuild/badge.svg)](https://github.com/node-usb/node-usb/actions)
4
+ [![npm](https://img.shields.io/npm/dm/usb.svg)](https://www.npmjs.com/package/usb)
5
+ [![Licence MIT](https://img.shields.io/badge/licence-MIT-blue.svg)](http://opensource.org/licenses/MIT)
5
6
 
6
- Node.JS library for communicating with USB devices in JavaScript / CoffeeScript.
7
+ Node.JS library for communicating with USB devices.
7
8
 
8
- This is a refactoring / rewrite of Christopher Klein's [node-usb](https://github.com/schakko/node-usb). The API is not compatible (hopefully you find it an improvement).
9
+ This is a refactoring / rewrite of Christopher Klein's [node-usb](https://github.com/schakko/node-usb).
9
10
 
10
- It's based entirely on libusb's asynchronous API for better efficiency, and provides a stream API for continuously streaming data or events.
11
+ # Prerequisites
11
12
 
12
- Installation
13
- ============
13
+ [Node.js >= v10.16.0](https://nodejs.org), which includes `npm`.
14
14
 
15
- Libusb is included as a submodule. On Linux, you'll need libudev to build libusb. On Ubuntu/Debian: `sudo apt-get install build-essential libudev-dev`
15
+ On Windows, use [Zadig](http://zadig.akeo.ie/) to install the WinUSB driver for your USB device. Otherwise you will get `LIBUSB_ERROR_NOT_SUPPORTED` when attempting to open devices.
16
16
 
17
- Then, just run
17
+ # Installation
18
18
 
19
- npm install usb
19
+ Native modules are bundled using `prebuildify`, so installation should be as simple as installing the package.
20
20
 
21
- to install from npm. See the bottom of this page for instructions for building from a git checkout.
21
+ With `npm`:
22
22
 
23
- ### Windows
24
- Use [Zadig](http://zadig.akeo.ie/) to install the WinUSB driver for your USB device. Otherwise you will get `LIBUSB_ERROR_NOT_SUPPORTED` when attempting to open devices.
23
+ ```bash
24
+ npm install usb
25
+ ```
25
26
 
27
+ With `yarn`:
26
28
 
27
- API
28
- ===
29
+ ```bash
30
+ yarn add usb
31
+ ```
29
32
 
30
- var usb = require('usb')
33
+ __Note:__ the library is now written in `TypeScript`, so a separate types file is not longer required to be installed.
31
34
 
32
- usb
33
- ---
35
+ # License
36
+ [MIT](LICENSE.md)
34
37
 
35
- Top-level object.
38
+ Note that the compiled Node extension includes [libusb](https://github.com/libusb/libusb), and is thus subject to the [LGPL](https://github.com/libusb/libusb/blob/master/COPYING).
36
39
 
37
- ### usb.getDeviceList()
38
- Return a list of `Device` objects for the USB devices attached to the system.
40
+ # Limitations
41
+ Does not support:
42
+
43
+ - Configurations other than the default one
44
+ - Isochronous transfers
45
+
46
+ # Getting Started
47
+ Use the following examples to kickstart your development. Once you have a desired device, use the APIs below to interact with it.
48
+
49
+ ## Migrating to `v2.0.0`
50
+ The legacy API exists on an object called `usb` on the main import and the convenience functions exist as top level objects.
51
+
52
+ To use `v2.0.0` simply update your import statements and the function calls;
53
+
54
+ ```typescript
55
+ // import * as usb from 'usb';
56
+ // const devices: usb.Device[] = usb.getDeviceList();
57
+
58
+ import { usb, getDeviceList } from 'usb';
59
+ const devices: usb.Device[] = getDeviceList();
60
+ ```
61
+
62
+ ## List all legacy devices
63
+ ```typescript
64
+ import { getDeviceList } from 'usb';
65
+
66
+ const devices = getDeviceList();
67
+
68
+ for (const device of devices) {
69
+ console.log(device); // Legacy device
70
+ }
71
+ ```
72
+
73
+ ## Find legacy device by vid/pid
74
+ ```typescript
75
+ import { findByIds } from 'usb';
76
+
77
+ const device = findByIds(0x59e3, 0x0a23);
78
+
79
+ if (device) {
80
+ console.log(device); // Legacy device
81
+ }
82
+ ```
83
+
84
+ ## Find legacy device by SerialNumber
85
+ ```typescript
86
+ import { findBySerialNumber } from 'usb';
87
+
88
+ (async () => {
89
+ // Uses a blocking call, so is async
90
+ const device = await findBySerialNumber('TEST_DEVICE');
91
+
92
+ if (device) {
93
+ console.log(device); // Legacy device
94
+ }
95
+ })();
96
+ ```
97
+
98
+ ## Turn legacy Device into WebUSB compatible device
99
+ ```typescript
100
+ import { findBySerialNumber, WebUSBDevice } from 'usb';
101
+
102
+ (async () => {
103
+ // Uses a blocking call, so is async
104
+ const device = await findBySerialNumber('TEST_DEVICE');
105
+
106
+ // Uses blocking calls, so is async
107
+ const webDevice = await WebUSBDevice.createInstance(device);
108
+
109
+ if (webDevice) {
110
+ console.log(webDevice); // WebUSB device
111
+ }
112
+ })();
113
+ ```
114
+
115
+ ## Use WebUSB approach to find a device
116
+ ```typescript
117
+ import { webusb } from 'usb';
118
+
119
+ (async () => {
120
+ // Returns first matching device
121
+ const device = await webusb.requestDevice({
122
+ filters: [{}]
123
+ })
124
+
125
+ if (device) {
126
+ console.log(device); // WebUSB device
127
+ }
128
+ })();
129
+ ```
130
+
131
+ ## Use WebUSB approach to find a device with custom selection method
132
+ ```typescript
133
+ import { WebUSB } from 'usb';
134
+
135
+ (async () => {
136
+ const customWebUSB = new WebUSB({
137
+ // This function can return a promise which allows a UI to be displayed if required
138
+ devicesFound: devices => devices.find(device => device.serialNumber === 'TEST_DEVICE')
139
+ });
140
+
141
+ // Returns device based on injected 'devicesFound' function
142
+ const device = await customWebUSB.requestDevice({
143
+ filters: [{}]
144
+ })
145
+
146
+ if (device) {
147
+ console.log(device); // WebUSB device
148
+ }
149
+ })();
150
+ ```
151
+
152
+ ## Use WebUSB approach to list authorised devices
153
+ ```typescript
154
+ import { webusb } from 'usb';
155
+
156
+ (async () => {
157
+ // The default webusb instance follows the WebUSB spec and only returns authorised devices
158
+ const devices = await webusb.getDevices();
159
+
160
+ for (const device of devices) {
161
+ console.log(device); // WebUSB device
162
+ }
163
+ })();
164
+ ```
165
+
166
+ ## Use WebUSB approach to list all devices
167
+ ```typescript
168
+ import { WebUSB } from 'usb';
169
+
170
+ (async () => {
171
+ const customWebUSB = new WebUSB({
172
+ // Bypass cheking for authorised devices
173
+ allowAllDevices: true
174
+ });
175
+
176
+ // Uses blocking calls, so is async
177
+ const devices = await customWebUSB.getDevices();
178
+
179
+ for (const device of devices) {
180
+ console.log(device); // WebUSB device
181
+ }
182
+ })();
183
+ ```
184
+
185
+ ## Electron
186
+ Please refer to the maintained example for using `node-usb` in electron:
187
+
188
+ https://github.com/node-usb/node-usb-example-electron
189
+
190
+ # APIs
191
+ Since `v2.0.0`, the `node-usb` library supports two APIs:
192
+
193
+ - `WebUSB` which follows the [WebUSB Specification](https://wicg.github.io/webusb/) (recommended)
194
+ - `Legacy API` which retains the previous 'non-blocking' API
195
+
196
+ Convenience methods also exist to easily list or find devices as well as convert between a legacy usb.Device device and WebUSB device.
197
+
198
+ Full auto-generated API documentation can be seen here:
199
+
200
+ https://node-usb.github.io/node-usb/
201
+
202
+ ## Convenience Functions
203
+
204
+ ### getDeviceList()
205
+ Return a list of legacy `Device` objects for the USB devices attached to the system.
206
+
207
+ ### findByIds(vid, pid)
208
+ Convenience method to get the first legacy device with the specified VID and PID, or `undefined` if no such device is present.
209
+
210
+ ### findBySerialNumber(serialNumber)
211
+ Convenience method to get a promise of the legacy device with the specified serial number, or `undefined` if no such device is present.
212
+
213
+ ### WebUSBDevice
214
+ WebUSB Device class for wrapping a legacy Device into a WebUSB device
215
+
216
+ #### WebUSBDevice.createInstance(device)
217
+ Convenience method to return a promise of a WebUSB device based on a legacy device
218
+
219
+ ## WebUSB
220
+
221
+ Please refer to the WebUSB specification which be found here:
222
+
223
+ https://wicg.github.io/webusb/
224
+
225
+ ### Implementation Status
226
+
227
+ #### USB
39
228
 
40
- ### usb.findByIds(vid, pid)
41
- Convenience method to get the first device with the specified VID and PID, or `undefined` if no such device is present.
229
+ - [x] getDevices()
230
+ - [x] requestDevice()
42
231
 
43
- ### usb.LIBUSB_*
232
+ #### USBDevice
233
+
234
+ - [x] usbVersionMajor
235
+ - [x] usbVersionMinor
236
+ - [x] usbVersionSubminor
237
+ - [x] deviceClass
238
+ - [x] deviceSubclass
239
+ - [x] deviceProtocol
240
+ - [x] vendorId
241
+ - [x] productId
242
+ - [x] deviceVersionMajor
243
+ - [x] deviceVersionMinor
244
+ - [x] deviceVersionSubminor
245
+ - [x] manufacturerName
246
+ - [x] productName
247
+ - [x] serialNumber
248
+ - [x] configuration
249
+ - [x] configurations
250
+ - [x] opened
251
+ - [x] open()
252
+ - [x] close()
253
+ - [x] selectConfiguration()
254
+ - [x] claimInterface()
255
+ - [x] releaseInterface()
256
+ - [x] selectAlternateInterface()
257
+ - [x] controlTransferIn()
258
+ - [x] controlTransferOut() - `bytesWritten` always equals the initial buffer length
259
+ - [x] transferIn()
260
+ - [x] transferOut() - `bytesWritten` always equals the initial buffer length
261
+ - [x] clearHalt()
262
+ - [x] reset()
263
+ - [ ] isochronousTransferIn()
264
+ - [ ] isochronousTransferOut()
265
+
266
+ #### Events
267
+
268
+ - [x] connect
269
+ - [x] disconnect
270
+
271
+ ## Legacy API
272
+
273
+ ### usb
274
+ Legacy usb object.
275
+
276
+ #### usb.LIBUSB_*
44
277
  Constant properties from libusb
45
278
 
46
- ### usb.setDebugLevel(level : int)
279
+ #### usb.setDebugLevel(level : int)
47
280
  Set the libusb debug level (between 0 and 4)
48
281
 
49
- Device
50
- ------
51
-
282
+ ### Device
52
283
  Represents a USB device.
53
284
 
54
- ### .busNumber
285
+ #### .busNumber
55
286
  Integer USB device number
56
287
 
57
- ### .deviceAddress
288
+ #### .deviceAddress
58
289
  Integer USB device address
59
290
 
60
- ### .portNumbers
291
+ #### .portNumbers
61
292
  Array containing the USB device port numbers, or `undefined` if not supported on this platform.
62
293
 
63
- ### .deviceDescriptor
294
+ #### .deviceDescriptor
64
295
  Object with properties for the fields of the device descriptor:
65
296
 
66
- - bLength
67
- - bDescriptorType
68
- - bcdUSB
69
- - bDeviceClass
70
- - bDeviceSubClass
71
- - bDeviceProtocol
72
- - bMaxPacketSize0
73
- - idVendor
74
- - idProduct
75
- - bcdDevice
76
- - iManufacturer
77
- - iProduct
78
- - iSerialNumber
79
- - bNumConfigurations
80
-
81
- ### .configDescriptor
297
+ - bLength
298
+ - bDescriptorType
299
+ - bcdUSB
300
+ - bDeviceClass
301
+ - bDeviceSubClass
302
+ - bDeviceProtocol
303
+ - bMaxPacketSize0
304
+ - idVendor
305
+ - idProduct
306
+ - bcdDevice
307
+ - iManufacturer
308
+ - iProduct
309
+ - iSerialNumber
310
+ - bNumConfigurations
311
+
312
+ #### .configDescriptor
82
313
  Object with properties for the fields of the configuration descriptor:
83
314
 
84
- - bLength
85
- - bDescriptorType
86
- - wTotalLength
87
- - bNumInterfaces
88
- - bConfigurationValue
89
- - iConfiguration
90
- - bmAttributes
91
- - bMaxPower
92
- - extra (Buffer containing any extra data or additional descriptors)
93
-
94
- ### .allConfigDescriptors
95
- Contains all config descriptors of the device (same structure as .configDescriptor above)
315
+ - bLength
316
+ - bDescriptorType
317
+ - wTotalLength
318
+ - bNumInterfaces
319
+ - bConfigurationValue
320
+ - iConfiguration
321
+ - bmAttributes
322
+ - bMaxPower
323
+ - extra (Buffer containing any extra data or additional descriptors)
96
324
 
97
- ### .parent
98
- Contains the parent of the device, such as a hub. If there is no parent this property is set to `null`.
325
+ #### .allConfigDescriptors
326
+ Contains all config descriptors of the device (same structure as .configDescriptor above)
99
327
 
100
- ### .open()
328
+ #### .parent
329
+ Contains the parent of the device, such as a hub. If there is no parent this property is set to `null`.
101
330
 
331
+ #### .open()
102
332
  Open the device. All methods below require the device to be open before use.
103
333
 
104
- ### .close()
105
-
334
+ #### .close()
106
335
  Close the device.
107
336
 
108
- ### .controlTransfer(bmRequestType, bRequest, wValue, wIndex, data_or_length, callback(error, data))
109
-
337
+ #### .controlTransfer(bmRequestType, bRequest, wValue, wIndex, data_or_length, callback(error, data))
110
338
  Perform a control transfer with `libusb_control_transfer`.
111
339
 
112
340
  Parameter `data_or_length` can be a integer length for an IN transfer, or a Buffer for an out transfer. The type must match the direction specified in the MSB of bmRequestType.
@@ -115,145 +343,137 @@ The `data` parameter of the callback is always undefined for OUT transfers, or w
115
343
 
116
344
  A [package is available to calculate bmRequestType](https://www.npmjs.com/package/bmrequesttype) if needed.
117
345
 
118
- ### .setConfiguration(id, callback(error))
346
+ #### .setConfiguration(id, callback(error))
119
347
  Set the device configuration to something other than the default (0). To use this, first call `.open(false)` (which tells it not to auto configure), then before claiming an interface, call this method.
120
348
 
121
- ### .getStringDescriptor(index, callback(error, data))
349
+ #### .getStringDescriptor(index, callback(error, data))
122
350
  Perform a control transfer to retrieve a string descriptor
123
351
 
124
- ### .getBosDescriptor(callback(error, bosDescriptor))
352
+ #### .getBosDescriptor(callback(error, bosDescriptor))
125
353
  Perform a control transfer to retrieve an object with properties for the fields of the Binary Object Store descriptor:
126
354
 
127
- - bLength
128
- - bDescriptorType
129
- - wTotalLength
130
- - bNumDeviceCaps
355
+ - bLength
356
+ - bDescriptorType
357
+ - wTotalLength
358
+ - bNumDeviceCaps
131
359
 
132
- ### .getCapabilities(callback(error, capabilities))
360
+ #### .getCapabilities(callback(error, capabilities))
133
361
  Retrieve a list of Capability objects for the Binary Object Store capabilities of the device.
134
362
 
135
- ### .interface(interface)
363
+ #### .interface(interface)
136
364
  Return the interface with the specified interface number.
137
365
 
138
- ### .interfaces
366
+ #### .interfaces
139
367
  List of Interface objects for the interfaces of the default configuration of the device.
140
368
 
141
- ### .timeout
369
+ #### .timeout
142
370
  Timeout in milliseconds to use for control transfers.
143
371
 
144
- ### .reset(callback(error))
372
+ #### .reset(callback(error))
145
373
  Performs a reset of the device. Callback is called when complete.
146
374
 
375
+ ### Interface
147
376
 
148
- Interface
149
- ---------
150
-
151
- ### .endpoint(address)
377
+ #### .endpoint(address)
152
378
  Return the InEndpoint or OutEndpoint with the specified address.
153
379
 
154
- ### .endpoints
380
+ #### .endpoints
155
381
  List of endpoints on this interface: InEndpoint and OutEndpoint objects.
156
382
 
157
- ### .interface
383
+ #### .interface
158
384
  Integer interface number.
159
385
 
160
- ### .altSetting
386
+ #### .altSetting
161
387
  Integer alternate setting number.
162
388
 
163
- ### .setAltSetting(altSetting, callback(error))
389
+ #### .setAltSetting(altSetting, callback(error))
164
390
  Sets the alternate setting. It updates the `interface.endpoints` array to reflect the endpoints found in the alternate setting.
165
391
 
166
- ### .claim()
392
+ #### .claim()
167
393
  Claims the interface. This method must be called before using any endpoints of this interface.
168
394
 
169
- ### .release([closeEndpoints], callback(error))
395
+ #### .release([closeEndpoints], callback(error))
170
396
  Releases the interface and resets the alternate setting. Calls callback when complete.
171
397
 
172
398
  It is an error to release an interface with pending transfers. If the optional closeEndpoints parameter is true, any active endpoint streams are stopped (see `Endpoint.stopStream`), and the interface is released after the stream transfers are cancelled. Transfers submitted individually with `Endpoint.transfer` are not affected by this parameter.
173
399
 
174
- ### .isKernelDriverActive()
400
+ #### .isKernelDriverActive()
175
401
  Returns `false` if a kernel driver is not active; `true` if active.
176
402
 
177
- ### .detachKernelDriver()
403
+ #### .detachKernelDriver()
178
404
  Detaches the kernel driver from the interface.
179
405
 
180
- ### .attachKernelDriver()
406
+ #### .attachKernelDriver()
181
407
  Re-attaches the kernel driver for the interface.
182
408
 
183
- ### .descriptor
409
+ #### .descriptor
184
410
  Object with fields from the interface descriptor -- see libusb documentation or USB spec.
185
411
 
186
- - bLength
187
- - bDescriptorType
188
- - bInterfaceNumber
189
- - bAlternateSetting
190
- - bNumEndpoints
191
- - bInterfaceClass
192
- - bInterfaceSubClass
193
- - bInterfaceProtocol
194
- - iInterface
195
- - extra (Buffer containing any extra data or additional descriptors)
196
-
412
+ - bLength
413
+ - bDescriptorType
414
+ - bInterfaceNumber
415
+ - bAlternateSetting
416
+ - bNumEndpoints
417
+ - bInterfaceClass
418
+ - bInterfaceSubClass
419
+ - bInterfaceProtocol
420
+ - iInterface
421
+ - extra (Buffer containing any extra data or additional descriptors)
197
422
 
198
- Capability
199
- ---------
423
+ ### Capability
200
424
 
201
- ### .type
425
+ #### .type
202
426
  Integer capability type.
203
427
 
204
- ### .data
428
+ #### .data
205
429
  Buffer capability data.
206
430
 
207
- ### .descriptor
431
+ #### .descriptor
208
432
  Object with fields from the capability descriptor -- see libusb documentation or USB spec.
209
- - bLength
210
- - bDescriptorType
211
- - bDevCapabilityType
212
-
213
-
214
- Endpoint
215
- --------
433
+
434
+ - bLength
435
+ - bDescriptorType
436
+ - bDevCapabilityType
216
437
 
438
+ ### Endpoint
217
439
  Common base for InEndpoint and OutEndpoint, see below.
218
440
 
219
- ### .direction
441
+ #### .direction
220
442
  Endpoint direction: `"in"` or `"out"`.
221
443
 
222
- ### .transferType
444
+ #### .transferType
223
445
  Endpoint type: `usb.LIBUSB_TRANSFER_TYPE_BULK`, `usb.LIBUSB_TRANSFER_TYPE_INTERRUPT`, or `usb.LIBUSB_TRANSFER_TYPE_ISOCHRONOUS`.
224
446
 
225
- ### .descriptor
447
+ #### .descriptor
226
448
  Object with fields from the endpoint descriptor -- see libusb documentation or USB spec.
227
449
 
228
- - bLength
229
- - bDescriptorType
230
- - bEndpointAddress
231
- - bmAttributes
232
- - wMaxPacketSize
233
- - bInterval
234
- - bRefresh
235
- - bSynchAddress
236
- - extra (Buffer containing any extra data or additional descriptors)
237
-
238
- ### .timeout
450
+ - bLength
451
+ - bDescriptorType
452
+ - bEndpointAddress
453
+ - bmAttributes
454
+ - wMaxPacketSize
455
+ - bInterval
456
+ - bRefresh
457
+ - bSynchAddress
458
+ - extra (Buffer containing any extra data or additional descriptors)
459
+
460
+ #### .timeout
239
461
  Sets the timeout in milliseconds for transfers on this endpoint. The default, `0`, is infinite timeout.
240
462
 
241
- ### .clearHalt(callback(error))
463
+ #### .clearHalt(callback(error))
242
464
  Clear the halt/stall condition for this endpoint.
243
465
 
244
- InEndpoint
245
- ----------
246
-
466
+ ### InEndpoint
247
467
  Endpoints in the IN direction (device->PC) have this type.
248
468
 
249
- ### .transfer(length, callback(error, data))
469
+ #### .transfer(length, callback(error, data))
250
470
  Perform a transfer to read data from the endpoint.
251
471
 
252
472
  If length is greater than maxPacketSize, libusb will automatically split the transfer in multiple packets, and you will receive one callback with all data once all packets are complete.
253
473
 
254
474
  `this` in the callback is the InEndpoint object.
255
475
 
256
- ### .startPoll(nTransfers=3, transferSize=maxPacketSize)
476
+ #### .startPoll(nTransfers=3, transferSize=maxPacketSize)
257
477
  Start polling the endpoint.
258
478
 
259
479
  The library will keep `nTransfers` transfers of size `transferSize` pending in
@@ -261,85 +481,90 @@ the kernel at all times to ensure continuous data flow. This is handled by the
261
481
  libusb event thread, so it continues even if the Node v8 thread is busy. The
262
482
  `data` and `error` events are emitted as transfers complete.
263
483
 
264
- ### .stopPoll(cb)
484
+ #### .stopPoll(cb)
265
485
  Stop polling.
266
486
 
267
487
  Further data may still be received. The `end` event is emitted and the callback
268
488
  is called once all transfers have completed or canceled.
269
489
 
270
- ### Event: data(data : Buffer)
490
+ #### Event: data(data : Buffer)
271
491
  Emitted with data received by the polling transfers
272
492
 
273
- ### Event: error(error)
493
+ #### Event: error(error)
274
494
  Emitted when polling encounters an error. All in flight transfers will be automatically canceled and no further polling will be done. You have to wait for the `end` event before you can start polling again.
275
495
 
276
- ### Event: end
496
+ #### Event: end
277
497
  Emitted when polling has been canceled
278
498
 
279
- OutEndpoint
280
- -----------
281
-
499
+ ### OutEndpoint
282
500
  Endpoints in the OUT direction (PC->device) have this type.
283
501
 
284
- ### .transfer(data, callback(error))
502
+ #### .transfer(data, callback(error))
285
503
  Perform a transfer to write `data` to the endpoint.
286
504
 
287
505
  If length is greater than maxPacketSize, libusb will automatically split the transfer in multiple packets, and you will receive one callback once all packets are complete.
288
506
 
289
507
  `this` in the callback is the OutEndpoint object.
290
508
 
291
- ### Event: error(error)
509
+ #### Event: error(error)
292
510
  Emitted when the stream encounters an error.
293
511
 
294
- ### Event: end
512
+ #### Event: end
295
513
  Emitted when the stream has been stopped and all pending requests have been completed.
296
514
 
515
+ ### UsbDetection
297
516
 
298
- UsbDetection
299
- ------------
300
-
301
- ### usb.on('attach', function(device) { ... });
517
+ #### usb.on('attach', function(device) { ... });
302
518
  Attaches a callback to plugging in a `device`.
303
519
 
304
- ### usb.on('detach', function(device) { ... });
520
+ #### usb.on('detach', function(device) { ... });
305
521
  Attaches a callback to unplugging a `device`.
306
522
 
307
- ### usb.refHotplugEvents();
523
+ #### usb.refHotplugEvents();
308
524
  Restore (re-reference) the hotplug events unreferenced by `unrefHotplugEvents()`
309
525
 
310
- ### usb.unrefHotplugEvents();
526
+ #### usb.unrefHotplugEvents();
311
527
  Listening to events will prevent the process to exit. By calling this function, hotplug events will be unreferenced by the event loop, allowing the process to exit even when listening for the `attach` and `detach` events.
312
528
 
529
+ # Development
530
+ The library is based on native bindings wrapping the [libusb](https://github.com/libusb/libusb) library.
313
531
 
314
- Development and testing
315
- =======================
316
-
317
- To build from git:
532
+ ## Setup
533
+ Libusb is included as a submodule, clone this repository and then the submodule as follows:
318
534
 
319
- git clone --recursive https://github.com/node-usb/node-usb.git
320
- cd node-usb
321
- npm install
535
+ ```bash
536
+ git clone https://github.com/node-usb/node-usb
537
+ cd node-usb
538
+ git submodule update --init
539
+ ```
322
540
 
323
- To execute the unit tests, [CoffeeScript](http://coffeescript.org) is required. Run
541
+ ## Building
542
+ The package uses `yarn` for the typescript code and `prebuildify` to generate the native binaries. These can be executed as follows:
324
543
 
325
- npm test
544
+ ```bash
545
+ yarn
546
+ yarn prebuild
547
+ ```
326
548
 
327
- Some tests require an [attached STM32F103 Microprocessor USB device with specific firmware](https://github.com/thegecko/node-usb-test-firmware).
549
+ __Note:__ On Linux, you'll need libudev to build libusb. On Ubuntu/Debian:
328
550
 
329
- npm run --silent full-test
330
- npm run --silent valgrind
551
+ ```bash
552
+ sudo apt-get install build-essential libudev-dev
553
+ ```
331
554
 
332
- Limitations
333
- ===========
334
-
335
- Does not support:
555
+ ## Testing
556
+ To execute the unit tests, Run:
336
557
 
337
- - Configurations other than the default one
338
- - Isochronous transfers
558
+ ```bash
559
+ yarn test
560
+ ```
339
561
 
340
- License
341
- =======
562
+ Some tests require an [attached STM32F103 Microprocessor USB device with specific firmware](https://github.com/node-usb/node-usb-test-firmware).
342
563
 
343
- MIT
564
+ ```bash
565
+ yarn full-test
566
+ yarn valgrind
567
+ ```
344
568
 
345
- Note that the compiled Node extension includes Libusb, and is thus subject to the LGPL.
569
+ ## Releasing
570
+ Please refer to the [Wiki](https://github.com/node-usb/node-usb/wiki/Release-Process) for release instructions.