Last active
January 27, 2020 08:43
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | |
} | |
}); | |
} |
Hum .... If I want to be local, with node.js, how can Ido it work ?
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 ?
@jaypram2014 did you achieve a communication with fingerprint scanner?
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.
Did anyone get lucky with getting a fingerprint Scanner to work, Thanks
@abrararies @pridemusvaire any luck with the fingerprint scanner?
@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
nice work