private void Read() { try { string data = ReadBlock(8); if (data == null) { return; } enNif.Text = data; data = ReadBlock(9); if (data == null) { return; } enName.Text = data; data = ReadBlock(10); if (data == null) { return; } enSurname.Text = data; data = ReadBlock(12); if (data == null) { return; } pkType.SelectedIndex = int.Parse(data); data = ReadBlock(13); if (data == null) { return; } enTickets.Text = data; data = ReadBlock(14); if (data == null) { return; } dpEndDate.Date = DateTime.Parse(data); DisplayAlert("Done", "Card configuration read", "Ok"); } finally { nfcService.StopByteBlockOperations(); } }
private void btnStop_Clicked(System.Object sender, System.EventArgs e) { nfcService.StopByteBlockOperations(); Device.BeginInvokeOnMainThread(() => lbState.Text = "Waiting..."); }
private async void NfcService_OnNfcTagDiscovered(object sender, EventArgs e) { nfcService.StopDiscovering(); try { string data = ReadBlock(8); if (data == null) { return; } lbNif.Text = data; data = ReadBlock(9); if (data == null) { return; } lbName.Text = data; data = ReadBlock(10); if (data == null) { return; } lbSurname.Text = data; data = ReadBlock(12); if (data == null) { return; } int type = int.Parse(data); data = ReadBlock(13); if (data == null) { return; } int tickets = int.Parse(data); data = ReadBlock(14); if (data == null) { return; } DateTime tillDate = DateTime.Parse(data); if (IsValidAccess(type, tickets, tillDate) && UpdateCardInfo(type, tickets)) { lbStatus.TextColor = Color.Green; lbStatus.Text = "Access granted"; } else { lbStatus.TextColor = Color.Red; lbStatus.Text = "Access denied"; } await Task.Delay(3000); } finally { lbNif.Text = string.Empty; lbName.Text = string.Empty; lbSurname.Text = string.Empty; lbStatus.TextColor = Color.Black; lbStatus.Text = "Bring your card closer to the reader to access"; nfcService.StopByteBlockOperations(); nfcService.StartDiscovering(); } }