我想知道是否有办法在 python 中轮询 ACR122U,如果有,怎么做?我下面的脚本获取卡的 UID,但不断运行。我知道它是因为 while1而运行,但它显示了我想要实现的目标
from smartcard.scard import *
from smartcard.util import toHexString
def s():
while 1:
hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)
assert hresult==SCARD_S_SUCCESS
hresult, readers = SCardListReaders(hcontext, [])
assert len(readers)>0
reader = readers[0]
hresult, hcard, dwActiveProtocol = SCardConnect(
hcontext,
reader,
SCARD_SHARE_SHARED,
SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1)
try:
hresult, response = SCardTransmit(hcard,dwActiveProtocol,[0xFF,0xCA,0x00,0x00,0x04])
uid = toHexString(response, format=0)
print uid
except SystemError:
print "no card found"
s()