private void Reader_CardReceived(object sender, CardDataEventArgs e) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.AppendLine($"Facility: {e.FacilityId}"); sb.AppendLine($"Card: {e.CardId}"); sb.AppendLine($"{DateTime.Now}"); output.Text = sb.ToString(); }
protected virtual void OnCardReceived(CardDataEventArgs args) => CardReceived?.Invoke(this, args);
private async void ReadData() { try { if (device == null) { return; } if (reader == null) { InitReader(); } if (IsReading) { return; } if (InputBuffer == null) { InputBuffer = new List <byte>(); } IsReading = true; reader.InputStreamOptions = InputStreamOptions.Partial; //reader.loa uint bitCount = await reader.LoadAsync(1); //.AsTask(); LastReceived = DateTime.Now; while (true) { byte b = reader.ReadByte(); if (b == 6) { // Do Nothing - Unit is jusr responding to a keep alive request. } else if (b == 2) { InputBuffer.Clear(); bool ContinueRead = true; while (ContinueRead) { bitCount = await reader.LoadAsync(1); //.AsTask(); b = reader.ReadByte(); if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debug.Write(b); } if (b != 3) { InputBuffer.Add(b); } else { ContinueRead = false; } } string result = System.Text.Encoding.UTF8.GetString(InputBuffer.ToArray()); CardDataEventArgs args = new CardDataEventArgs(result); OnCardReceived(args); } else { bitCount = await reader.LoadAsync(1); //.AsTask(); } } } catch (Exception ex) { } finally { IsReading = false; } }