usb 2.0.0-alpha.2 → 2.1.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.
Files changed (258) hide show
  1. package/.gitmodules +1 -1
  2. package/CHANGELOG.md +100 -0
  3. package/README.md +573 -0
  4. package/binding.gyp +12 -2
  5. package/dist/index.d.ts +4 -4
  6. package/dist/index.js +14 -8
  7. package/dist/index.js.map +1 -1
  8. package/dist/usb/bindings.d.ts +13 -0
  9. package/dist/usb/bindings.js +2 -1
  10. package/dist/usb/bindings.js.map +1 -1
  11. package/dist/usb/index.js +86 -2
  12. package/dist/usb/index.js.map +1 -1
  13. package/dist/usb/interface.js.map +1 -1
  14. package/dist/webusb/index.d.ts +32 -19
  15. package/dist/webusb/index.js +163 -67
  16. package/dist/webusb/index.js.map +1 -1
  17. package/dist/webusb/webusb-device.d.ts +1 -1
  18. package/dist/webusb/webusb-device.js +27 -15
  19. package/dist/webusb/webusb-device.js.map +1 -1
  20. package/libusb/.private/pre-commit.sh +7 -1
  21. package/libusb/.travis.yml +49 -0
  22. package/libusb/AUTHORS +44 -3
  23. package/libusb/Brewfile +4 -0
  24. package/libusb/ChangeLog +74 -2
  25. package/libusb/README.md +32 -0
  26. package/libusb/TODO +1 -1
  27. package/libusb/Xcode/common.xcconfig +12 -0
  28. package/libusb/Xcode/config.h +25 -0
  29. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +959 -1
  30. package/libusb/android/README +4 -2
  31. package/libusb/android/config.h +75 -0
  32. package/libusb/appveyor.yml +41 -0
  33. package/libusb/appveyor_cygwin.bat +11 -0
  34. package/libusb/appveyor_minGW.bat +19 -0
  35. package/libusb/autogen.sh +1 -1
  36. package/libusb/bootstrap.sh +3 -16
  37. package/libusb/configure.ac +108 -80
  38. package/libusb/doc/doxygen.cfg.in +1785 -739
  39. package/libusb/examples/Makefile.am +1 -1
  40. package/libusb/examples/dpfp.c +3 -1
  41. package/libusb/examples/dpfp_threaded.c +23 -10
  42. package/libusb/examples/ezusb.c +3 -3
  43. package/libusb/examples/ezusb.h +2 -2
  44. package/libusb/examples/fxload.c +31 -9
  45. package/libusb/examples/hotplugtest.c +35 -7
  46. package/libusb/examples/listdevs.c +3 -1
  47. package/libusb/examples/sam3u_benchmark.c +3 -3
  48. package/libusb/examples/testlibusb.c +277 -0
  49. package/libusb/examples/xusb.c +40 -34
  50. package/libusb/libusb/Makefile.am +49 -23
  51. package/libusb/libusb/core.c +855 -457
  52. package/libusb/libusb/descriptor.c +72 -78
  53. package/libusb/libusb/hotplug.c +122 -76
  54. package/libusb/libusb/hotplug.h +42 -25
  55. package/libusb/libusb/io.c +625 -390
  56. package/libusb/libusb/libusb-1.0.def +12 -0
  57. package/libusb/libusb/libusb.h +218 -150
  58. package/libusb/libusb/libusbi.h +346 -176
  59. package/libusb/libusb/os/darwin_usb.c +604 -319
  60. package/libusb/libusb/os/darwin_usb.h +61 -20
  61. package/libusb/libusb/os/haiku_pollfs.cpp +367 -0
  62. package/libusb/libusb/os/haiku_usb.h +113 -0
  63. package/libusb/libusb/os/haiku_usb_backend.cpp +533 -0
  64. package/libusb/libusb/os/haiku_usb_raw.cpp +267 -0
  65. package/libusb/libusb/os/haiku_usb_raw.h +188 -0
  66. package/libusb/libusb/os/linux_netlink.c +186 -146
  67. package/libusb/libusb/os/linux_udev.c +36 -14
  68. package/libusb/libusb/os/linux_usbfs.c +426 -225
  69. package/libusb/libusb/os/linux_usbfs.h +5 -3
  70. package/libusb/libusb/os/netbsd_usb.c +21 -77
  71. package/libusb/libusb/os/openbsd_usb.c +32 -115
  72. package/libusb/libusb/os/poll_posix.c +38 -5
  73. package/libusb/libusb/os/poll_posix.h +3 -0
  74. package/libusb/libusb/os/poll_windows.c +277 -626
  75. package/libusb/libusb/os/poll_windows.h +11 -44
  76. package/libusb/libusb/os/sunos_usb.c +1695 -0
  77. package/libusb/libusb/os/sunos_usb.h +80 -0
  78. package/libusb/libusb/os/threads_posix.c +24 -26
  79. package/libusb/libusb/os/threads_posix.h +73 -21
  80. package/libusb/libusb/os/threads_windows.c +71 -157
  81. package/libusb/libusb/os/threads_windows.h +68 -44
  82. package/libusb/libusb/os/wince_usb.c +276 -420
  83. package/libusb/libusb/os/wince_usb.h +23 -28
  84. package/libusb/libusb/os/windows_common.h +78 -58
  85. package/libusb/libusb/os/windows_nt_common.c +1010 -0
  86. package/libusb/libusb/os/windows_nt_common.h +110 -0
  87. package/libusb/libusb/os/windows_nt_shared_types.h +147 -0
  88. package/libusb/libusb/os/windows_usbdk.c +830 -0
  89. package/libusb/libusb/os/windows_usbdk.h +103 -0
  90. package/libusb/libusb/os/windows_winusb.c +4391 -0
  91. package/libusb/libusb/os/windows_winusb.h +783 -0
  92. package/libusb/libusb/strerror.c +41 -7
  93. package/libusb/libusb/sync.c +41 -13
  94. package/libusb/libusb/version.h +1 -1
  95. package/libusb/libusb/version_nano.h +1 -1
  96. package/libusb/libusb-1.0.pc.in +1 -1
  97. package/libusb/msvc/appveyor.bat +27 -0
  98. package/libusb/msvc/config.h +5 -4
  99. package/libusb/msvc/ddk_build.cmd +87 -43
  100. package/libusb/msvc/fxload_2010.vcxproj +24 -104
  101. package/libusb/msvc/fxload_2012.vcxproj +24 -107
  102. package/libusb/msvc/fxload_2013.vcxproj +24 -107
  103. package/libusb/msvc/fxload_2015.vcxproj +91 -0
  104. package/libusb/msvc/fxload_2017.vcxproj +114 -0
  105. package/libusb/msvc/fxload_sources +1 -1
  106. package/libusb/msvc/getopt_2010.vcxproj +16 -75
  107. package/libusb/msvc/getopt_2012.vcxproj +16 -79
  108. package/libusb/msvc/getopt_2013.vcxproj +16 -79
  109. package/libusb/msvc/getopt_2015.vcxproj +73 -0
  110. package/libusb/msvc/getopt_2017.vcxproj +98 -0
  111. package/libusb/msvc/getopt_sources +6 -2
  112. package/libusb/msvc/hotplugtest_2010.vcxproj +18 -99
  113. package/libusb/msvc/hotplugtest_2012.vcxproj +18 -102
  114. package/libusb/msvc/hotplugtest_2013.vcxproj +18 -102
  115. package/libusb/msvc/hotplugtest_2015.vcxproj +83 -0
  116. package/libusb/msvc/hotplugtest_2017.vcxproj +106 -0
  117. package/libusb/msvc/hotplugtest_sources +1 -1
  118. package/libusb/msvc/libusb_2005.sln +20 -20
  119. package/libusb/msvc/libusb_2010.sln +57 -46
  120. package/libusb/msvc/libusb_2012.sln +57 -46
  121. package/libusb/msvc/libusb_2013.sln +57 -50
  122. package/libusb/msvc/libusb_2015.sln +59 -52
  123. package/libusb/msvc/libusb_2017.sln +186 -0
  124. package/libusb/msvc/libusb_dll.dsp +2 -2
  125. package/libusb/msvc/libusb_dll_2005.vcproj +30 -2
  126. package/libusb/msvc/libusb_dll_2010.vcxproj +26 -90
  127. package/libusb/msvc/libusb_dll_2012.vcxproj +28 -96
  128. package/libusb/msvc/libusb_dll_2013.vcxproj +28 -96
  129. package/libusb/msvc/libusb_dll_2015.vcxproj +107 -0
  130. package/libusb/msvc/libusb_dll_2017.vcxproj +134 -0
  131. package/libusb/msvc/libusb_dll_wince.vcproj +9 -1
  132. package/libusb/msvc/libusb_sources +10 -5
  133. package/libusb/msvc/libusb_static.dsp +2 -2
  134. package/libusb/msvc/libusb_static_2005.vcproj +32 -4
  135. package/libusb/msvc/libusb_static_2010.vcxproj +24 -83
  136. package/libusb/msvc/libusb_static_2012.vcxproj +25 -87
  137. package/libusb/msvc/libusb_static_2013.vcxproj +25 -87
  138. package/libusb/msvc/libusb_static_2015.vcxproj +98 -0
  139. package/libusb/msvc/libusb_static_2017.vcxproj +117 -0
  140. package/libusb/msvc/libusb_static_wince.vcproj +20 -26
  141. package/libusb/msvc/libusb_wince.sln +88 -88
  142. package/libusb/msvc/listdevs_2010.vcxproj +16 -99
  143. package/libusb/msvc/listdevs_2012.vcxproj +16 -102
  144. package/libusb/msvc/listdevs_2013.vcxproj +16 -102
  145. package/libusb/msvc/listdevs_2015.vcxproj +83 -0
  146. package/libusb/msvc/listdevs_2017.vcxproj +106 -0
  147. package/libusb/msvc/listdevs_sources +2 -1
  148. package/libusb/msvc/stress_2010.vcxproj +20 -101
  149. package/libusb/msvc/stress_2012.vcxproj +20 -104
  150. package/libusb/msvc/stress_2013.vcxproj +20 -104
  151. package/libusb/msvc/stress_2015.vcxproj +87 -0
  152. package/libusb/msvc/stress_2017.vcxproj +110 -0
  153. package/libusb/msvc/stress_sources +21 -0
  154. package/libusb/msvc/testlibusb_2010.vcxproj +82 -0
  155. package/libusb/msvc/testlibusb_2012.vcxproj +83 -0
  156. package/libusb/msvc/testlibusb_2013.vcxproj +83 -0
  157. package/libusb/msvc/testlibusb_2015.vcxproj +83 -0
  158. package/libusb/msvc/testlibusb_2017.vcxproj +106 -0
  159. package/libusb/msvc/testlibusb_sources +20 -0
  160. package/libusb/msvc/xusb_2010.vcxproj +17 -98
  161. package/libusb/msvc/xusb_2012.vcxproj +17 -101
  162. package/libusb/msvc/xusb_2013.vcxproj +17 -101
  163. package/libusb/msvc/xusb_2015.vcxproj +83 -0
  164. package/libusb/msvc/xusb_2017.vcxproj +106 -0
  165. package/libusb/msvc/xusb_sources +1 -1
  166. package/libusb/tests/stress.c +2 -2
  167. package/libusb/tests/testlib.c +0 -4
  168. package/libusb/travis-autogen.sh +39 -0
  169. package/libusb.gypi +21 -2
  170. package/package.json +18 -13
  171. package/prebuilds/android-arm/node.napi.node +0 -0
  172. package/prebuilds/android-arm64/node.napi.node +0 -0
  173. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  174. package/prebuilds/linux-arm/node.napi.node +0 -0
  175. package/prebuilds/linux-arm64/node.napi.node +0 -0
  176. package/prebuilds/linux-ia32/node.napi.node +0 -0
  177. package/prebuilds/linux-x64/node.napi.node +0 -0
  178. package/prebuilds/win32-ia32/node.napi.node +0 -0
  179. package/prebuilds/win32-x64/node.napi.node +0 -0
  180. package/src/device.cc +7 -7
  181. package/src/node_usb.cc +43 -1
  182. package/src/node_usb.h +1 -0
  183. package/src/uv_async_queue.h +33 -25
  184. package/test/usb.coffee +6 -0
  185. package/tsc/index.ts +13 -7
  186. package/tsc/usb/bindings.ts +19 -1
  187. package/tsc/usb/index.ts +67 -19
  188. package/tsc/usb/interface.ts +2 -2
  189. package/tsc/webusb/index.ts +197 -74
  190. package/tsc/webusb/webusb-device.ts +30 -17
  191. package/.github/workflows/prebuild.yml +0 -48
  192. package/Readme.md +0 -339
  193. package/dist/webusb/typed-event-target.d.ts +0 -11
  194. package/dist/webusb/typed-event-target.js +0 -21
  195. package/dist/webusb/typed-event-target.js.map +0 -1
  196. package/docs/assets/css/main.css +0 -2660
  197. package/docs/assets/images/icons.png +0 -0
  198. package/docs/assets/images/icons@2x.png +0 -0
  199. package/docs/assets/images/widgets.png +0 -0
  200. package/docs/assets/images/widgets@2x.png +0 -0
  201. package/docs/assets/js/main.js +0 -248
  202. package/docs/assets/js/search.js +0 -1
  203. package/docs/classes/usb_bindings.device.html +0 -1338
  204. package/docs/classes/usb_bindings.libusbexception.html +0 -234
  205. package/docs/classes/usb_bindings.transfer.html +0 -344
  206. package/docs/classes/usb_capability.capability.html +0 -297
  207. package/docs/classes/usb_device.extendeddevice.html +0 -766
  208. package/docs/classes/usb_endpoint.endpoint.html +0 -472
  209. package/docs/classes/usb_endpoint.inendpoint.html +0 -766
  210. package/docs/classes/usb_endpoint.outendpoint.html +0 -582
  211. package/docs/classes/usb_interface.interface.html +0 -648
  212. package/docs/classes/webusb.webusb-1.html +0 -615
  213. package/docs/classes/webusb_mutex.mutex.html +0 -270
  214. package/docs/classes/webusb_typed_event_target.typedeventtarget.html +0 -443
  215. package/docs/classes/webusb_webusb_device.webusbdevice.html +0 -904
  216. package/docs/index.html +0 -500
  217. package/docs/interfaces/usb.deviceevents.html +0 -242
  218. package/docs/interfaces/usb_descriptors.bosdescriptor.html +0 -293
  219. package/docs/interfaces/usb_descriptors.capabilitydescriptor.html +0 -274
  220. package/docs/interfaces/usb_descriptors.configdescriptor.html +0 -388
  221. package/docs/interfaces/usb_descriptors.devicedescriptor.html +0 -464
  222. package/docs/interfaces/usb_descriptors.endpointdescriptor.html +0 -370
  223. package/docs/interfaces/usb_descriptors.interfacedescriptor.html +0 -407
  224. package/docs/interfaces/webusb.usboptions.html +0 -226
  225. package/docs/modules/index.html +0 -304
  226. package/docs/modules/usb.html +0 -173
  227. package/docs/modules/usb_bindings.html +0 -2248
  228. package/docs/modules/usb_capability.html +0 -156
  229. package/docs/modules/usb_descriptors.html +0 -176
  230. package/docs/modules/usb_device.html +0 -156
  231. package/docs/modules/usb_endpoint.html +0 -164
  232. package/docs/modules/usb_interface.html +0 -156
  233. package/docs/modules/webusb.html +0 -165
  234. package/docs/modules/webusb_mutex.html +0 -156
  235. package/docs/modules/webusb_typed_event_target.html +0 -156
  236. package/docs/modules/webusb_webusb_device.html +0 -156
  237. package/docs/modules.html +0 -156
  238. package/libusb/INSTALL +0 -234
  239. package/libusb/README +0 -28
  240. package/libusb/libusb/os/windows_usb.c +0 -5347
  241. package/libusb/libusb/os/windows_usb.h +0 -971
  242. package/libusb/msvc/fxload_2010.vcxproj.filters +0 -25
  243. package/libusb/msvc/fxload_2012.vcxproj.filters +0 -25
  244. package/libusb/msvc/getopt_2010.vcxproj.filters +0 -26
  245. package/libusb/msvc/getopt_2012.vcxproj.filters +0 -26
  246. package/libusb/msvc/hotplugtest_2010.vcxproj.filters +0 -14
  247. package/libusb/msvc/hotplugtest_2012.vcxproj.filters +0 -14
  248. package/libusb/msvc/libusb_dll_2010.vcxproj.filters +0 -81
  249. package/libusb/msvc/libusb_dll_2012.vcxproj.filters +0 -84
  250. package/libusb/msvc/libusb_static_2010.vcxproj.filters +0 -74
  251. package/libusb/msvc/libusb_static_2012.vcxproj.filters +0 -74
  252. package/libusb/msvc/listdevs_2010.vcxproj.filters +0 -14
  253. package/libusb/msvc/listdevs_2012.vcxproj.filters +0 -14
  254. package/libusb/msvc/stress_2010.vcxproj.filters +0 -25
  255. package/libusb/msvc/stress_2012.vcxproj.filters +0 -25
  256. package/libusb/msvc/xusb_2010.vcxproj.filters +0 -14
  257. package/libusb/msvc/xusb_2012.vcxproj.filters +0 -14
  258. package/tsc/webusb/typed-event-target.ts +0 -23
