Changeset 16493


Ignore:
Timestamp:
Aug 5, 2016, 4:03:10 PM (3 years ago)
Author:
dcorreia
Message:

Added functions to check if reader is connected and card is inserted.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • internals/2016/linuxloginsmartcardwizard/trunk/proto1/cardHelper.py

    r16484 r16493  
    99def init():
    1010    # First of all you always have to initialize the sdk.
    11     print("CC sdk example, starting...")
    1211    pteid.PTEID_ReaderSet.initSDK()
    1312
    1413
    1514def release():
    16     print("CC sdk example, releasing resources...")
    1715    # At the end, always release the sdk
    1816    pteid.PTEID_ReaderSet.releaseSDK()
     17
     18
     19def hasReaderConnected():
     20    init()
     21    # Obtain the instance of readerSet
     22    readers = pteid.PTEID_ReaderSet.instance()
     23    count = readers.readerCount()
     24    release()
     25    return count > 0
     26
     27
     28def hasCardInserted():
     29    init()
     30    # Obtain the instance of readerSet
     31    readers = pteid.PTEID_ReaderSet.instance()
     32    count = readers.readerCount()
     33    if count:
     34        devices_names = []
     35        # Obtain the names of all connected readers
     36        for idx in range(count):
     37            name = readers.getReaderName(idx)
     38            devices_names.append(name)
     39
     40        ctx_with_card = None
     41        # try to find a smart card in one of the detected readers
     42        for name in devices_names:
     43            reader_ctx = readers.getReaderByName(name)
     44
     45            if reader_ctx.isCardPresent():
     46                ctx_with_card = reader_ctx
     47                # found a card connected, don't look around in other readers
     48                break
     49        release()
     50        return ctx_with_card is not None
    1951
    2052
     
    2254    # Obtain the instance of readerSet
    2355    readers = pteid.PTEID_ReaderSet.instance()
    24 
    2556    count = readers.readerCount()
    26     print("Number of connected card readers to the system:", count)
    2757
    2858    # Check if we have connected smart card readers
     
    3262        # Obtain the names of all connected readers
    3363        for idx in range(count):
    34             print("Obtaining card name for index:", idx)
    35 
    3664            name = readers.getReaderName(idx)
    3765            devices_names.append(name)
    38 
    3966            print("Connected device:", name)
    4067
     
    4572
    4673            if reader_ctx.isCardPresent():
    47                 print("The reader <", name, "> has a card in it.")
    48 
    4974                ctx_with_card = reader_ctx
    5075                # found a card connected, don't look around in other readers
Note: See TracChangeset for help on using the changeset viewer.