• Stars
    star
    182
  • Rank 210,480 (Top 5 %)
  • Language
    JavaScript
  • Created almost 14 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

node.js bindings for libusb-1.0

libusb-1.0 bindings for Node.js

node-usb binds libusb-1.0 to Node.js

Tested with Node version 0.6.6/Linux. Brew/OSX port of libusb-1.0 has still an issue which results in a segfault. Try using the latest development branch from http://git.libusb.org

Installation

Make sure you have installed libusb-1.0-0-dev (Ubuntu: sudo apt-get install libusb-1.0-0-dev).

Just run

make

in current directory and wait. "Unit tests" are automatically executed by default target. Failed unit tests do not mean that node-usb is not working. It depends on your USB environment that all tests pass. If they fail, just ignore them.

You can although execute the tests by typing:

node tests/node-usb-test.js

If you want to use the USB vendor ids, execute

make create-usb-ids

For creating debug output you have to compile node-usb with

make debug

or

node-waf clean configure --debug=true build

API

returned values can always be an error object, so make sure that no error occurs! The device/interface/endpoint descriptor values are always injected into the proper object. I do not list them.

Usb

.LIBUSB_* : const
	constant properties from libusb
.isLibusbInitalized : boolean
	property for getting libusb initalization status
.refresh() : undefined
	refreshes the node-usb environment
.setDebugLevel(int _level) : undefined
	wrapper for libusb_set_debug; _level has to be between 0 and 4
.getDevices() : Device[]
	returns the devices discovered by libusb
.close() : undefined
	closes node-usb

Device
.deviceAddress : int
	property for getting device address
.busNumber : int
	property for getting bus number
.reset(function _afterReset) : undefined
	[async] resets device, expects callback function after reset
.getConfigDescriptor() : Object
	returns configuration descriptor of device
.getExtraData() : Array
	returns byte array with extra data from config descriptor
.getInterfaces() : Interface[]
	returns interfaces
.getDeviceDescriptor() : Object
	returns devices descriptor
.controlTransfer(mixed read|write, int _bmRequestType, int _bRequest, int _wValue, int _wIndex, function afterTransfer(data) [, int _timeout])
	[async] delegates to libusb_control_transfer. First parameter can be either
	  * int, then controlTransfer works in read mode (read data FROM USB device)
	  * Buffer object, then controlTransfer works in write mode (write data TO USB device)
	_timeout parameter is optional.
	afterTransfer contains a Buffer object with the data read from device.

Interface

.__idxInterface : int
	property for internal interface index
.__idxAltSetting : int
	property for internal alternate interface setting
.getEndpoints() : Endpoint[]
	returns an array of Endpoint objects
.detachKernelDriver() : undefined
	detaches the kernel driver from interface
.attachKernelDriver() : undefined
	re-attaches the kernel driver to interface
.claim() : undefined
	claims the interface. this method must be __always__ called if you want to transfer data via the endpoint. There is no hig level API check for this
.release(function afterClaim(data)) : undefined
	[async] releases prior claimed interface; function wil be called after releasing
.setAlternateSetting(int _alternateSettingIdx, function afterAlternateSettingChosen(data))
	[async] sets alternate setting of interface; first parameter is the alternate setting index (there is no check for a valid index!), seconds is the callback function which is called after alternate setting has been chosen	
.isKernelDriverActive() : int
	returns 0  if not active; 1 if active
.getExtraData() : Array
	returns byte array with extra data from interface descriptor

Endpoint

.__endpointType : int
	property for getting the endpoint type (IN/OUT), check with Usb.LIBUSB_ENDPOINT_TYPE constants
.__transferType : int
	property for getting the transfer type (bulk, interrupt, isochronous); check with Usb.LIBUSB_TRANSFER_* constants
.__maxIsoPacketSize : int
	property for getting the max isochronous packet size if transfer type is isochronous
.__maxPacketSize : int
	property for getting the max packet size
.getExtraData() : Array
	byte array with extra data from endpoint descriptor
.bulkTransfer(mixed read|write, function afterTransfer(data) [, int _timeout])
.interruptTransfer(mixed read|write, function afterTransfer(data) [, int _timeout]) : undefined
	[async] bulkTransfer and interruptTransfer are more or less equal. If endpoint works in bulk mode, you use bulkTransfer(), if endpoint work in interrupt mode, you use interruptTransfer(). If you use the wrong method, the function call will fail.
	First parameter can be either
	* int, then the function will work in read mode (read _int_ bytes FROM USB device)
	* Buffer object, the function will work in write mode (write buffer TO USB device)
	The _timeout parameter is optional; if not used, an unlimited timeout is used.
	Both functions are working in asynchronous mode, the second parameter is the callback handler after the function has been executed / data arrived.
	afterTransfer contains a Buffer object as first parameter
