首页 > 解决方案 > 在 ACR1252U NFC 读卡器上强制 PC/SC 驱动程序并使用 python 进入卡仿真模式

问题描述

目的:让ACR1252U NFC读卡器在Mac上使用python进入卡模拟模式

我在使用 PC/SC 驱动程序的 macOS Catalina 10.15.3 上使用 ACS ACR1252U 读卡器时遇到问题。我从ACS 网站安装了驱动程序。

通过使用 pyscard ( http://pyscard.sourceforge.net/ ) 库,以下 python 代码工作并在windows计算机上返回正确的输入卡模拟模式响应: 输入卡模拟模式命令和响应格式

import smartcard

hresult, hcontext = smartcard.scard.SCardEstablishContext( smartcard.scard.SCARD_SCOPE_USER )

hresult, readers = smartcard.scard.SCardListReaders( hcontext, [] )
print(readers)

hresult, hcard, dwActiveProtocol = smartcard.scard.SCardConnect(hcontext, readers[0], smartcard.scard.SCARD_SHARE_DIRECT, 0)

CTL_CODE = smartcard.scard.SCARD_CTL_CODE(3500)

apdu = [0xE0, 0x00, 0x00, 0x40, 0x03, 0x01, 0x00, 0x00]

hresult, response = smartcard.scard.SCardControl( hcard, CTL_CODE, apdu )

但它在 Mac 上给出了错误。我按照这个答案来更改 plist 文件,但我仍然得到同样的错误:

python3 nfc.py
['ACS ACR1252 1S CL Reader(1)', 'ACS ACR1252 1S CL Reader(2)']
Traceback (most recent call last):
  File "nfc.py", line 17, in <module>
    hresult, response = smartcard.scard.SCardControl( hcard, CTL_CODE, apdu )
  File "/usr/local/lib/python3.7/site-packages/smartcard/scard/scard.py", line 408, in SCardControl
    return _scard.SCardControl(hcard, dwControlCode, inbuffer)
SystemError: <built-in function SCardControl> returned NULL without setting an error

我使用自制软件安装了 libnfc,但我不确定如何根据答案的第二部分来编译它。

任何帮助将不胜感激。

标签: pythonnfcmacos-catalinapcsclib-nfc

解决方案


推荐阅读