Skip to content

Instantly share code, notes, and snippets.

@tpdn
Created January 27, 2014 03:47
Show Gist options
  • Save tpdn/8642985 to your computer and use it in GitHub Desktop.
Save tpdn/8642985 to your computer and use it in GitHub Desktop.
winscard sample
# -*- coding: utf-8 -*-
import winscard
from ctypes import *
import time
import sys
user32 = windll.user32
sc = winscard.SCard()
reader = sc.list_readers()[0]
while(True):
while(True):
try:
reader.connect()
c = False
break
except winscard.WinSCardError as e:
if e.errno == winscard.SCARD_W_REMOVED_CARD:
time.sleep(0.1)
else:
print e
sys.exit(1)
cardid = reader.transmit((0xFF, 0xCA, 0x00, 0x00, 0x00), winscard.SCARD_PCI_T1)
reader.disconnect()
print [hex(x) for x in cardid]
txt = "".join([str.format('{0:02X}',x) for x in cardid])
user32.MessageBoxA(
0,
txt,
"your card id",
0x00000040)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment