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.
- package/.eslintignore +4 -0
- package/.eslintrc.json +87 -0
- package/.gitattributes +1 -0
- package/.vscode/launch.json +15 -0
- package/.vscode/tasks.json +23 -0
- package/CHANGELOG.md +13 -0
- package/README.md +400 -175
- package/dist/index.d.ts +17 -0
- package/dist/index.js +133 -0
- package/dist/index.js.map +1 -0
- package/dist/usb/bindings.d.ts +253 -0
- package/dist/usb/bindings.js +10 -0
- package/dist/usb/bindings.js.map +1 -0
- package/dist/usb/capability.d.ts +14 -0
- package/dist/usb/capability.js +18 -0
- package/dist/usb/capability.js.map +1 -0
- package/dist/usb/descriptors.d.ts +129 -0
- package/dist/usb/descriptors.js +3 -0
- package/dist/usb/descriptors.js.map +1 -0
- package/dist/usb/device.d.ts +94 -0
- package/dist/usb/device.js +300 -0
- package/dist/usb/device.js.map +1 -0
- package/dist/usb/endpoint.d.ts +91 -0
- package/dist/usb/endpoint.js +236 -0
- package/dist/usb/endpoint.js.map +1 -0
- package/dist/usb/index.d.ts +25 -0
- package/dist/usb/index.js +116 -0
- package/dist/usb/index.js.map +1 -0
- package/dist/usb/interface.d.ts +78 -0
- package/dist/usb/interface.js +137 -0
- package/dist/usb/interface.js.map +1 -0
- package/dist/webusb/index.d.ts +56 -0
- package/dist/webusb/index.js +412 -0
- package/dist/webusb/index.js.map +1 -0
- package/dist/webusb/mutex.d.ts +22 -0
- package/dist/webusb/mutex.js +89 -0
- package/dist/webusb/mutex.js.map +1 -0
- package/dist/webusb/webusb-device.d.ts +49 -0
- package/dist/webusb/webusb-device.js +888 -0
- package/dist/webusb/webusb-device.js.map +1 -0
- package/package.json +28 -15
- package/prebuilds/android-arm/node.napi.armv7.node +0 -0
- package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
- package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/linux-ia32/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
- package/prebuilds/linux-x64/node.napi.musl.node +0 -0
- package/prebuilds/win32-ia32/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/device.cc +6 -6
- package/test/usb.coffee +13 -7
- package/test/webusb.coffee +189 -0
- package/tsc/index.ts +67 -0
- package/tsc/usb/bindings.ts +304 -0
- package/tsc/usb/capability.ts +22 -0
- package/tsc/usb/descriptors.ts +180 -0
- package/tsc/usb/device.ts +325 -0
- package/tsc/usb/endpoint.ts +228 -0
- package/tsc/usb/index.ts +111 -0
- package/tsc/usb/interface.ts +172 -0
- package/tsc/webusb/index.ts +363 -0
- package/tsc/webusb/mutex.ts +38 -0
- package/tsc/webusb/webusb-device.ts +534 -0
- package/tsconfig.json +17 -0
- package/typedoc.json +9 -0
- package/usb.js +0 -573
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webusb-device.js","sourceRoot":"","sources":["../../tsc/webusb/webusb-device.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAA8B;AAC9B,6BAAiC;AAEjC,iCAAgC;AAEhC,IAAM,yBAAyB,GAAG,IAAI,CAAC;AACvC,IAAM,oBAAoB,GAAG,IAAI,CAAC;AAClC,IAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,IAAM,aAAa,GAAG,IAAI,CAAC;AAE3B;;GAEG;AACH;IA8BI,sBAA4B,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAJvC,mBAAc,GAAuB,EAAE,CAAC;QAEvC,gBAAW,GAAG,IAAI,aAAK,EAAE,CAAC;QAG9B,IAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAA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C,eAAe,CAAC,CAAC;wBAC/C,OAAO,GAAG,gBAAS,CAAC,OAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAK,CAAC,CAAC;wBACrD,qBAAM,OAAO,EAAE,EAAA;;wBAAf,SAAe,CAAC;;;;wBAEhB,MAAM,IAAI,KAAK,CAAC,6BAA2B,QAAO,CAAC,CAAC;;;;;KAE3D;IACL,mBAAC;AAAD,CAAC,AAxgBD,IAwgBC;AAxgBY,oCAAY"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "usb",
|
|
3
3
|
"description": "Library to access USB devices",
|
|
4
|
-
"
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"version": "2.0.1",
|
|
6
|
+
"main": "dist/index.js",
|
|
5
7
|
"engines": {
|
|
6
8
|
"node": ">=10.16.0"
|
|
7
9
|
},
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/node-usb/node-usb.git"
|
|
13
|
+
},
|
|
12
14
|
"contributors": [
|
|
13
15
|
{
|
|
14
16
|
"name": "Kevin Mehall",
|
|
@@ -29,16 +31,21 @@
|
|
|
29
31
|
"name": "Christopher Klein"
|
|
30
32
|
}
|
|
31
33
|
],
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"usb",
|
|
36
|
+
"hardware"
|
|
37
|
+
],
|
|
37
38
|
"scripts": {
|
|
39
|
+
"prepare": "yarn compile",
|
|
38
40
|
"install": "node-gyp-build",
|
|
41
|
+
"clean": "git clean -dfx",
|
|
42
|
+
"compile": "tsc && yarn lint && yarn docs",
|
|
43
|
+
"lint": "eslint . --ext .ts",
|
|
44
|
+
"watch": "tsc -w --preserveWatchOutput",
|
|
39
45
|
"test": "mocha --require coffeescript/register --grep Module test/*",
|
|
40
|
-
"full-test": "mocha --require coffeescript/register test
|
|
41
|
-
"valgrind": "coffee -c test
|
|
46
|
+
"full-test": "mocha --require coffeescript/register test/*.coffee",
|
|
47
|
+
"valgrind": "coffee -c test/*.coffee; valgrind --leak-check=full --show-possibly-lost=no node --expose-gc --trace-gc node_modules/mocha/bin/_mocha -R spec",
|
|
48
|
+
"docs": "typedoc",
|
|
42
49
|
"prebuild": "prebuildify --napi --strip",
|
|
43
50
|
"prebuild-darwin": "prebuildify --napi --strip --arch x64+arm64",
|
|
44
51
|
"prebuild-win32-x86": "prebuildify --napi --strip",
|
|
@@ -50,18 +57,24 @@
|
|
|
50
57
|
"prebuild-download": "prebuildify-ci download"
|
|
51
58
|
},
|
|
52
59
|
"dependencies": {
|
|
60
|
+
"@types/w3c-web-usb": "^1.0.4",
|
|
53
61
|
"node-addon-api": "^4.2.0",
|
|
54
62
|
"node-gyp-build": "^4.3.0"
|
|
55
63
|
},
|
|
56
64
|
"devDependencies": {
|
|
57
|
-
"
|
|
65
|
+
"@types/node": "^14.14.41",
|
|
66
|
+
"@typescript-eslint/eslint-plugin": "^4.28.0",
|
|
67
|
+
"@typescript-eslint/parser": "^4.28.0",
|
|
68
|
+
"coffeescript": "^2.5.1",
|
|
69
|
+
"eslint": "^7.29.0",
|
|
58
70
|
"mocha": "^9.1.3",
|
|
59
71
|
"node-gyp": "^7.1.2",
|
|
60
72
|
"prebuildify": "^4.2.1",
|
|
61
73
|
"prebuildify-ci": "^1.0.5",
|
|
62
|
-
"prebuildify-cross": "^4.0.1"
|
|
74
|
+
"prebuildify-cross": "^4.0.1",
|
|
75
|
+
"typedoc": "^0.22.10",
|
|
76
|
+
"typescript": "~4.2.4"
|
|
63
77
|
},
|
|
64
|
-
"license": "MIT",
|
|
65
78
|
"binary": {
|
|
66
79
|
"napi_versions": [
|
|
67
80
|
4
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/device.cc
CHANGED
|
@@ -19,18 +19,12 @@ Device::Device(const Napi::CallbackInfo & info) : Napi::ObjectWrap<Device>(info)
|
|
|
19
19
|
device = info[0].As<Napi::External<libusb_device>>().Data();
|
|
20
20
|
libusb_ref_device(device);
|
|
21
21
|
byPtr.insert(std::make_pair(device, this));
|
|
22
|
-
#ifndef USE_POLL
|
|
23
|
-
completionQueue.start(info.Env());
|
|
24
|
-
#endif
|
|
25
22
|
DEBUG_LOG("Created device %p", this);
|
|
26
23
|
Constructor(info);
|
|
27
24
|
}
|
|
28
25
|
|
|
29
26
|
Device::~Device(){
|
|
30
27
|
DEBUG_LOG("Freed device %p", this);
|
|
31
|
-
#ifndef USE_POLL
|
|
32
|
-
completionQueue.stop();
|
|
33
|
-
#endif
|
|
34
28
|
byPtr.erase(device);
|
|
35
29
|
libusb_close(device_handle);
|
|
36
30
|
libusb_unref_device(device);
|
|
@@ -194,6 +188,9 @@ Napi::Value Device::Open(const Napi::CallbackInfo& info) {
|
|
|
194
188
|
ENTER_METHOD(Device, 0);
|
|
195
189
|
if (!self->device_handle){
|
|
196
190
|
CHECK_USB(libusb_open(self->device, &self->device_handle));
|
|
191
|
+
#ifndef USE_POLL
|
|
192
|
+
completionQueue.start(info.Env());
|
|
193
|
+
#endif
|
|
197
194
|
}
|
|
198
195
|
return env.Undefined();
|
|
199
196
|
}
|
|
@@ -203,6 +200,9 @@ Napi::Value Device::Close(const Napi::CallbackInfo& info) {
|
|
|
203
200
|
if (self->canClose()){
|
|
204
201
|
libusb_close(self->device_handle);
|
|
205
202
|
self->device_handle = NULL;
|
|
203
|
+
#ifndef USE_POLL
|
|
204
|
+
completionQueue.stop();
|
|
205
|
+
#endif
|
|
206
206
|
}else{
|
|
207
207
|
THROW_ERROR("Can't close device with a pending request");
|
|
208
208
|
}
|
package/test/usb.coffee
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
assert = require('assert')
|
|
2
2
|
util = require('util')
|
|
3
|
-
usb = require(
|
|
3
|
+
usb = require('../').usb
|
|
4
|
+
getDeviceList = require('../').getDeviceList
|
|
5
|
+
findByIds = require('../').findByIds
|
|
6
|
+
findBySerialNumber = require('../').findBySerialNumber
|
|
4
7
|
|
|
5
8
|
if typeof gc is 'function'
|
|
6
9
|
# running with --expose-gc, do a sweep between tests so valgrind blames the right one
|
|
7
10
|
afterEach -> gc()
|
|
8
11
|
|
|
9
|
-
describe 'Module', ->
|
|
12
|
+
describe 'USB Module', ->
|
|
10
13
|
it 'should describe basic constants', ->
|
|
11
14
|
assert.notEqual(usb, undefined, "usb must be undefined")
|
|
12
15
|
assert.ok((usb.LIBUSB_CLASS_PER_INTERFACE != undefined), "Constants must be described")
|
|
@@ -28,19 +31,23 @@ describe 'Module', ->
|
|
|
28
31
|
|
|
29
32
|
describe 'getDeviceList', ->
|
|
30
33
|
it 'should return at least one device', ->
|
|
31
|
-
l =
|
|
34
|
+
l = getDeviceList()
|
|
32
35
|
assert.ok((l.length > 0))
|
|
33
36
|
|
|
34
37
|
describe 'findByIds', ->
|
|
35
38
|
it 'should return an array with length > 0', ->
|
|
36
|
-
dev =
|
|
39
|
+
dev = findByIds(0x59e3, 0x0a23)
|
|
37
40
|
assert.ok(dev, "Demo device is not attached")
|
|
38
41
|
|
|
42
|
+
describe 'findBySerialNumber', ->
|
|
43
|
+
it 'should return a single device ', ->
|
|
44
|
+
dev = findBySerialNumber('TEST_DEVICE')
|
|
45
|
+
assert.ok(dev, "Demo device is not attached")
|
|
39
46
|
|
|
40
47
|
describe 'Device', ->
|
|
41
48
|
device = null
|
|
42
49
|
before ->
|
|
43
|
-
device =
|
|
50
|
+
device = findByIds(0x59e3, 0x0a23)
|
|
44
51
|
|
|
45
52
|
it 'should have sane properties', ->
|
|
46
53
|
assert.ok((device.busNumber > 0), "busNumber must be larger than 0")
|
|
@@ -70,7 +77,7 @@ describe 'Device', ->
|
|
|
70
77
|
assert.ok(e == undefined, e)
|
|
71
78
|
done()
|
|
72
79
|
|
|
73
|
-
it
|
|
80
|
+
it 'should fail when bmRequestType doesn\'t match buffer / length', ->
|
|
74
81
|
assert.throws(-> device.controlTransfer(0x40, 0x81, 0, 0, 64))
|
|
75
82
|
|
|
76
83
|
it 'should IN transfer when the IN bit is set', (done) ->
|
|
@@ -158,7 +165,6 @@ describe 'Device', ->
|
|
|
158
165
|
#console.log("Stream stopped")
|
|
159
166
|
done()
|
|
160
167
|
|
|
161
|
-
|
|
162
168
|
describe 'OUT endpoint', ->
|
|
163
169
|
outEndpoint = null
|
|
164
170
|
before ->
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
assert = require('assert')
|
|
2
|
+
util = require('util')
|
|
3
|
+
webusb = require('../').webusb
|
|
4
|
+
|
|
5
|
+
if typeof gc is 'function'
|
|
6
|
+
# running with --expose-gc, do a sweep between tests so valgrind blames the right one
|
|
7
|
+
afterEach -> gc()
|
|
8
|
+
|
|
9
|
+
describe 'WebUSB Module', ->
|
|
10
|
+
it 'should describe basic constants', ->
|
|
11
|
+
assert.notEqual(webusb, undefined, "webusb must be undefined")
|
|
12
|
+
|
|
13
|
+
describe 'requestDevice', ->
|
|
14
|
+
it 'should return a device', ->
|
|
15
|
+
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
16
|
+
assert.notEqual(device, undefined)
|
|
17
|
+
|
|
18
|
+
describe 'getDevices', ->
|
|
19
|
+
it 'should return one device', ->
|
|
20
|
+
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
21
|
+
l = await webusb.getDevices()
|
|
22
|
+
assert.equal(l.length, 1)
|
|
23
|
+
assert.notEqual(l[0], undefined)
|
|
24
|
+
assert.deepEqual(l[0], device)
|
|
25
|
+
|
|
26
|
+
describe 'Device properties', ->
|
|
27
|
+
device = null
|
|
28
|
+
before ->
|
|
29
|
+
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
30
|
+
|
|
31
|
+
it 'should have usb version properties', ->
|
|
32
|
+
assert.equal(device.usbVersionMajor, 1)
|
|
33
|
+
assert.equal(device.usbVersionMinor, 1)
|
|
34
|
+
assert.equal(device.usbVersionSubminor, 0)
|
|
35
|
+
|
|
36
|
+
it 'should have device version properties', ->
|
|
37
|
+
assert.equal(device.deviceVersionMajor, 1)
|
|
38
|
+
assert.equal(device.deviceVersionMinor, 1)
|
|
39
|
+
assert.equal(device.deviceVersionSubminor, 0)
|
|
40
|
+
|
|
41
|
+
it 'should have class properties', ->
|
|
42
|
+
assert.equal(device.deviceClass, 0)
|
|
43
|
+
assert.equal(device.deviceSubclass, 0)
|
|
44
|
+
|
|
45
|
+
it 'should have protocol property', ->
|
|
46
|
+
assert.equal(device.deviceProtocol, 0)
|
|
47
|
+
|
|
48
|
+
it 'should have vid/pid properties', ->
|
|
49
|
+
assert.equal(device.vendorId, 0x59e3)
|
|
50
|
+
assert.equal(device.productId, 0x0a23)
|
|
51
|
+
|
|
52
|
+
it 'should have a single configuration', ->
|
|
53
|
+
assert.equal(device.configurations.length, 1)
|
|
54
|
+
assert.equal(device.configurations[0].configurationValue, 1)
|
|
55
|
+
|
|
56
|
+
it 'should have a configuration property', ->
|
|
57
|
+
assert.notEqual(device.configuration, undefined)
|
|
58
|
+
|
|
59
|
+
it 'should have a single interface', ->
|
|
60
|
+
assert.equal(device.configuration.interfaces.length, 1)
|
|
61
|
+
assert.equal(device.configuration.interfaces[0].interfaceNumber, 0)
|
|
62
|
+
|
|
63
|
+
it 'should have a single alternate', ->
|
|
64
|
+
assert.equal(device.configuration.interfaces[0].alternates.length, 1)
|
|
65
|
+
assert.equal(device.configuration.interfaces[0].alternates[0].alternateSetting, 0)
|
|
66
|
+
|
|
67
|
+
describe 'String descriptors', ->
|
|
68
|
+
device = null
|
|
69
|
+
before ->
|
|
70
|
+
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
71
|
+
|
|
72
|
+
it 'gets serialNumber string', ->
|
|
73
|
+
assert.equal(device.serialNumber, "TEST_DEVICE")
|
|
74
|
+
|
|
75
|
+
it 'gets manufacturerName string', ->
|
|
76
|
+
assert.equal(device.manufacturerName, "Nonolith Labs")
|
|
77
|
+
|
|
78
|
+
it 'gets productName string', ->
|
|
79
|
+
assert.equal(device.productName, "STM32F103 Test Device")
|
|
80
|
+
|
|
81
|
+
describe 'Device access', ->
|
|
82
|
+
device = null
|
|
83
|
+
before ->
|
|
84
|
+
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
85
|
+
|
|
86
|
+
it 'is not open', ->
|
|
87
|
+
assert.equal(device.opened, false)
|
|
88
|
+
|
|
89
|
+
it 'is opens and closes', ->
|
|
90
|
+
assert.equal(device.opened, false)
|
|
91
|
+
await device.open()
|
|
92
|
+
assert.equal(device.opened, true)
|
|
93
|
+
await device.close()
|
|
94
|
+
assert.equal(device.opened, false)
|
|
95
|
+
|
|
96
|
+
describe 'Configurations', ->
|
|
97
|
+
device = null
|
|
98
|
+
before ->
|
|
99
|
+
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
100
|
+
await device.open()
|
|
101
|
+
|
|
102
|
+
it 'selects existing configuration', ->
|
|
103
|
+
assert.doesNotReject(device.selectConfiguration(1))
|
|
104
|
+
|
|
105
|
+
it 'fails to select missing configuration', ->
|
|
106
|
+
assert.rejects(device.selectConfiguration(99))
|
|
107
|
+
|
|
108
|
+
after ->
|
|
109
|
+
device.close()
|
|
110
|
+
|
|
111
|
+
describe 'Interfaces', ->
|
|
112
|
+
device = null
|
|
113
|
+
before ->
|
|
114
|
+
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
115
|
+
await device.open()
|
|
116
|
+
|
|
117
|
+
it 'claims existing interface', ->
|
|
118
|
+
assert.doesNotReject(device.claimInterface(0))
|
|
119
|
+
|
|
120
|
+
it 'fails to claim missing interface', ->
|
|
121
|
+
assert.rejects(device.claimInterface(99))
|
|
122
|
+
|
|
123
|
+
it 'releases existing interface', ->
|
|
124
|
+
assert.doesNotReject(device.releaseInterface(0))
|
|
125
|
+
|
|
126
|
+
it 'fails to release missing interface', ->
|
|
127
|
+
assert.rejects(device.releaseInterface(99))
|
|
128
|
+
|
|
129
|
+
after ->
|
|
130
|
+
device.close()
|
|
131
|
+
|
|
132
|
+
describe 'Alternates', ->
|
|
133
|
+
device = null
|
|
134
|
+
before ->
|
|
135
|
+
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
136
|
+
await device.open()
|
|
137
|
+
await device.claimInterface(0)
|
|
138
|
+
|
|
139
|
+
it 'selects existing alternate', ->
|
|
140
|
+
assert.doesNotReject(device.selectAlternateInterface(0, 0))
|
|
141
|
+
|
|
142
|
+
after ->
|
|
143
|
+
device.close()
|
|
144
|
+
|
|
145
|
+
describe 'Transfers', ->
|
|
146
|
+
device = null
|
|
147
|
+
b = Uint8Array.from([0x30...0x40]).buffer
|
|
148
|
+
|
|
149
|
+
before ->
|
|
150
|
+
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
151
|
+
await device.open()
|
|
152
|
+
await device.claimInterface(0)
|
|
153
|
+
|
|
154
|
+
it 'should control transfer OUT', ->
|
|
155
|
+
transferResult = await device.controlTransferOut({
|
|
156
|
+
requestType: 'device',
|
|
157
|
+
recipient: 'vendor';
|
|
158
|
+
request: 0x81,
|
|
159
|
+
value: 0,
|
|
160
|
+
index: 0
|
|
161
|
+
}, b)
|
|
162
|
+
|
|
163
|
+
assert.equal(transferResult.status, 'ok')
|
|
164
|
+
assert.equal(transferResult.bytesWritten, b.byteLength)
|
|
165
|
+
|
|
166
|
+
it 'should control transfer IN', ->
|
|
167
|
+
transferResult = await device.controlTransferIn({
|
|
168
|
+
requestType: 'device',
|
|
169
|
+
recipient: 'vendor';
|
|
170
|
+
request: 0x81,
|
|
171
|
+
value: 0,
|
|
172
|
+
index: 0
|
|
173
|
+
}, 128)
|
|
174
|
+
|
|
175
|
+
assert.equal(transferResult.status, 'ok')
|
|
176
|
+
assert.equal(transferResult.data.buffer.toString(), b.toString())
|
|
177
|
+
|
|
178
|
+
it 'should transfer OUT', ->
|
|
179
|
+
transferResult = await device.transferOut(2, b)
|
|
180
|
+
assert.equal(transferResult.status, 'ok')
|
|
181
|
+
assert.equal(transferResult.bytesWritten, b.byteLength)
|
|
182
|
+
|
|
183
|
+
it 'should transfer IN', ->
|
|
184
|
+
transferResult = await device.transferIn(1, 64)
|
|
185
|
+
assert.equal(transferResult.status, 'ok')
|
|
186
|
+
assert.equal(transferResult.data.byteLength, 64)
|
|
187
|
+
|
|
188
|
+
after ->
|
|
189
|
+
device.close()
|
package/tsc/index.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { promisify } from 'util';
|
|
2
|
+
import { WebUSB } from './webusb';
|
|
3
|
+
import { WebUSBDevice } from './webusb/webusb-device';
|
|
4
|
+
import * as usb from './usb';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Convenience method to get the first device with the specified VID and PID, or `undefined` if no such device is present.
|
|
8
|
+
* @param vid
|
|
9
|
+
* @param pid
|
|
10
|
+
*/
|
|
11
|
+
const findByIds = (vid: number, pid: number): usb.Device | undefined => {
|
|
12
|
+
const devices = usb.getDeviceList();
|
|
13
|
+
return devices.find(item => item.deviceDescriptor.idVendor === vid && item.deviceDescriptor.idProduct === pid);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Convenience method to get the device with the specified serial number, or `undefined` if no such device is present.
|
|
18
|
+
* @param serialNumber
|
|
19
|
+
*/
|
|
20
|
+
const findBySerialNumber = async (serialNumber: string): Promise<usb.Device | undefined> => {
|
|
21
|
+
const devices = usb.getDeviceList();
|
|
22
|
+
|
|
23
|
+
for (const device of devices) {
|
|
24
|
+
try {
|
|
25
|
+
device.open();
|
|
26
|
+
|
|
27
|
+
const getStringDescriptor = promisify(device.getStringDescriptor).bind(device);
|
|
28
|
+
const buffer = await getStringDescriptor(device.deviceDescriptor.iSerialNumber);
|
|
29
|
+
|
|
30
|
+
if (buffer && buffer.toString() === serialNumber) {
|
|
31
|
+
return device;
|
|
32
|
+
}
|
|
33
|
+
} catch {
|
|
34
|
+
// Ignore any errors, device may be a system device or inaccessible
|
|
35
|
+
} finally {
|
|
36
|
+
try {
|
|
37
|
+
device.close();
|
|
38
|
+
} catch {
|
|
39
|
+
// Ignore any errors, device may be a system device or inaccessible
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return undefined;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const webusb = new WebUSB();
|
|
48
|
+
const getDeviceList = usb.getDeviceList;
|
|
49
|
+
|
|
50
|
+
export {
|
|
51
|
+
// Core usb object for quick access
|
|
52
|
+
usb,
|
|
53
|
+
|
|
54
|
+
// Convenience methods
|
|
55
|
+
getDeviceList,
|
|
56
|
+
findByIds,
|
|
57
|
+
findBySerialNumber,
|
|
58
|
+
|
|
59
|
+
// Default WebUSB object (mimics navigator.usb)
|
|
60
|
+
webusb,
|
|
61
|
+
|
|
62
|
+
// WebUSB class for creating custom webusb instances
|
|
63
|
+
WebUSB,
|
|
64
|
+
|
|
65
|
+
// WebUSB Device class for turning a legacy usb.Device into a webusb device
|
|
66
|
+
WebUSBDevice
|
|
67
|
+
};
|