Closed leileigong closed 5 years ago
this problem trap on win10 , but work fine on win7 `def getReaderNames(self): """Returns the list or PCSC readers on which to wait for cards."""
# get inserted readers
hresult, pcscreaders = SCardListReaders(self.hcontext, [])
if 0 != hresult and SCARD_E_NO_READERS_AVAILABLE != hresult:
raise ListReadersException(hresult)`
i use SCardGetErrorMessage print error message:
SCardGetErrorMessage(hresult).decode('gbk').encode('utf8')
the error mssage is "smartcard resource manager is closed"("智能卡资源管理器已关闭") . I guess this may be a bug of pyscard on win10.
-2146435042L is 0x8010001E and is SCARD_E_SERVICE_STOPPED
What should be the expected behaviour for you?
After i plug in a device, the pyscard service should not stop.
PySCard does not stop, but raises an exception.
When a reader is plugged IN no exception is raised. My question is what should happen when a reader is plugged OUT.
When a reader is plugged OUT, ScardListReader methord should not raise an exception.But now it raises SCARD_E_SERVICE_STOPPED
The exception SCARD_E_SERVICE_STOPPED
is not raised by SCardListReaders()
but by getReaderNames()
https://github.com/LudovicRousseau/pyscard/blob/master/smartcard/pcsc/PCSCCardRequest.py#L84
getReaderNames()
returns a list of reader(s). The only way for it to return an error is by throwing an exception.
What should getReaderNames()
do instead?
After reader is pluged OUT, the windows smartcard service does not really stop, so getReaderNames() should not raise an exception, it should return a list of reader(s).
I don't know if PC/SC manager really stopped or not. But SCardListReaders()
returned SCARD_E_SERVICE_STOPPED
. I don't think PySCard should just ignore this error code.
Do you get the error/exception if you have 2 reader connected and disconnect one, or only when you disconnect the last reader?
i just have one reader contected, if it is plugged OUT, SCardListReaders() should not return an error but return an empty list .
I got an new tip. If you have 2 reader connected and disconnect one, i do not get an error/exception. But if disconnect the last reader, then SCardListReaders() returned SCARD_E_SERVICE_STOPPED.
I expected this behaviour with 2 readers.
I propose you to:
OK,thanks,you help a lot.
I use pyscard-1.9.17, but i got an problem which is similar to several. 1)Exception ListReadersException raised after disconnecting PCSC reader #13 2)Stop CardMonitor monitor thread after traceback print. #22
I guess that #13 #22 do not fixed the problem.
Here is my traceback info:
Traceback (most recent call last): File "C:\Users\lei.virtualenvs\TestTool-gkAj8wo0\lib\site-packages\smartcard\CardMonitoring.py", line 162, in run currentcards = self.cardrequest.waitforcardevent() File "C:\Users\lei.virtualenvs\TestTool-gkAj8wo0\lib\site-packages\smartcard\CardRequest.py", line 73, in waitforcardevent return self.pcsccardrequest.waitforcardevent() File "C:\Users\lei.virtualenvs\TestTool-gkAj8wo0\lib\site-packages\smartcard\pcsc\PCSCCardRequest.py", line 288, in waitforcardevent readernames = self.getReaderNames() File "C:\Users\lei.virtualenvs\TestTool-gkAj8wo0\lib\site-packages\smartcard\pcsc\PCSCCardRequest.py", line 90, in getReaderNames raise ListReadersException(hresult) ListReadersException: ('Failed to list readers', -2146435042L)