Socket
Socket
Sign inDemoInstall

usb

Package Overview
Dependencies
Maintainers
2
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

usb - npm Package Compare versions

Comparing version 0.3.11 to 1.0.1

.gitmodules

11

package.json

@@ -27,7 +27,7 @@ {

],
"version": "0.3.11",
"version": "1.0.1",
"optionalDependencies": {
"usb-shyp-win32-x64": "0.3.x",
"usb-shyp-win32-ia32": "0.3.x",
"usb-shyp-darwin-x64": "0.3.x"
"usb-shyp-win32-x64": "1.0.0",
"usb-shyp-win32-ia32": "1.0.0",
"usb-shyp-darwin-x64": "1.0.0"
},

@@ -49,3 +49,4 @@ "engines": {

"dependencies": {
"bindings-shyp": "~0.2.3"
"bindings-shyp": "~0.2.3",
"nan": "^1.6.0"
},

@@ -52,0 +53,0 @@ "devDependencies": {

USB Library for Node.JS
===============================
**POSIX:** [![Build Status](https://travis-ci.org/nonolith/node-usb.svg?branch=tcr-usb)](https://travis-ci.org/nonolith/node-usb)     **Windows:** [![Build status](https://ci.appveyor.com/api/projects/status/1q64jnnfseidkjwl)](https://ci.appveyor.com/project/tcr/node-usb)
**POSIX:** [![Build Status](https://travis-ci.org/nonolith/node-usb.svg?branch=tcr-usb)](https://travis-ci.org/nonolith/node-usb)     **Windows:** [![Build status](https://ci.appveyor.com/api/projects/status/b23kn1pi386nguya/branch/master)](https://ci.appveyor.com/project/kevinmehall/node-usb/branch/master)

@@ -12,17 +12,7 @@ Node.JS library for communicating with USB devices in JavaScript / CoffeeScript.

Tested with Node 0.10/Fedora and Node 0.10/WinXP.
Installation
============
Libusb is required. Older versions of libusb segfault when using bulk or interrupt endpoints.
Use [libusb](http://libusb.org) or [libusbx](http://libusbx.org) 1.0.9 or greater.
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`
**Ubuntu/Debian:** `sudo apt-get install build-essential pkg-config libusb-1.0-0-dev`
**Fedora:** `sudo yum install libusbx-devel`
**OSX:** `brew install libusb pkg-config`
**Windows:** Download a Windows Binary package from http://libusbx.org/ and extract it at `C:\Program Files\libusb`. Use [Zadig](http://sourceforge.net/projects/libwdi/files/zadig/) to install the WinUSB driver for your USB device. Otherwise you will get a `LIBUSB_ERROR_NOT_SUPPORTED` when attempting to open devices.
Then, just run

@@ -34,6 +24,10 @@

### Windows
Use [Zadig](http://sourceforge.net/projects/libwdi/files/zadig/) to install the WinUSB driver for your USB device. Otherwise you will get `LIBUSB_ERROR_NOT_SUPPORTED` when attempting to open devices.
API
===
var usb = require('usb')
var usb = require('usb')

@@ -68,2 +62,5 @@ usb

### .portNumbers
Array containing the USB device port numbers
### .deviceDescriptor

@@ -126,3 +123,3 @@ Object with properties for the fields of the device descriptor:

### .timeout
Timeout in milliseconds to use for controlTransfer and endpoint transfers.
Timeout in milliseconds to use for control transfers.

@@ -188,3 +185,3 @@ ### .reset(callback(error))

### .direction
Endpoint direction: `usb.LIBUSB_ENDPOINT_IN` or `usb.LIBUSB_ENDPOINT_OUT`.
Endpoint direction: `"in"` or `"out"`.

@@ -207,2 +204,5 @@ ### .transferType

### .timeout
Sets the timeout in milliseconds for transfers on this endpoint. The default, `0`, is infinite timeout.
InEndpoint

@@ -220,23 +220,24 @@ ----------

### .startStream(nTransfers=3, transferSize=maxPacketSize)
Start a streaming transfer from the endpoint.
### .startPoll(nTransfers=3, transferSize=maxPacketSize)
Start polling the endpoint.
The library will keep `nTransfers`
transfers of size `transferSize` pending in the kernel at all times to ensure
continuous data flow. This is handled by the libusb event thread, so it continues even
if the Node v8 thread is busy. The `data` and `error` events are emitted as transfers complete.
The library will keep `nTransfers` transfers of size `transferSize` pending in
the kernel at all times to ensure continuous data flow. This is handled by the
libusb event thread, so it continues even if the Node v8 thread is busy. The
`data` and `error` events are emitted as transfers complete.
### .stopStream()
Stop the streaming transfer.
### .stopPoll(cb)
Stop polling.
Further data may still be received. The `end` event is emitted once all transfers have completed or canceled.
Further data may still be received. The `end` event is emitted and the callback
is called once all transfers have completed or canceled.
### Event: data(data : Buffer)
Emitted with data received by the stream
Emitted with data received by the polling transfers
### Event: error(error)
Emitted when the stream encounters an error.
Emitted when polling encounters an error.
### Event: end
Emitted when the stream has been canceled
Emitted when polling has been canceled

@@ -255,22 +256,2 @@ OutEndpoint

### .startStream(nTransfers=3, transferSize=maxPacketSize)
Start a streaming transfer to the endpoint.
The library will help you maintain `nTransfers` transfers pending in the kernel to ensure continuous data flow.
The `drain` event is emitted when another transfer is necessary. Your `drain` handler should use the .write() method
to start another transfer.
### .write(data)
Write `data` to the endpoint with the stream. `data` should be a buffer of length `transferSize` as passed to startStream.
Delegates to .transfer(), but differs in that it updates the stream state tracking the number of requests in flight.
### .stopStream()
Stop the streaming transfer.
No further `drain` events will be emitted. When all transfers have been completed, the OutEndpoint emits the `end` event.
### Event: drain
Emitted when the stream requests more data. Use the .write() method to start another transfer.
### Event: error(error)

@@ -288,3 +269,3 @@ Emitted when the stream encounters an error.

git clone https://github.com/nonolith/node-usb.git
git clone --recursive https://github.com/nonolith/node-usb.git
cd node-usb

@@ -306,1 +287,8 @@ npm install

- Isochronous transfers
License
=======
MIT
Note that the compiled Node extension includes Libusb, and is thus subject to the LGPL.

@@ -10,6 +10,10 @@ var usb = exports = module.exports = require("bindings-shyp")("usb_bindings")

Object.keys(events.EventEmitter.prototype).forEach(function (key) {
exports[key] = events.EventEmitter.prototype[key];
});
// convenience method for finding a device by vendor and product id
exports.findByIds = function(vid, pid) {
var devices = usb.getDeviceList()
for (var i = 0; i < devices.length; i++) {

@@ -40,5 +44,5 @@ var deviceDesc = devices[i].deviceDescriptor

Object.defineProperty(usb.Device.prototype, "configDescriptor", {
get: function() {
return this.configDescriptor = this.__getConfigDescriptor()
}
get: function() {
return this._configDescriptor || (this._configDescriptor = this.__getConfigDescriptor())
}
});

@@ -102,3 +106,9 @@

)
return transfer.submit(buf)
try {
transfer.submit(buf)
} catch (e) {
process.nextTick(function() { callback.call(self, e); });
}
return this;
}

@@ -157,7 +167,7 @@

self.endpoints.forEach(function (ep, i) {
if (ep.streamActive) {
if (ep.pollActive) {
ep.once('end', function () {
if (--n == 0) next();
});
ep.stopStream();
ep.stopPoll();
} else {

@@ -221,2 +231,4 @@ if (--n == 0) next();

Endpoint.prototype.timeout = 0
Endpoint.prototype.makeTransfer = function(timeout, callback){

@@ -226,11 +238,11 @@ return new usb.Transfer(this.device, this.address, this.transferType, timeout, callback)

Endpoint.prototype.startStream = function(nTransfers, transferSize, callback){
if (this.streamTransfers){
throw new Error("Stream already active")
Endpoint.prototype.startPoll = function(nTransfers, transferSize, callback){
if (this.pollTransfers){
throw new Error("Polling already active")
}
nTransfers = nTransfers || 3;
this.streamTransferSize = transferSize || this.maxPacketSize;
this.streamActive = true
this.streamPending = 0
this.pollTransferSize = transferSize || this.descriptor.wMaxPacketSize;
this.pollActive = true
this.pollPending = 0

@@ -244,10 +256,11 @@ var transfers = []

Endpoint.prototype.stopStream = function(){
if (!this.streamTransfers) {
throw new Error('Stream is not active.');
Endpoint.prototype.stopPoll = function(cb){
if (!this.pollTransfers) {
throw new Error('Polling is not active.');
}
for (var i=0; i<this.streamTransfers.length; i++){
this.streamTransfers[i].cancel()
for (var i=0; i<this.pollTransfers.length; i++){
this.pollTransfers[i].cancel()
}
this.streamActive = false
this.pollActive = false
if (cb) this.once('end', cb);
}

@@ -271,9 +284,14 @@

return this.makeTransfer(this.device.timeout, callback).submit(buffer)
try {
this.makeTransfer(this.timeout, callback).submit(buffer)
} catch (e) {
process.nextTick(function() { cb.call(self, e); });
}
return this;
}
InEndpoint.prototype.startStream = function(nTransfers, transferSize){
InEndpoint.prototype.startPoll = function(nTransfers, transferSize){
var self = this
this.streamTransfers = InEndpoint.super_.prototype.startStream.call(this, nTransfers, transferSize, transferDone)
this.pollTransfers = InEndpoint.super_.prototype.startPoll.call(this, nTransfers, transferSize, transferDone)
function transferDone(error, buf, actual){

@@ -284,11 +302,11 @@ if (!error){

self.emit("error", error)
self.stopStream()
self.stopPoll()
}
if (self.streamActive){
if (self.pollActive){
startTransfer(this)
}else{
self.streamPending--
self.pollPending--
if (self.streamPending == 0){
if (self.pollPending == 0){
self.emit('end')

@@ -300,7 +318,12 @@ }

function startTransfer(t){
t.submit(new Buffer(self.streamTransferSize), transferDone)
try {
t.submit(new Buffer(self.pollTransferSize), transferDone);
} catch (e) {
self.emit("error", e);
self.stopPoll();
}
}
this.streamTransfers.forEach(startTransfer)
self.streamPending = this.streamTransfers.length
this.pollTransfers.forEach(startTransfer)
self.pollPending = this.pollTransfers.length
}

@@ -329,3 +352,9 @@

return this.makeTransfer(this.device.timeout, callback).submit(buffer)
try {
this.makeTransfer(this.timeout, callback).submit(buffer);
} catch (e) {
process.nextTick(function() { callback(e); });
}
return this;
}

@@ -342,36 +371,11 @@

var hotplugListeners = 0;
exports.on('newListener', function(name) {
if (name !== 'attach' && name !== 'detach') return;
if (++hotplugListeners === 1) usb._enableHotplugEvents();
});
OutEndpoint.prototype.startStream = function startStream(n_transfers, transfer_size){
n_transfers = n_transfers || 3;
transfer_size = transfer_size || this.maxPacketSize;
this.streamActive = true;
this._streamTransfers = n_transfers;
this._pendingTransfers = 0;
var self = this
process.nextTick(function(){
for (var i=0; i<n_transfers; i++) self.emit('drain')
})
}
function out_ep_callback(err, d){
if (err) this.emit('error', err);
this._pendingTransfers--;
if (this._pendingTransfers < this._streamTransfers){
this.emit('drain');
}
if (this._pendingTransfers <= 0 && this._streamTransfers == 0){
this.emit('end');
}
}
usb.OutEndpoint.prototype.write = function write(data){
this.transfer(data, out_ep_callback);
this._pendingTransfers++;
}
usb.OutEndpoint.prototype.stopStream = function stopStream(){
this._streamTransfers = 0;
this.streamActive = false;
if (this._pendingTransfers === null) throw new Error('stopStream invoked on non-active stream.');
if (this._pendingTransfers == 0) this.emit('end');
}
exports.on('removeListener', function(name) {
if (name !== 'attach' && name !== 'detach') return;
if (--hotplugListeners === 0) usb._disableHotplugEvents();
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc