Skip to content

Instantly share code, notes, and snippets.

@davidkelley
Last active January 27, 2020 08:43
Show Gist options
  • Save davidkelley/9002267 to your computer and use it in GitHub Desktop.
Save davidkelley/9002267 to your computer and use it in GitHub Desktop.
Example showing how to connect with a USB device using Javascript. Note that this file uses the chrome.usb.* API's which are only available for "packaged app" Chrome extensions.
var port = 0;
var endpoint = 0x01;
var device = { vendorId: 0x04b8, productId: 0x0202};
var connect = function(callback) {
chrome.permissions.getAll(function(p) {
if (p.permissions.indexOf('usb') >= 0) {
//construct permission object for our device
var obj = { usbDevices: [device] };
//now request the permissions
chrome.permissions.request({ permissions: [obj] }, function(granted) {
if (granted) {
chrome.usb.findDevices(device, function(devices) {
if (devices && devices.length > 0) {
//use the first found device
var foundDevice = devices[0];
//now lets reset the device
chrome.usb.resetDevice(foundDevice, function() {
//perform some error checking to make sure we reset the device
if ( ! chrome.runtime.lastError) {
//now claim the interface using the port we specified
chrome.usb.claimInterface(foundDevice, port, function() {
if ( ! chrome.runtime.lastError) {
callback(foundDevice);
} else {
throw chrome.runtime.lastError.message;
}
})
} else {
throw chrome.runtime.lastError.message;
}
});
} else {
console.warn("Device not found!");
}
});
} else {
console.warn("USB Permission not granted.")
}
});
} else {
console.warn("No USB permissions granted.");
}
});
}
@vickyi
Copy link

vickyi commented Jun 5, 2014

nice work

@FlorianCcj
Copy link

Hum .... If I want to be local, with node.js, how can Ido it work ?

@jaypram2014
Copy link

I need to communicate with a biometric fingerprint scanner attached with a USB port with my computer. How to fetch the bytes from the scanner ?

@vieirin
Copy link

vieirin commented Jul 18, 2018

@jaypram2014 did you achieve a communication with fingerprint scanner?

@abrararies
Copy link

This looks great! We are also looking for a way to communicate with fingerprint reader for web user identification.
@jaypram2014 @vieiramanoel did you have any luck with it? Thanks.

@pridemusvaire
Copy link

Did anyone get lucky with getting a fingerprint Scanner to work, Thanks

@elgibor-solution
Copy link

@abrararies @pridemusvaire any luck with the fingerprint scanner?

@pridemusvaire
Copy link

pridemusvaire commented Jan 27, 2020

@frozenmaiden nop, didn't manage to, did you find a different solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment