From 44b0c3e47992e2cbbe11785638010385b4733e02 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Wed, 24 Sep 2014 16:15:11 +0200 Subject: [PATCH] example: connect with SHARED share_mode - This way the example works both in Linux and OS X. See: https://github.com/santigimeno/node-pcsclite/issues/14#issuecomment-56665208 --- README.md | 15 +++++++-------- examples/example.js | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c3f1b26..4ab7b8b 100644 --- a/README.md +++ b/README.md @@ -33,11 +33,14 @@ To run any code you will also need to have installed the pcsc daemon: var pcsc = require('pcsclite'); var pcsc = pcsc(); -/* Check for new card reader detection */ pcsc.on('reader', function(reader) { + console.log('New reader detected', reader.name); - /* Check for reader status changes such a new card insertion */ + reader.on('error', function(err) { + console.log('Error(', this.name, '):', err.message); + }); + reader.on('status', function(status) { console.log('Status(', this.name, '):', status); /* check what has changed */ @@ -54,11 +57,11 @@ pcsc.on('reader', function(reader) { }); } else if ((changes & this.SCARD_STATE_PRESENT) && (status.state & this.SCARD_STATE_PRESENT)) { console.log("card inserted");/* card inserted */ - reader.connect(function(err, protocol) { + reader.connect({ share_mode : this.SCARD_SHARE_SHARED }, function(err, protocol) { if (err) { console.log(err); } else { - console.log('Protocol(', this.name, '):', protocol); + console.log('Protocol(', reader.name, '):', protocol); reader.transmit(new Buffer([0x00, 0xB0, 0x00, 0x00, 0x20]), 40, protocol, function(err, data) { if (err) { console.log(err); @@ -75,10 +78,6 @@ pcsc.on('reader', function(reader) { reader.on('end', function() { console.log('Reader', this.name, 'removed'); }); - - reader.on('error', function(err) { - console.log('Error(', this.name, '):', err.message); - }); }); pcsc.on('error', function(err) { diff --git a/examples/example.js b/examples/example.js index 5bcb53e..c731ee3 100644 --- a/examples/example.js +++ b/examples/example.js @@ -25,7 +25,7 @@ pcsc.on('reader', function(reader) { }); } else if ((changes & this.SCARD_STATE_PRESENT) && (status.state & this.SCARD_STATE_PRESENT)) { console.log("card inserted");/* card inserted */ - reader.connect(function(err, protocol) { + reader.connect({ share_mode : this.SCARD_SHARE_SHARED }, function(err, protocol) { if (err) { console.log(err); } else {