Ejemplo n.º 1
0
        /// <summary>
        /// The WaitForCardRemoval function blocks execution until there is no card in the reader.
        /// </summary>
        /// <param name="szReader">
        /// The name of the reader that contains the target card.
        /// </param>
        public void WaitForCardRemoval(string szReader)
        {
            int ret;

            SCARD_READERSTATE[] readerStates = new SCARD_READERSTATE[1];
            readerStates[0].m_szReader       = szReader;
            readerStates[0].m_dwEventState   = (uint)SCARD_CARD_STATE.UNAWARE;
            readerStates[0].m_dwCurrentState = (uint)SCARD_CARD_STATE.UNAWARE;

            ret = WinSCardAPIWrapper.SCardGetStatusChange(phContext, (uint)10, readerStates, (uint)1);
            if (ret != 0)
            {
                throw new WinSCardException(scardTrace, "SCard.Connect", ret);
            }

            if ((readerStates[0].m_dwEventState & (uint)SCARD_CARD_STATE.EMPTY) == (uint)SCARD_CARD_STATE.EMPTY)
            {
                return;
            }
            Trace.WriteLineIf(this.TraceSCard, "    Wait for card removal...");

            do
            {
                ret = WinSCardAPIWrapper.SCardGetStatusChange(phContext, (uint)10, readerStates, (uint)1);
                if (ret != 0)
                {
                    throw new WinSCardException(scardTrace, "SCard.Connect", ret);
                }
            } while ((readerStates[0].m_dwEventState & (uint)SCARD_CARD_STATE.EMPTY) != (uint)SCARD_CARD_STATE.EMPTY);
        }
Ejemplo n.º 2
0
        // blocks until someone scans their card
        public void WaitForCardPresent(string szReader)
        {
            int ret;

            SCARD_READERSTATE[] readerStates = new SCARD_READERSTATE[1];
            readerStates[0].m_szReader       = szReader;
            readerStates[0].m_dwEventState   = (uint)SCARD_CARD_STATE.UNAWARE;
            readerStates[0].m_dwCurrentState = (uint)SCARD_CARD_STATE.UNAWARE;

            ret = WinSCardAPIWrapper.SCardGetStatusChange(phContext, (uint)10, readerStates, (uint)1);
            if (ret != 0)
            {
                throw new WinSCardException(scardTrace, "SCard.Connect", ret);
            }

            if ((readerStates[0].m_dwEventState & (uint)SCARD_CARD_STATE.PRESENT) == (uint)SCARD_CARD_STATE.PRESENT)
            {
                return;
            }
            Trace.WriteLineIf(this.TraceSCard, "    Wait for card present...");

            do
            {
                ret = WinSCardAPIWrapper.SCardGetStatusChange(phContext, (uint)10, readerStates, (uint)1);

                if (ret != 0)
                {
                    throw new WinSCardException(scardTrace, "SCard.Connect", ret);
                }

                //this is our event loop to simulate what would be an action listener
            } while ((readerStates[0].m_dwEventState & (uint)SCARD_CARD_STATE.PRESENT) != (uint)SCARD_CARD_STATE.PRESENT);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a value indicating whether smart card is present.
        /// </summary>
        /// <param name="szReader">
        /// The name of the reader that contains the target card.
        /// </param>
        /// <value><c>true</c> if [card activated]; otherwise, <c>false</c>.</value>
        public bool GetCardPresentState(string szReader)
        {
            int ret;

            SCARD_READERSTATE[] readerStates = new SCARD_READERSTATE[1];
            readerStates[0].m_szReader       = szReader;
            readerStates[0].m_dwEventState   = (uint)SCARD_CARD_STATE.UNAWARE;
            readerStates[0].m_dwCurrentState = (uint)SCARD_CARD_STATE.UNAWARE;

            ret = WinSCardAPIWrapper.SCardGetStatusChange(phContext, (uint)100, readerStates, (uint)1);
            if (ret != 0)
            {
                throw new WinSCardException(scardTrace, "SCard.Connect", ret);
            }

            if ((readerStates[0].m_dwEventState & (uint)SCARD_CARD_STATE.PRESENT) == (uint)SCARD_CARD_STATE.PRESENT)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
        // The WaitForCardRemoval function blocks execution until there is no card
        // present in the previous selected the selected reader.
        //waits until there is no more card in the specified reader
        public void WaitForCardRemoval(string szReader)
        {
            int ret;

            SCARD_READERSTATE[] readerStates = new SCARD_READERSTATE[1];
            readerStates[0].m_szReader = szReader;
            readerStates[0].m_dwEventState = (uint)SCARD_CARD_STATE.UNAWARE;
            readerStates[0].m_dwCurrentState = (uint)SCARD_CARD_STATE.UNAWARE;

            ret = WinSCardAPIWrapper.SCardGetStatusChange(phContext, (uint)10, readerStates, (uint)1);
            if (ret != 0) throw new WinSCardException(scardTrace, "SCard.Connect", ret);

            if ((readerStates[0].m_dwEventState & (uint)SCARD_CARD_STATE.EMPTY) == (uint)SCARD_CARD_STATE.EMPTY)
            {
                return;
            }
            Trace.WriteLineIf(this.TraceSCard, "    Wait for card removal...");

            do
            {
                ret = WinSCardAPIWrapper.SCardGetStatusChange(phContext, (uint)10, readerStates, (uint)1);
                if (ret != 0) throw new WinSCardException(scardTrace, "SCard.Connect", ret);
                //this is our event loop to simulate what would be an action listener
            } while ((readerStates[0].m_dwEventState & (uint)SCARD_CARD_STATE.EMPTY) != (uint)SCARD_CARD_STATE.EMPTY);
        }
Ejemplo n.º 5
0
        //gets the present state of the card reader specifyed
        public bool GetCardPresentState(string szReader)
        {
            int ret;

            SCARD_READERSTATE[] readerStates = new SCARD_READERSTATE[1];
            readerStates[0].m_szReader = szReader;
            readerStates[0].m_dwEventState = (uint)SCARD_CARD_STATE.UNAWARE;
            readerStates[0].m_dwCurrentState = (uint)SCARD_CARD_STATE.UNAWARE;

            ret = WinSCardAPIWrapper.SCardGetStatusChange(phContext, (uint)100, readerStates, (uint)1);
            if (ret != 0) throw new WinSCardException(scardTrace, "SCard.Connect", ret);

            if ((readerStates[0].m_dwEventState & (uint)SCARD_CARD_STATE.PRESENT) == (uint)SCARD_CARD_STATE.PRESENT)
            {
                return true;
            }
            else
            {
                return false;
            }
        }