Visual FoxPro
Visual FoxPro
PC/SC Check the Status of each Smart Card Reader (and USB token)
See more SCard Examples
Demonstrates how to list the smart card readers and USB tokens connected to the computer, and check the status of each.Note: This functionality was introduced in Chilkat v9.5.0.87.
Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loScard
LOCAL loStReaders
LOCAL lnNumReaders
LOCAL i
LOCAL lcReader
lnSuccess = 0
* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loScard = CreateObject('Chilkat.SCard')
* First establish a context to the PC/SC Resource Manager
lnSuccess = loScard.EstablishContext("user")
IF (lnSuccess = 0) THEN
? loScard.LastErrorText
RELEASE loScard
CANCEL
ENDIF
loStReaders = CreateObject('Chilkat.StringTable')
lnSuccess = loScard.ListReaders(loStReaders)
IF (lnSuccess = 0) THEN
? loScard.LastErrorText
RELEASE loScard
RELEASE loStReaders
CANCEL
ENDIF
lnNumReaders = loStReaders.Count
i = 0
DO WHILE i < lnNumReaders
lcReader = loStReaders.StringAt(i)
? STR(i) + ": " + lcReader
* Connect to this reader.
IF (loScard.Connect(lcReader,"shared","no_preference") = 1) THEN
* Check the status to get the reader state, active protocol, and card ATR (if a card is inserted).
IF (loScard.CheckStatus() = 1) THEN
? "ReaderStatus: " + loScard.ReaderStatus
? "CardAtr: " + loScard.CardAtr
? "ActiveProtocol: " + loScard.ActiveProtocol
ELSE
? loScard.LastErrorText
? "CheckStatus failed."
ENDIF
* Disconnect from this reader.
lnSuccess = loScard.Disconnect("leave")
ELSE
? loScard.LastErrorText
? "Connect failed."
ENDIF
? "---------------------------------------"
i = i + 1
ENDDO
* Sample output:
* 0: Alcor Micro USB Smart Card Reader 0
* ReaderStatus: specific
* CardAtr: 3B7F96000080318065B0855956FB120FFE829000
* ActiveProtocol: T0
* ---------------------------------------
* 1: Generic Smart Card Reader Interface 0
* ReaderStatus: specific
* CardAtr: 3BFC180000813180459067464A00641606F2727E00E0
* ActiveProtocol: T1
* ---------------------------------------
* 2: SCM Microsystems Inc. SCR33x USB Smart Card Reader 0
* ReaderStatus: specific
* CardAtr: 3BDF96FF8131FE455A018048494443313158587300011B09
* ActiveProtocol: T1
* ---------------------------------------
* Applications should always release the context when finished.
lnSuccess = loScard.ReleaseContext()
IF (lnSuccess = 0) THEN
? loScard.LastErrorText
ENDIF
RELEASE loScard
RELEASE loStReaders