Skip to content

Instantly share code, notes, and snippets.

@brickgao
Created May 24, 2014 14:30
Show Gist options
  • Save brickgao/5354231e86a30cefe31d to your computer and use it in GitHub Desktop.
Save brickgao/5354231e86a30cefe31d to your computer and use it in GitHub Desktop.
var usb = require('usb');
var my_drive = usb.findByIds(4901, 49193);
my_drive.open();
interfaces = my_drive.interfaces[0];
interfaces.claim()
inEndpoint = interfaces.endpoints[0];
outEndpoint = interfaces.endpoints[1];
var data_sent = new Buffer('100300', 'hex');
inEndpoint.transferType = 2;
inEndpoint.startStream(1, 64);
inEndpoint.transfer(64, function (error, data) {
if (!error) {
console.log(data);
} else {
console.log(error);
}
});
inEndpoint.on('data', function (data) {
console.log(data);
});
inEndpoint.on('error', function (error) {
console.log(error);
});
outEndpoint.transferType = 2;
outEndpoint.startStream(1, 64);
outEndpoint.transfer(new Buffer('d\n'), function (err) {
console.log(err);
});
//ep_out.transfer(' ', function(err) {
//if(err) {
//console.log(err);
//}
//else {
//console.log('success');
//}
//});
//
//var data = new Buffer('100300', 'hex');
//
//interf.write(data)
//
//interf.transfer(10, function(err, data) {
//console.log(data);
//});
//
//my_drive.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment