private void CreateNfcReader() { SetStatus("Connecting to RFID Reader through UART Bridge ..."); nfc?.Close(); Pn532CommunicationHsu.CreateSerialPort(UartBridgeName3).ContinueWith(t => { if (t.IsFaulted || t.Result == null) { SetStatus("Reader port configuration failed"); return; } nfc = new NfcPn532Reader(t.Result); nfc.TagDetected += nfc_TagDetected; nfc.TagLost += nfc_TagLost; try { var openResult = nfc.Open(NfcTagType.MifareUltralight).Wait(5000); SetStatus(openResult ? "Reader ready" : "Reader open failed"); } catch (Exception) { SetStatus("Reader open failed"); } }); }
private async Task CreateNfcReader() { while (true) { if (_nfcReader == null || _nfcReader != null && !_nfcReader.IsRunning) { SetNfcStatus("Connecting Reader..."); if (_nfcReader != null) { await Task.Delay(2000); _nfcReader.Close(); } try { var portCreated = await Pn532CommunicationHsu.CreateSerialPort(UartBridgeName); _nfcReader = new NfcPn532Reader(portCreated); _nfcReader.TagDetected += nfc_TagDetected; _nfcReader.TagLost += nfc_TagLost; await ReaderOpen(); } catch (Exception) { SetNfcStatus("Reader port configuration failed"); } } } }