[Pcsclite-muscle] How to dectect card status?
Ludovic Rousseau
ludovic.rousseau at gmail.com
Sat Jun 27 04:38:15 EDT 2020
Le sam. 27 juin 2020 à 09:56, Carlos Almeida Jr. <almeidajr at gmail.com> a écrit :
>
> Hello!
Hello Carlos
> I'm developing an application that needs to detect when a card is
> removed from the reader.
>
> I tried to use:
>
> // fragment #1
> m_readerState = new SCARD_READERSTATE[1];
> m_readerState->szReader = m_readerModel;
> SCardGetStatusChange(m_cardContext, 100000000, m_readerState, 1);
> qDebug() << ">> Reader status" << m_readerState->dwCurrentState;
>
> if(l_readerStatus == SCARD_STATE_PRESENT) {
> qDebug() << "card still present";
> } else {
> qDebug() << "card not present";
> }
> // ---
> // >> m_readerState->dwCurrentState always returns something like 94893093710928
>
> or
> // fragment #2
> m_readerState = new SCARD_READERSTATE[1];
> m_readerState->szReader = m_readerModel; // or "\\\\?PnP?\\Notification";
> m_readerState->cbAtr = 0;
> m_readerState->dwCurrentState = 0;
> m_readerState->dwEventState = 0;
> while(true) {
> SCardGetStatusChange(m_cardContext, 500, m_readerState, 1);
> qDebug() << ">> Reader status" << m_readerState->dwCurrentState <<
> " --- " << SCARD_STATE_PRESENT;
> }
> // ---
>
>
> // >> m_readerState->dwCurrentState always returns 0
>
> m_cardContext and m_readerState are correctly defined and I'm able to
> read cards but not to identify when it is disconnected.
>
> Someone can help me?
The missing part is:
m_readerState[0].dwCurrentState = SCARD_STATE_UNAWARE
See https://ludovicrousseau.blogspot.com/2020/03/wait-for-card-state-change.html
Bye
--
Dr. Ludovic Rousseau
More information about the pcsclite-muscle
mailing list