Created
October 8, 2012 16:43
-
-
Save flexd/3853512 to your computer and use it in GitHub Desktop.
This file contains 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 spawn = require('child_process').spawn, | |
ls = spawn('pcsc_scan', []); | |
var util = require('util'); | |
var atrfound = false; | |
console.log("pcsc_scan should be running now"); | |
ls.stdout.on('data', function (data) { | |
//console.log('stdout: ' + data); | |
var data = data.toString(); | |
data = data.replace(/\u001b\[\d{0,2}m/g, ''); // Remove ANSI colors. | |
var state = /Card state: Card (.+),/.exec(data); | |
if (state) { | |
state = state[1]; | |
if (state == "inserted") { | |
} | |
if (state == "removed") { | |
atrfound = false; | |
} | |
console.log("Card state is: " + state); | |
} | |
// lets try to read a UID. | |
var atr = /ATR: (.+)/.exec(data); | |
if (atr && !atrfound) { | |
atr = atr[1]; | |
atrfound = true; | |
console.log("ATR: " + atr); | |
} | |
}); | |
ls.stderr.on('data', function (data) { | |
//console.log('stderr: ' + data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment