Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyscard - windows - How to re-open connection to a smartcard (open/close/open again)

On windows 8.1, Python 2.7, pyscard(latest) i list readers from my software like so:

for reader in readers():
        print "list of readers:"
        print readers
        try:
            conn = reader.createConnection()
            conn.connect()

            data, status = _cmd2(conn, 0, 0xa4, 0x04, 0x00, 'appletID'.decode('hex'))

Now, when i remove the smart card and plug it back in and try to open the connection again with the same software (i didnt closed the software meanwhile) i get this error:

> 'Failure to list readers: The Smart Card Resource Manager has shut
> down. '

If instead I close the software and re-list readers and open the connection everything works fine.

Apparently Windows does something if the smart-card is removed and re-inserted that prevents to establish a new connection.

Anyone can show me the way of the Ninja? Thank you.

like image 556
NoobTom Avatar asked Nov 23 '22 11:11

NoobTom


1 Answers

In PySCard 2.0.3 (March 2022) I fixed a problem that the PC/SC resource manager was shutdown by Windows when the last reader (not smart card) is removed.

You may want to try a newer version of PySCard.

like image 143
Ludovic Rousseau Avatar answered Nov 29 '22 05:11

Ludovic Rousseau