예제 #1
0
        static void Initialized(object sender, CardStatusEventArgs args)
        {
            SCardMonitor monitor = (SCardMonitor)sender;

            Console.WriteLine(">> Initialized Event for reader: "
                + args.ReaderName);
            Console.WriteLine("   ATR: " + StringAtr(args.Atr));
            Console.WriteLine("   State: " + args.State + "\n");
        }
 private void CardEvent(object sender, CardStatusEventArgs args)
 {
   if (this.Dispatcher.CheckAccess())
   {
     UpdateDataGrid();
   }
   else
   {
     this.Dispatcher.Invoke((Action)(() =>
     {
       UpdateDataGrid();
     }));
   }
 }
예제 #3
0
 private void _cardRemoved(object sender, CardStatusEventArgs e)
 {
 }
예제 #4
0
 private void _cardInserted(object sender, CardStatusEventArgs e)
 {
     ReadCard();
 }
예제 #5
0
        private void _cardInitalised(object sender, CardStatusEventArgs e)
        {
            string temp_message = string.Empty;

            if (string.IsNullOrEmpty(_connectedReader) || _monitor == null) return;
            if (_monitor.Monitoring)
            {
                _monitoredReaders = _monitor.ReaderNames;
                string monitoredReaders = _monitor.ReaderNames.Aggregate(string.Empty, (current, reader) => current + " " + reader);
                temp_message = string.Format("Now monitoring {0}", monitoredReaders);
                // TODO: Update the UI
            }
            else
            {
                temp_message = "Not monitoring any card readers, won't detect that a new card is inserted.";
            }
        }
예제 #6
0
        /// <summary>
        ///     Invoked when a new card was inserted into the reader
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        protected void CardInserted( object sender, CardStatusEventArgs args )
        {
            Log.Info( "Card detected." );
            try {
                byte[] uid = UidFromConnectedCard( args.ReaderName );

                // We only care about the first 4 bytes
                byte[] shortUid = new byte[4];
                Array.Copy( uid, shortUid, 4 );
                string uidString = BitConverter.ToString( shortUid ).Replace( "-", string.Empty );
                Log.InfoFormat( "Read UID '{0}' from '{1}'.", uidString, args.ReaderName );
                BroadcastUidEvent( shortUid );
            } catch( Exception ex ) {
                Log.Error( ex.Message );
                BroadcastErrorEvent( new byte[] {0} );
            }
        }
예제 #7
0
 private static void DisplayEvent(string eventName, CardStatusEventArgs unknown) {
     Console.WriteLine(">> {0} Event for reader: {1}", eventName, unknown.ReaderName);
     Console.WriteLine("ATR: {0}", BitConverter.ToString(unknown.Atr ?? new byte[0]));
     Console.WriteLine("State: {0}\n", unknown.State);
 }
예제 #8
0
 private void ReaderInitializedEvent(CardStatusEventArgs args)
 {
     Debug.WriteLine("Reader {0} initialized", args.ReaderName);
 }
예제 #9
0
        private void CardInsertedEvent(CardStatusEventArgs args)
        {
            int readerId = -1;
            for (int i = 0; i < readerNames.Length; i++)
            {
                if(readerNames[i].Equals(args.ReaderName)){
                    readerId = i;
                    break;
                }
            }
            if(readerId < 0) return;

            NdefMessage message = GetNdefMessage(args.ReaderName);

            if(message != null){
                _newNdefMessageDetected(message, readerId);
            }
        }
예제 #10
0
        private void OnInitialized(byte[] atr, string readerName, SCRState initState)
        {
            var handler = Initialized;

            if (handler == null) {
                return;
            }

            var args = new CardStatusEventArgs(
                readerName,
                initState,
                atr);

            handler(this, args);
        }
예제 #11
0
        private void OnCardRemoved(byte[] atr, string readerName, SCRState newState)
        {
            var handler = CardRemoved;

            if (handler == null) {
                return;
            }

            var args = new CardStatusEventArgs(
                readerName,
                newState,
                atr);

            handler(this, args);
        }
예제 #12
0
파일: CardReader.cs 프로젝트: edjo23/shop
 private void CardRemoved(object sender, CardStatusEventArgs e)
 {
     //throw new NotImplementedException();
 }
예제 #13
0
파일: CardReader.cs 프로젝트: edjo23/shop
        private void CardInserted(object sender, CardStatusEventArgs e)
        {
            Log.Debug("Card inserted");

            try
            {
                using (var reader = new IsoReader(CardContext, GetReader(), SCardShareMode.Shared, SCardProtocol.Any, false))
                {
                    var id = GetCardId(reader);
                    var status = GetReaderStatus(reader);

                    var cardName = GetCardName(status.Atr);
                    var cardType = GetInt16(cardName);

                    var isMifare = cardType == Mifare1KCard || cardType == Mifare4KCard;
                    var isMifareUltralight = cardType == MifareUltralightCard;

                    //var bytes = GetAllCardBytes(reader, isMifareUltralight ? 4 : 16);
                    var isShopCard = true; // IsShopCard(bytes);

                    Log.Debug(String.Format("Card Id: {0}, Shop Card: {1}", BitConverter.ToString(id), isShopCard));

                    if (isShopCard)
                    {
                        var cardString = BitConverter.ToString(cardName.Concat(id).ToArray()).Replace("-", "");

                        EventAggregator.Publish(new CardInserted { CardId = cardString });
                    }
                    else
                    {
                        EventAggregator.Publish(new InvalidCardInserted { });
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);

                EventAggregator.Publish(new InvalidCardInserted { });
            }
        }
예제 #14
0
 private void _Removed(string eventName, CardStatusEventArgs unknown)
 {
     if (eventCardRemoved != null)
     {
         eventCardRemoved();
     }
 }