.submitNative(mixed read|write, function after(data) [, int _timeout, int _iso_packets, int _flags]) : undefined
	[async] bulkTransfer, controlTransfer and interruptTransfer are using the EV library for threading. submitNative() uses the libusb asynchronous interface. This is not really tested now.
	submitNative() will be the only function to handle isochronous transfer mode and detects the endpoint type automatically.
	First parameter can be either (you know it already):
	* int, the function will be work in read mode (read _int_ bytes FROM USB device)
	* Buffer object, the function will work in write mode (write byte array TO USB device)
	The parameter _iso_packets and _flags can be used, if the endpoint is working in isochronous mode otherwise they are useless. 

Examples

A simple port of lsusb can be executed by typing

node examples/lsusb/lsusb.js

If you own a Microsoft Kinect, you can manipulate the LED, set the angle of the device and read the axis of the accelerometer

node examples/node-usb-kinect.js

Browse to localhost:8080 and see the magic.

If you have permission issues, you have to add the proper rights to the USB device or execute the examples as root (NOT RECOMMENDED!)

More information

More Repositories

1

monitord

inoffizielles Git-Repository von monitord.de
C
8
star
2

spring-modules-validation

spring-modules-validation fork for Java 1.6
Java
4
star
3

composite-eventbus

A simple composite manager and event bus for JavaScript
JavaScript
3
star
4

asp.net-msbuild-casperjs-teamcity

Example project: Connecting ASP.NET MVC, MSBuild, CasperJS and TeamCity
JavaScript
3
star
5

xtext-plugin-with-maven-tycho

A sample project configuration how to build your Xtext based DSL with Maven Tycho
Java
2
star
6

my-job-resources

Resources for developers and administrators
2
star
7

cryptocurrency-mining-tax-report

Einnahmenüberschussrechnung for the German Finanzamt when mining crypto currencies (BTC, ETH)
PHP
2
star
8

bootstrap-zf

Zend Framework library for rapid prototyping
PHP
2
star
9

bootstrap-zf-example

An example project how to use bootstrap-zf, twitter-bootstrap, composite-eventbus, PHP addendum and jQuery. This example shows how to implement AJAX requests, validation, Unit testing and other features.
PHP
2
star
10

ActiveDirectoryACE

ActiveDirectoryACE is a simple GUI for building ACE/SDDL string combinations. See http://msdn.microsoft.com/en-us/library/aa374928%28VS.85%29.aspx and http://msdn.microsoft.com/en-us/library/aa379570%28VS.85%29.aspx for more information
C#
2
star
11

zabos

ZABOS ist eine webbasierte Applikation zur SMS-Alarmierung von Behörden und Organisationen.
Java
1
star
12

monitord-activemq

ActiveMQ support for monitord
C++
1
star
13

nagios-twitter

small Twitter script for Nagios
Python
1
star
14

ant-twitter

Twitter support for the famous build tool Ant
Java
1
star
15

node-examples

Some node.js examples
JavaScript
1
star
16

nagdtsched

Nagios 3 downtime scheduler
1
star
17

svnPostCommitHook

svnPostCommitHook can be plugged into the SVN/Subversion post-commit-hook phase for executing special tasks.
PHP
1
star
18

db-migrator

A schema and data migration tool for databases
Groovy
1
star
19

confluence-macro-exchange-contacts

Use this Confluence macro to view all Exchange contacts inside a public folder
Java
1
star
20

bootstrap-net

Eine Sammlung von .NET Klassen, die in den letzten Jahren erstellt worden sind
C#
1
star
21

arquillian-warp-mocked-ejb

Mocked EJBs inside Arquillian and Warp integration testing environment
Java
1
star
22

scc

scc (ServiceConsoleControl) starts, stops and restarts Win32 services with their dependencies
C#
1
star
23

global-bind-user-for-mod_auth_ldap

patches mod_auth_ldap / mod_authnz_ldap so you can use one global LDAP bind user
C
1
star
24

eventcreateservice

SOAP service for Windows Event log - eventcreateservice.php (ECS) is a simple SOAP service which uses eventcreatef.exe by Florian Weinert (http://prunkster.ecw.de/2010/04/12/eventcreatef-exe-eine-erganzung-zu-eventcreate-exe/). Every incoming SOAP message will be passed through to eventcreatef.exe which will write the log message to a Windows 2003/XP event log. With ECS and eventcreatef.exe you can log any event to a an eventlog of central Windows machine without Syslogd running.
PHP
1
star