AutoIt
AutoIt
PC/SC Get Card UID
See more SCard Examples
Sends the APDU command to get a card's UID.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oScard = ObjCreate("Chilkat.SCard")
; First establish a context to the PC/SC Resource Manager
$bSuccess = $oScard.EstablishContext("user")
If ($bSuccess = False) Then
ConsoleWrite($oScard.LastErrorText & @CRLF)
Exit
EndIf
; Use your own smart card reader name here.
$bSuccess = $oScard.Connect("ACS ACR122 0","shared","no_preference")
If ($bSuccess = False) Then
ConsoleWrite($oScard.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Connected reader: " & $oScard.ConnectedReader & @CRLF)
ConsoleWrite("Active protocol: " & $oScard.ActiveProtocol & @CRLF)
ConsoleWrite("ATR: " & $oScard.CardAtr & @CRLF)
ConsoleWrite("Reader Status: " & $oScard.ReaderStatus & @CRLF)
; Send the APDU command 0xFF, 0xCA, 0x00, 0x00, 0x00
$oBdRecv = ObjCreate("Chilkat.BinData")
$bSuccess = $oScard.TransmitHex($oScard.ActiveProtocol,"FFCA000000",$oBdRecv,32)
If ($bSuccess = True) Then
ConsoleWrite("Received: " & $oBdRecv.GetEncoded("hex") & @CRLF)
; The UID is the returned data without the final 2 bytes.
Local $iNumBytes = $oBdRecv.NumBytes
If ($iNumBytes > 2) Then
ConsoleWrite("UID: " & $oBdRecv.GetEncodedChunk(0,$iNumBytes - 2,"hex") & @CRLF)
EndIf
Else
ConsoleWrite($oScard.LastErrorText & @CRLF)
EndIf
; Disconnect from this reader.
$bSuccess = $oScard.Disconnect("leave")
If ($bSuccess = False) Then
ConsoleWrite($oScard.LastErrorText & @CRLF)
EndIf
; Applications should always release the context when finished.
$bSuccess = $oScard.ReleaseContext()
If ($bSuccess = False) Then
ConsoleWrite($oScard.LastErrorText & @CRLF)
EndIf