package/.gitmodules CHANGED
@@ -1,3 +1,3 @@
1
1
  [submodule "libusb"]
2
2
  path = libusb
3
- url = https://github.com/kevinmehall/libusb.git
3
+ url = https://github.com/libusb/libusb.git
package/CHANGELOG.md ADDED
@@ -0,0 +1,100 @@
1
+ # Changelog
2
+
3
+ ## [2.1.0] - 2022-01-29
4
+
5
+ ### Added
6
+ - Added `getWebUsb()` convenience method - [`467`](https://github.com/node-usb/node-usb/pull/467) ([Rob Moran](https://github.com/thegecko))
7
+ - Added initialize() error - [`470`](https://github.com/node-usb/node-usb/pull/470) ([Gerrit Niezen](https://github.com/gniezen))
8
+
9
+ ### Fixed
10
+ - Fixed lack of universal binary for MacOS darwin arm64 - [`473`](https://github.com/node-usb/node-usb/pull/473) ([Rob Moran](https://github.com/thegecko))
11
+
12
+ ## [2.0.3] - 2021-12-13
13
+
14
+ ### Added
15
+ - Added definition for `NAPI_VERSION 4` and added N-API v4 target to prebuildify - ([Rob Moran](https://github.com/thegecko))
16
+
17
+ ## [2.0.2] - 2021-12-12
18
+
19
+ ### Fixed
20
+ - Fixed error with trying to close WebUSB devices after they had failed to open - ([Rob Moran](https://github.com/thegecko))
21
+
22
+ ## [2.0.1] - 2021-12-11
23
+
24
+ ### Added
25
+ - Added new WebUSB API - [`443`](https://github.com/node-usb/node-usb/pull/443) ([Rob Moran](https://github.com/thegecko))
26
+ - Switched to TypeScript
27
+ - Switched to yarn instead of npm
28
+ - Added docs using Typedoc
29
+
30
+ ## [1.9.2] - 2021-12-05
31
+
32
+ ### Fixed
33
+ - Fixed exit delay and hang by moving queue start/stop to device open/close - [`460`](https://github.com/node-usb/node-usb/pull/460) ([MikeColeGuru](https://github.com/MikeColeGuru))
34
+
35
+ ## [1.9.1] - 2021-11-14
36
+
37
+ ### Fixed
38
+ - Reverted fix for exit delay fixing a segfault issue it introduced - [`456`](https://github.com/node-usb/node-usb/pull/456) ([Rob Moran](https://github.com/thegecko))
39
+
40
+ ## [1.9.0] - 2021-11-08
41
+
42
+ ### Changed
43
+ - Changed libusb dependency to upstream v1.0.23 - [`453`](https://github.com/node-usb/node-usb/pull/453) ([Rob Moran](https://github.com/thegecko))
44
+
45
+ ## [1.8.1] - 2021-11-08
46
+
47
+ ### Added
48
+ - Added functionality to ref/unref the hotplug events - [`455`](https://github.com/node-usb/node-usb/pull/455) ([Guilherme Francescon](https://github.com/gfcittolin))
49
+ - Added CHANGELOG - [`454`](https://github.com/node-usb/node-usb/pull/454) ([Rob Moran](https://github.com/thegecko))
50
+
51
+ ### Fixed
52
+ - Fixed delay when exiting program - [`455`](https://github.com/node-usb/node-usb/pull/455) ([Rob Moran](https://github.com/thegecko))
53
+
54
+ ## [1.8.0] - 2021-10-14
55
+
56
+ ### Added
57
+ - Added prebuildify and GitHub action for native binaries - [`450`](https://github.com/node-usb/node-usb/pull/450) ([Rob Moran](https://github.com/thegecko))
58
+
59
+ ### Fixed
60
+ - Fixed crash after wake on Windows when using Electron - [`451`](https://github.com/node-usb/node-usb/pull/451) ([Rob Moran](https://github.com/thegecko))
61
+ - Fixed invalid initial refs - [`445`](https://github.com/node-usb/node-usb/pull/445) ([Alba Mendez](https://github.com/mildsunrise))
62
+
63
+ ### Changed
64
+ - Changed GitHub organisation to [node-usb](https://github.com/node-usb) - [`447`](https://github.com/node-usb/node-usb/pull/447) ([Rob Moran](https://github.com/thegecko))
65
+
66
+ ## [1.7.2] - 2021-08-30
67
+
68
+ ### Fixed
69
+ - Fixed crash when exiting on MacOS with Electron 9 - [`440`](https://github.com/node-usb/node-usb/pull/440) ([Daniel Main](https://github.com/danielmain))
70
+
71
+ ### Changed
72
+ - **Breaking:** Changed minimum Node.js version to `10` - [`428`](https://github.com/node-usb/node-usb/pull/428) ([Rob Moran](https://github.com/thegecko))
73
+
74
+ ## [1.7.1] - 2021-05-08
75
+
76
+ ### Fixed
77
+ - Fixed compiler warnings - [`419`](https://github.com/node-usb/node-usb/pull/419) ([Joel Purra](https://github.com/joelpurra))
78
+
79
+ ## [1.7.0] - 2021-04-10
80
+
81
+ ### Changed
82
+ - Changed native support to use Node Addon API - [`399`](https://github.com/node-usb/node-usb/pull/399) ([Georg Vienna](https://github.com/geovie))
83
+
84
+ ## [1.6.5] - 2021-02-14
85
+
86
+ ### Changed
87
+ - Changed prebuild for Electron 12 beta to nightly - [`410`](https://github.com/node-usb/node-usb/pull/410) ([Piotr Rogowski](https://github.com/karniv00l))
88
+
89
+ ### Removed
90
+ - Removed `portNumbers` test on arm64 - [`408`](https://github.com/node-usb/node-usb/pull/408) ([Rob Moran](https://github.com/thegecko))
91
+
92
+ ## [1.6.4] - 2021-01-30
93
+
94
+ ### Added
95
+ - Added prebuild for Electron 10 and 12 beta - [`407`](https://github.com/node-usb/node-usb/pull/407) ([Rob Moran](https://github.com/thegecko))
96
+ - Added prebuild for Electron 9 - [`362`](https://github.com/node-usb/node-usb/pull/362) (Luke Whyte)
97
+
98
+ ### Changed
99
+ - Changed to GitHub Actions for prebuild workflow - [`404`](https://github.com/node-usb/node-usb/pull/404) ([Rob Moran](https://github.com/thegecko))
100
+ - Changed Node.js 13 prebuild target to Node.js 14 - [`374`](https://github.com/node-usb/node-usb/pull/374) ([Micah Zoltu](https://github.com/MicahZoltu))
package/README.md ADDED
@@ -0,0 +1,573 @@
1
+ # USB Library for Node.JS
2
+
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)
6
+
7
+ Node.JS library for communicating with USB devices.
8
+
9
+ This is a refactoring / rewrite of Christopher Klein's [node-usb](https://github.com/schakko/node-usb).
10
+
11
+ # Prerequisites
12
+
13
+ [Node.js >= v10.16.0](https://nodejs.org), which includes `npm`.
14
+
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
+
17
+ # Installation
18
+
19
+ Native modules are bundled using `prebuildify`, so installation should be as simple as installing the package.
20
+
21
+ With `npm`:
22
+
23
+ ```bash
24
+ npm install usb
25
+ ```
26
+
27
+ With `yarn`:
28
+
29
+ ```bash
30
+ yarn add usb
31
+ ```
32
+
33
+ __Note:__ the library is now written in `TypeScript`, so a separate types file is not longer required to be installed.
34
+
35
+ # License
36
+ [MIT](LICENSE.md)
37
+
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).
39
+
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
+ ### getWebUsb()
214
+ Return the `navigator.usb` instance if it exists, otherwise a `webusb` instance.
215
+
216
+ ### WebUSBDevice
217
+ WebUSB Device class for wrapping a legacy Device into a WebUSB device
218
+
219
+ #### WebUSBDevice.createInstance(device)
220
+ Convenience method to return a promise of a WebUSB device based on a legacy device
221
+
222
+ ## WebUSB
223
+
224
+ Please refer to the WebUSB specification which be found here:
225
+
226
+ https://wicg.github.io/webusb/
227
+
228
+ ### Implementation Status
229
+
230
+ #### USB
231
+
232
+ - [x] getDevices()
233
+ - [x] requestDevice()
234
+
235
+ #### USBDevice
236
+
237
+ - [x] usbVersionMajor
238
+ - [x] usbVersionMinor
239
+ - [x] usbVersionSubminor
240
+ - [x] deviceClass
241
+ - [x] deviceSubclass
242
+ - [x] deviceProtocol
243
+ - [x] vendorId
244
+ - [x] productId
245
+ - [x] deviceVersionMajor
246
+ - [x] deviceVersionMinor
247
+ - [x] deviceVersionSubminor
248
+ - [x] manufacturerName
249
+ - [x] productName
250
+ - [x] serialNumber
251
+ - [x] configuration
252
+ - [x] configurations
253
+ - [x] opened
254
+ - [x] open()
255
+ - [x] close()
256
+ - [x] selectConfiguration()
257
+ - [x] claimInterface()
258
+ - [x] releaseInterface()
259
+ - [x] selectAlternateInterface()
260
+ - [x] controlTransferIn()
261
+ - [x] controlTransferOut() - `bytesWritten` always equals the initial buffer length
262
+ - [x] transferIn()
263
+ - [x] transferOut() - `bytesWritten` always equals the initial buffer length
264
+ - [x] clearHalt()
265
+ - [x] reset()
266
+ - [ ] isochronousTransferIn()
267
+ - [ ] isochronousTransferOut()
268
+
269
+ #### Events
270
+
271
+ - [x] connect
272
+ - [x] disconnect
273
+
274
+ ## Legacy API
275
+
276
+ ### usb
277
+ Legacy usb object.
278
+
279
+ #### usb.LIBUSB_*
280
+ Constant properties from libusb
281
+
282
+ #### usb.setDebugLevel(level : int)
283
+ Set the libusb debug level (between 0 and 4)
284
+
285
+ ### Device
286
+ Represents a USB device.
287
+
288
+ #### .busNumber
289
+ Integer USB device number
290
+
291
+ #### .deviceAddress
292
+ Integer USB device address
293
+
294
+ #### .portNumbers
295
+ Array containing the USB device port numbers, or `undefined` if not supported on this platform.
296
+
297
+ #### .deviceDescriptor
298
+ Object with properties for the fields of the device descriptor:
299
+
300
+ - bLength
301
+ - bDescriptorType
302
+ - bcdUSB
303
+ - bDeviceClass
304
+ - bDeviceSubClass
305
+ - bDeviceProtocol
306
+ - bMaxPacketSize0
307
+ - idVendor
308
+ - idProduct
309
+ - bcdDevice
310
+ - iManufacturer
311
+ - iProduct
312
+ - iSerialNumber
313
+ - bNumConfigurations
314
+
315
+ #### .configDescriptor
316
+ Object with properties for the fields of the configuration descriptor:
317
+
318
+ - bLength
319
+ - bDescriptorType
320
+ - wTotalLength
321
+ - bNumInterfaces
322
+ - bConfigurationValue
323
+ - iConfiguration
324
+ - bmAttributes
325
+ - bMaxPower
326
+ - extra (Buffer containing any extra data or additional descriptors)
327
+
328
+ #### .allConfigDescriptors
329
+ Contains all config descriptors of the device (same structure as .configDescriptor above)
330
+
331
+ #### .parent
332
+ Contains the parent of the device, such as a hub. If there is no parent this property is set to `null`.
333
+
334
+ #### .open()
335
+ Open the device. All methods below require the device to be open before use.
336
+
337
+ #### .close()
338
+ Close the device.
339
+
340
+ #### .controlTransfer(bmRequestType, bRequest, wValue, wIndex, data_or_length, callback(error, data))
341
+ Perform a control transfer with `libusb_control_transfer`.
342
+
343
+ 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.
344
+
345
+ The `data` parameter of the callback is always undefined for OUT transfers, or will be passed a Buffer for IN transfers.
346
+
347
+ A [package is available to calculate bmRequestType](https://www.npmjs.com/package/bmrequesttype) if needed.
348
+
349
+ #### .setConfiguration(id, callback(error))
350
+ 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.
351
+
352
+ #### .getStringDescriptor(index, callback(error, data))
353
+ Perform a control transfer to retrieve a string descriptor
354
+
355
+ #### .getBosDescriptor(callback(error, bosDescriptor))
356
+ Perform a control transfer to retrieve an object with properties for the fields of the Binary Object Store descriptor:
357
+
358
+ - bLength
359
+ - bDescriptorType
360
+ - wTotalLength
361
+ - bNumDeviceCaps
362
+
363
+ #### .getCapabilities(callback(error, capabilities))
364
+ Retrieve a list of Capability objects for the Binary Object Store capabilities of the device.
365
+
366
+ #### .interface(interface)
367
+ Return the interface with the specified interface number.
368
+
369
+ #### .interfaces
370
+ List of Interface objects for the interfaces of the default configuration of the device.
371
+
372
+ #### .timeout
373
+ Timeout in milliseconds to use for control transfers.
374
+
375
+ #### .reset(callback(error))
376
+ Performs a reset of the device. Callback is called when complete.
377
+
378
+ ### Interface
379
+
380
+ #### .endpoint(address)
381
+ Return the InEndpoint or OutEndpoint with the specified address.
382
+
383
+ #### .endpoints
384
+ List of endpoints on this interface: InEndpoint and OutEndpoint objects.
385
+
386
+ #### .interface
387
+ Integer interface number.
388
+
389
+ #### .altSetting
390
+ Integer alternate setting number.
391
+
392
+ #### .setAltSetting(altSetting, callback(error))
393
+ Sets the alternate setting. It updates the `interface.endpoints` array to reflect the endpoints found in the alternate setting.
394
+
395
+ #### .claim()
396
+ Claims the interface. This method must be called before using any endpoints of this interface.
397
+
398
+ #### .release([closeEndpoints], callback(error))
399
+ Releases the interface and resets the alternate setting. Calls callback when complete.
400
+
401
+ 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.
402
+
403
+ #### .isKernelDriverActive()
404
+ Returns `false` if a kernel driver is not active; `true` if active.
405
+
406
+ #### .detachKernelDriver()
407
+ Detaches the kernel driver from the interface.
408
+
409
+ #### .attachKernelDriver()
410
+ Re-attaches the kernel driver for the interface.
411
+
412
+ #### .descriptor
413
+ Object with fields from the interface descriptor -- see libusb documentation or USB spec.
414
+
415
+ - bLength
416
+ - bDescriptorType
417
+ - bInterfaceNumber
418
+ - bAlternateSetting
419
+ - bNumEndpoints
420
+ - bInterfaceClass
421
+ - bInterfaceSubClass
422
+ - bInterfaceProtocol
423
+ - iInterface
424
+ - extra (Buffer containing any extra data or additional descriptors)
425
+
426
+ ### Capability
427
+
428
+ #### .type
429
+ Integer capability type.
430
+
431
+ #### .data
432
+ Buffer capability data.
433
+
434
+ #### .descriptor
435
+ Object with fields from the capability descriptor -- see libusb documentation or USB spec.
436
+
437
+ - bLength
438
+ - bDescriptorType
439
+ - bDevCapabilityType
440
+
441
+ ### Endpoint
442
+ Common base for InEndpoint and OutEndpoint, see below.
443
+
444
+ #### .direction
445
+ Endpoint direction: `"in"` or `"out"`.
446
+
447
+ #### .transferType
448
+ Endpoint type: `usb.LIBUSB_TRANSFER_TYPE_BULK`, `usb.LIBUSB_TRANSFER_TYPE_INTERRUPT`, or `usb.LIBUSB_TRANSFER_TYPE_ISOCHRONOUS`.
449
+
450
+ #### .descriptor
451
+ Object with fields from the endpoint descriptor -- see libusb documentation or USB spec.
452
+
453
+ - bLength
454
+ - bDescriptorType
455
+ - bEndpointAddress
456
+ - bmAttributes
457
+ - wMaxPacketSize
458
+ - bInterval
459
+ - bRefresh
460
+ - bSynchAddress
461
+ - extra (Buffer containing any extra data or additional descriptors)
462
+
463
+ #### .timeout
464
+ Sets the timeout in milliseconds for transfers on this endpoint. The default, `0`, is infinite timeout.
465
+
466
+ #### .clearHalt(callback(error))
467
+ Clear the halt/stall condition for this endpoint.
468
+
469
+ ### InEndpoint
470
+ Endpoints in the IN direction (device->PC) have this type.
471
+
472
+ #### .transfer(length, callback(error, data))
473
+ Perform a transfer to read data from the endpoint.
474
+
475
+ 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.
476
+
477
+ `this` in the callback is the InEndpoint object.
478
+
479
+ #### .startPoll(nTransfers=3, transferSize=maxPacketSize)
480
+ Start polling the endpoint.
481
+
482
+ The library will keep `nTransfers` transfers of size `transferSize` pending in
483
+ the kernel at all times to ensure continuous data flow. This is handled by the
484
+ libusb event thread, so it continues even if the Node v8 thread is busy. The
485
+ `data` and `error` events are emitted as transfers complete.
486
+
487
+ #### .stopPoll(cb)
488
+ Stop polling.
489
+
490
+ Further data may still be received. The `end` event is emitted and the callback
491
+ is called once all transfers have completed or canceled.
492
+
493
+ #### Event: data(data : Buffer)
494
+ Emitted with data received by the polling transfers
495
+
496
+ #### Event: error(error)
497
+ 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.
498
+
499
+ #### Event: end
500
+ Emitted when polling has been canceled
501
+
502
+ ### OutEndpoint
503
+ Endpoints in the OUT direction (PC->device) have this type.
504
+
505
+ #### .transfer(data, callback(error))
506
+ Perform a transfer to write `data` to the endpoint.
507
+
508
+ 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.
509
+
510
+ `this` in the callback is the OutEndpoint object.
511
+
512
+ #### Event: error(error)
513
+ Emitted when the stream encounters an error.
514
+
515
+ #### Event: end
516
+ Emitted when the stream has been stopped and all pending requests have been completed.
517
+
518
+ ### UsbDetection
519
+
520
+ #### usb.on('attach', function(device) { ... });
521
+ Attaches a callback to plugging in a `device`.
522
+
523
+ #### usb.on('detach', function(device) { ... });
524
+ Attaches a callback to unplugging a `device`.
525
+
526
+ #### usb.refHotplugEvents();
527
+ Restore (re-reference) the hotplug events unreferenced by `unrefHotplugEvents()`
528
+
529
+ #### usb.unrefHotplugEvents();
530
+ 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.
531
+
532
+ # Development
533
+ The library is based on native bindings wrapping the [libusb](https://github.com/libusb/libusb) library.
534
+
535
+ ## Setup
536
+ Libusb is included as a submodule, clone this repository and then the submodule as follows:
537
+
538
+ ```bash
539
+ git clone https://github.com/node-usb/node-usb
540
+ cd node-usb
541
+ git submodule update --init
542
+ ```
543
+
544
+ ## Building
545
+ The package uses `yarn` for the typescript code and `prebuildify` to generate the native binaries. These can be executed as follows:
546
+
547
+ ```bash
548
+ yarn
549
+ yarn prebuild
550
+ ```
551
+
552
+ __Note:__ On Linux, you'll need libudev to build libusb. On Ubuntu/Debian:
553
+
554
+ ```bash
555
+ sudo apt-get install build-essential libudev-dev
556
+ ```
557
+
558
+ ## Testing
559
+ To execute the unit tests, Run:
560
+
561
+ ```bash
562
+ yarn test
563
+ ```
564
+
565
+ Some tests require an [attached STM32F103 Microprocessor USB device with specific firmware](https://github.com/node-usb/node-usb-test-firmware).
566
+
567
+ ```bash
568
+ yarn full-test
569
+ yarn valgrind
570
+ ```
571
+
572
+ ## Releasing
573
+ Please refer to the [Wiki](https://github.com/node-usb/node-usb/wiki/Release-Process) for release instructions.
package/binding.gyp CHANGED
@@ -49,8 +49,18 @@
49
49
  }],
50
50
  ['OS=="mac"', {
51
51
  'xcode_settings': {
52
- 'OTHER_CFLAGS': [ '-std=c++1y', '-stdlib=libc++' ],
53
- 'OTHER_LDFLAGS': [ '-framework', 'CoreFoundation', '-framework', 'IOKit' ],
52
+ 'OTHER_CFLAGS': [
53
+ '-std=c++1y',
54
+ '-stdlib=libc++',
55
+ '-arch x86_64',
56
+ '-arch arm64'
57
+ ],
58
+ 'OTHER_LDFLAGS': [
59
+ '-framework', 'CoreFoundation',
60
+ '-framework', 'IOKit',
61
+ '-arch x86_64',
62
+ '-arch arm64'
63
+ ],
54
64
  'SDKROOT': 'macosx',
55
65
  'MACOSX_DEPLOYMENT_TARGET': '10.7',
56
66
  },