【问题标题】:Node smartcard throw SCardConnect error while scanning the card and SCardListReaders error after disconnect节点智能卡在扫描卡时抛出 SCardConnect 错误,在断开连接后抛出 SCardListReaders 错误
【发布时间】:2017-04-03 12:27:03
【问题描述】:

我也在使用角度和电子,但以前一切正常。这是错误:

Error: SCardConnect error: 
SCardConnect error: The smart card cannot be accessed because of other connections outstanding.
(0x8010000b)

第一次扫描卡片后,它不再抛出错误并且可以正常读取卡片,直到重新启动。以下是我的一些与智能卡相关的代码的 sn-ps:

const smartcard = require('smartcard');
const Devices = smartcard.Devices;
const devices = new Devices();
let currentDevices = [];

//something else

app.run(function($rootScope) {
let registerDevices = function (event) {
    currentDevices = event.devices;
    currentDevices.forEach(function (device) {
        device.on('card-inserted', event => {
            let card = event.card;
            console.log(`Card '${card.getAtr()}' inserted into '${card.device}'`);
            $rootScope.$broadcast('card-attach',card.getAtr());
        });
        device.on('card-removed', event => {
        });
        device.on('error', event => {
            console.error("Card Reader Error: " + event);
        });
    });
};

devices.on('device-activated', event => {
    console.log("Reader added :" + event.device);
    registerDevices(event);
});

devices.on('device-deactivated', event => {
    console.log("Reader removed :" + event.device);
    registerDevices(event);
});
});

此外,当我断开扫描仪时,它会说

events.js:160 Uncaught Error: SCardListReaders error: The Smart Card Resource Manager is not running.
(0x8010001d)

events.js:163 Uncaught Error: Uncaught, unspecified "error" event. ([object Object])

重新连接后扫描仪不工作。

【问题讨论】:

    标签: javascript angularjs node.js electron smartcard


    【解决方案1】:

    这个错误代码是E_SHARING_VIOLATION——一些进程已经以独占模式连接到卡(使用SCARD_SHARE_EXCLUSIVE代替SCardConnect)。


    [假设你在Windows下]:

    Windows 中有一个Plug&Play 机制,默认情况下会在插入后立即自动访问每张卡并尝试为其确定正确的驱动程序——这会在访问卡时创建一个短时间窗口(恕我直言,这是最可能的原因)。

    你有两个选择:

    1. 处理它 -- 一段时间后(数十毫秒,YMMV)重试此特定错误代码的卡连接尝试(可能可以在循环中完成一些最大重试次数)。

    2. 禁用此行为 -- 有两种方法(我从未使用过组策略之一,但应该可以):

      a/ 使用本地组策略设置(禁用计算机配置 -> 管理模板 -> Windows 组件 -> 智能卡 -> 打开智能卡即插即用服务)(参见例如here

      b/ 通过将HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\ScPnP 下的注册表项EnableScPnP 设置为dword:0x00000000(对于64 位系统,也将其设置在HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\ScPnP 下)——参见例如here。请务必重新启动系统以使更改生效


    关于您对 0x8010001D (E_NO_SERVICE) 错误代码的编辑并重新连接阅读器 -- 我不知道。

    祝你好运!

    【讨论】:

    • 我更改了注册表并重新启动,它第一次工作。但是,在我重新启动应用程序后,再次发生相同的错误...
    猜你喜欢
    • 2018-03-18
    • 2022-01-24
    • 2011-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-06
    • 1970-01-01
    相关资源
    最近更新 更多