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(); })); } }
private void _cardRemoved(object sender, CardStatusEventArgs e) { }
private void _cardInserted(object sender, CardStatusEventArgs e) { ReadCard(); }
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."; } }
/// <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} ); } }
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); }
private void ReaderInitializedEvent(CardStatusEventArgs args) { Debug.WriteLine("Reader {0} initialized", args.ReaderName); }
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); } }
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); }
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); }
private void CardRemoved(object sender, CardStatusEventArgs e) { //throw new NotImplementedException(); }
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 { }); } }
private void _Removed(string eventName, CardStatusEventArgs unknown) { if (eventCardRemoved != null) { eventCardRemoved(); } }