Exemplo n.º 1
0
        public static async Task <bool> Initialize()
        {
            if (reader == null)
            {
                try
                {
                    reader = await CardReader.FindAsync();

                    if (reader == null)
                    {
                        throw new Exception();
                    }
                    reader.CardAdded   += Reader_CardAdded;
                    reader.CardRemoved += Reader_CardRemoved;
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 2
0
        private static async Task <int> InitializeReader()
        {
            WriteToLog("InitializeReader");
            try
            {
                if (_reader != null)
                {
                    return((int)ErrorCodes.E_SUCCESS);
                    //_reader.CardAdded -= Reader_CardAdded;
                    //_reader.CardRemoved -= Reader_CardRemoved;
                    //_reader = null;
                    //WriteToLog("ClearReader");
                }
                var    readers    = CardReader.GetReaderNames().ToArray();
                string currReader = "";
                if (readers.Length > 0)
                {
                    //var r = new ReaderSelect();
                    //r.Init(readers);
                    //r.ShowDialog();
                    var configPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "\\",
                                                  "Mifaread3.ini");
                    //MessageBox.Show($"LIB IN {configPath}");
                    var config = new INIHelper(configPath);
                    WriteToLog($"ini file:{configPath}");

                    currReader = (string.IsNullOrWhiteSpace(_readerName) ? config["LogicalDevice"] : _readerName);
                    //currReader = config["LogicalDevice"];
                }
                WriteToLog($"select reader:{currReader}");

                if (!readers.Contains(currReader))
                {
                    currReader = readers.First();
                }

                _reader = await CardReader.FindAsync(currReader);

                WriteToLog($"reader is:{currReader}");

                if (_reader != null)
                {
                    _reader.CardAdded   += Reader_CardAdded;
                    _reader.CardRemoved += Reader_CardRemoved;
                }
                return((int)ErrorCodes.E_SUCCESS);
            }
            catch (Exception e)
            {
                WriteToLog($"InitializeReader ERROR!!!\r\n {e}");
                return((int)ErrorCodes.E_GENERIC);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Enumerates NFC reader and registers event handlers for card added/removed
        /// </summary>
        /// <returns>None</returns>
        async private void GetDevices()
        {
            try
            {
                Reader = await CardReader.FindAsync();

                if (Reader == null)
                {
                    PopupMessage("No Readers Found");
                    return;
                }

                Reader.CardAdded   += CardAdded;
                Reader.CardRemoved += CardRemoved;
            }
            catch (Exception e)
            {
                PopupMessage("Exception: " + e.Message);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates The Scanner Object
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="ev"></param>
        private async void cmdConnectScanner_Click(object sender, EventArgs ev)
        {
            if (cmbScanners.SelectedIndex == -1)
            {
                return;
            }
            try
            {
                reader = await CardReader.FindAsync(cmbScanners.Text);

                reader.CardAdded   += CardAdded;
                reader.CardRemoved += CardRemoved;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }



            lblCardPresence.Invoke(new Action(() => lblCardPresence.Text = "No Card Present"));
        }
Exemplo n.º 5
0
        public static async Task Initialize()
        {
            // Clear out any old event handlers
            cardAdded   = null;
            cardRemoved = null;

            if (reader != null)
            {
                return;
            }

            context = SynchronizationContext.Current;

            var r = await CardReader.FindAsync();

            if (r != null)
            {
                reader = r;

                reader.CardAdded   += OnCardAdded;
                reader.CardRemoved += OnCardRemoved;
            }
        }
Exemplo n.º 6
0
        public async void ListReadersTest()
        {
            var reader = await CardReader.FindAsync();

            Assert.NotNull(reader);
        }