npm install @pokusew/usbUSB Library for Node.JS
===============================
POSIX:  Windows: 
Node.JS library for communicating with USB devices in JavaScript / CoffeeScript.
This is a refactoring / rewrite of Christopher Klein's node-usb. The API is not compatible (hopefully you find it an improvement).
It's based entirely on libusb's asynchronous API for better efficiency, and provides a stream API for continuously streaming data or events.
Installation
============
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
Then, just run
npm install usb
to install from npm. See the bottom of this page for instructions for building from a git checkout.
LIBUSB_ERROR_NOT_SUPPORTED when attempting to open devices.
API
===
var usb = require('usb')
usb
---
Top-level object.
Device objects for the USB devices attached to the system.undefined if no such device is present.Device
------
Represents a USB device.
undefined if not supported on this platform. - bLength
- bDescriptorType
- bcdUSB
- bDeviceClass
- bDeviceSubClass
- bDeviceProtocol
- bMaxPacketSize0
- idVendor
- idProduct
- bcdDevice
- iManufacturer
- iProduct
- iSerialNumber
- bNumConfigurations
- bLength
- bDescriptorType
- wTotalLength
- bNumInterfaces
- bConfigurationValue
- iConfiguration
- bmAttributes
- bMaxPower
- extra (Buffer containing any extra data or additional descriptors)
null.Open the device. All methods below require the device to be open before use.
Close the device.
Perform a control transfer with libusb_control_transfer.
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.
The data parameter of the callback is always undefined for OUT transfers, or will be passed a Buffer for IN transfers.
.open(false) (which tells it not to auto configure), then before claiming an interface, call this method.
Interface
---------
interface.endpoints array to reflect the endpoints found in the alternate setting.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.
false if a kernel driver is not active; true if active. - bLength
- bDescriptorType
- bInterfaceNumber
- bAlternateSetting
- bNumEndpoints
- bInterfaceClass
- bInterfaceSubClass
- bInterfaceProtocol
- iInterface
- extra (Buffer containing any extra data or additional descriptors)
Endpoint
--------
Common base for InEndpoint and OutEndpoint, see below.
"in" or "out".usb.LIBUSB_TRANSFER_TYPE_BULK, usb.LIBUSB_TRANSFER_TYPE_INTERRUPT, or usb.LIBUSB_TRANSFER_TYPE_ISOCHRONOUS. - bLength
- bDescriptorType
- bEndpointAddress
- bmAttributes
- wMaxPacketSize
- bInterval
- bRefresh
- bSynchAddress
- extra (Buffer containing any extra data or additional descriptors)
0, is infinite timeout.InEndpoint
----------
Endpoints in the IN direction (device->PC) have this type.
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.
this in the callback is the InEndpoint object.
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. Thedata and error events are emitted as transfers complete.
Further data may still be received. The end event is emitted and the callback
is called once all transfers have completed or canceled.
OutEndpoint
-----------
Endpoints in the OUT direction (PC->device) have this type.
data to the endpoint.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.
this in the callback is the OutEndpoint object.
UsbDetection
------------
device.device.
Development and testing
=======================
To build from git:
git clone --recursive https://github.com/nonolith/node-usb.git
cd node-usb
npm install
To execute the unit tests, CoffeeScript is required. Run
npm test
Some tests require an attached USB device -- firmware to be released soon.
Limitations
===========
Does not support:
- Configurations other than the default one
- Isochronous transfers
License
=======
MIT
Note that the compiled Node extension includes Libusb, and is thus subject to the LGPL.