循环等待卡片,每当有卡片插入时,获取并打印其ATR,通过 input 提示用户操作完成以及提示正在等待插入卡片
from smartcard.CardRequest import CardRequest
from smartcard.util import toHexString, toBytes
cardrequest = CardRequest(timeout=60) # 等待插入卡片的时长为60秒,超时则抛异常
while True:
cardservice = cardrequest.waitforcard()
cardservice.connection.connect()
print(toHexString(cardservice.connection.getATR()))
input("操作完成
正在等待插入卡片")
循环等待特定ATR的卡片,每当有对应ATR的卡片插入时,获取并打印其ATR,通过 input 提示用户操作完成以及提示正在等待插入卡片
from smartcard.CardRequest import CardRequest
from smartcard.util import toHexString, toBytes
cardtype = ATRCardType(toBytes("3B 16 94 20 02 01 00 00 0D"))
cardrequest = CardRequest(timeout=1, cardType=cardtype)
while True:
cardservice = cardrequest.waitforcard()
cardservice.connection.connect()
print(toHexString(cardservice.connection.getATR()))
input("操作完成
正在等待插入卡片")