Пример #1
1
        public static void Main()
        {
            using (var ctx = new SCardContext()) {
                ctx.Establish(SCardScope.System);

                var readerNames = ctx.GetReaders();
                var readerStates = ctx.GetReaderStatus(readerNames);

                foreach (var state in readerStates) {
                    Console.WriteLine(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                    Console.WriteLine("Reader: {0}\n" +
                        "CurrentState: {1}\n" +
                        "EventState: {2}\n" +
                        "CurrentStateValue: {3}\n" +
                        "EventStateValue: {4}\n" +
                        "UserData: {5}\n" +
                        "CardChangeEventCnt: {6}\n" +
                        "ATR: {7}",

                        state.ReaderName,
                        state.CurrentState,
                        state.EventState,
                        state.CurrentStateValue,
                        state.EventStateValue,
                        state.UserData,
                        state.CardChangeEventCnt,
                        BitConverter.ToString(state.Atr ?? new byte[0]));

                    state.Dispose();
                }

                ctx.Release();
            }
            Console.ReadKey();
        }
Пример #2
0
        public string GetReaderStatus()
        {
            SCardContext context = new SCardContext();
            context.Establish(SCardScope.System);

            if (context.GetReaders().All(r => r != _connectedReader)) // Check to see if the context has _connectedReader as a reader before we use it.
            {
                context.Dispose();
                return string.Format("{0} cannot be found in the list of connected readers", _connectedReader);
            }

            var state = context.GetReaderStatus(_connectedReader);

            if (state == null)
            {
                context.Dispose();
                return string.Format("Cannot get the reader status of {0}.", _connectedReader);
            }

            context.Dispose();

            return string.Format("Name: {1}{0}Current State: {2}{0}Event State: {3}{0}" +
                                 "Current State Value: {4}{0}Event State Value: {5}{0}" +
                                 "User Data: {6}{0}Card Change Event Count: {7}{0}" +
                                 "ATR: {8}{0}", Environment.NewLine, state.ReaderName, state.CurrentState,
                                 state.EventState, state.CurrentStateValue, state.EventStateValue, state.UserData,
                                 state.CardChangeEventCnt, state.Atr.Length == 0 ? "0" : BitConverter.ToString(state.Atr));
        }
Пример #3
0
        static void Main(string[] args)
        {
            // Retrieve the names of all installed readers.
            SCardContext ctx = new SCardContext();
            ctx.Establish(SCardScope.System);
            string[] readernames = ctx.GetReaders();

            /* Get the current status of each reader in "readernames".
             */
            SCardReaderState[] states = ctx.GetReaderStatus(readernames);

            foreach (SCardReaderState state in states)
            {
                Console.WriteLine(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                Console.WriteLine("Reader: " + state.ReaderName);
                Console.WriteLine("CurrentState: " + state.CurrentState
                    + " EventState: " + state.EventState + "\n"
                    + "CurrentStateValue: " + state.CurrentStateValue
                    + " EventStateValue: " + state.EventStateValue);
                Console.WriteLine("UserData: " + state.UserData.ToString()
                    + " CardChangeEventCnt: " + state.CardChangeEventCnt);
                Console.WriteLine("ATR: " + StringAtr(state.ATR));
            }

            ctx.Release();
            return;
        }