public static int GetLogicalDevices([MarshalAs(UnmanagedType.LPWStr)] ref string itemsBuf, ref int bufLen, IntPtr obj) { string text = $"!!! GetLogicalDevices !!!\tobj:{obj}\tItemsBuf:{itemsBuf}\tbufLen:{bufLen}\t"; WriteToLog(text); try { var readers = CardReader.GetReaderNames().ToArray(); string res = ""; Array.ForEach(readers, t => res += (string.IsNullOrWhiteSpace(res) ? "" : "#0") + t); res += '\0'; bufLen = readers.Length; text = $"!!! GetLogicalDevices !!!\tLogicalDevices:{res}"; WriteToLog(text); //UnMemory<char>.SaveInMemArr(res.ToCharArray(), ref itemsBuf); itemsBuf = res; return((int)ErrorCodes.E_SUCCESS); } catch (Exception e) { WriteToLog($"GetLogicalDevices ERROR !!! {text}\r\n {e}"); return((int)ErrorCodes.E_GENERIC); } }
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); } }
/// <summary> /// Updates The Combobox to show attached scanners /// </summary> private void UpdateScanners() { string[] scanners = CardReader.GetReaderNames().ToArray <string>(); cmbScanners.Items.Clear(); if (scanners.Length == 0) { cmbScanners.Text = "No NFC Scanners Detected..."; cmdConnectScanner.Enabled = false; return; } cmbScanners.Items.AddRange(scanners); cmdConnectScanner.Enabled = true; return; }
public void ListReadersTest() { var readers = CardReader.GetReaderNames(); Assert.Equal(1, readers.Count); }