private async Task ReadAsync() { var mfrc = new Mfrc522(); await mfrc.InitIOAsync(); await ResetAsync(); while (true) { try { if (mfrc.IsTagPresent()) { Uid uid = mfrc.ReadUid(); if (uid.IsValid) { await CheckingAsync(uid); DataBadge badge = new DataBadge { Orario = DateTime.Now, Id = uid.FullUid, Posizione = "Villafranca" }; _pinBlueLed.SetDriveMode(GpioPinDriveMode.Output); _pinBlueLed.Write(GpioPinValue.High); var messageString = JsonConvert.SerializeObject(badge); var message = new Microsoft.Azure.Devices.Client.Message(Encoding.ASCII.GetBytes(messageString)); message.Properties.Add("DeviceId", DeviceId); await _client.SendEventAsync(message); } else { await ErrorReadAsync(); } mfrc.HaltTag(); } } catch (Exception ex) { await _client.CloseAsync(); var e = ex; } } }