public void Start() { var mfrc = new Mfrc522(); var task = new Task(async() => { await mfrc.InitIO(); }); task.RunSynchronously(); while (true) { if (_isStoping) { break; } if (mfrc.IsTagPresent()) { var uid = mfrc.ReadUid(); var sendTask = new Task(async() => { await _sender.SendUserId(uid.ToString()); }); sendTask.Start(); mfrc.HaltTag(); } Task.Delay(100).Wait(); } }
public async Task RfidReader() { try { var mfrc = new Mfrc522(); await mfrc.InitIO(); Debug.WriteLine("InitIO Success"); while (true) { await Task.Delay(TimeSpan.FromSeconds(1)); // Saniyelik saysın. if (mfrc.IsTagPresent()) { Debug.WriteLine("There is a Tah"); var uid = mfrc.ReadUid(); mfrc.HaltTag(); var dialog = new MessageDialog(uid.ToString()) { Title = "A card has been read" }; dialog.Commands.Add(new UICommand { Label = "Ok", Id = 0 }); dialog.Commands.Add(new UICommand { Label = "Cancel", Id = 1 }); var result = await dialog.ShowAsync(); Debug.WriteLine("Success"); if ((int)result.Id == 0) { // DO some stuff like sending id to web references //send id to your db web service.. } else { continue; //skip your task } } } } catch (Exception ex) { var dialog = new MessageDialog("An Error has Occured While Reading... Inner Exception is " + ex.Message) { Title = "What Da?" }; var result = await dialog.ShowAsync(); } }
public async Task Init() { lcd.init(); lcd.prints("bom dia"); lcd.gotoxy(0, 1); lcd.prints("Lcd test"); var gpioController = await GpioController.GetDefaultAsync(); try { var pin7 = gpioController.OpenPin(17); pin7.SetDriveMode(GpioPinDriveMode.Output); lcd.clrscr(); lcd.prints("liga"); pin7.Write(GpioPinValue.Low); await Task.Delay(1000); lcd.clrscr(); lcd.prints("desliga"); pin7.Write(GpioPinValue.High); await Task.Delay(1000); lcd.clrscr(); lcd.prints("liga"); pin7.Write(GpioPinValue.Low); } catch { Debug.Write("Erro desconhecido"); } var mfrc = new Mfrc522(); await mfrc.InitIO(); while (true) { if (!mfrc.IsTagPresent()) { continue; } var uidd = mfrc.ReadUid(); mfrc.HaltTag(); lcd.clrscr(); lcd.prints(uidd.ToString()); await Task.Delay(1000); } }
public static void Main() { var led = new OutputPort(Pins.ONBOARD_LED, false); var mfrc = new Mfrc522(SPI.SPI_module.SPI1, Pins.GPIO_PIN_D8, Pins.GPIO_PIN_D7); // Request while (true) { led.Write(mfrc.IsTagPresent()); mfrc.HaltTag(); } }
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; } } }
public static async Task <string> GetSmartCardIdAsync(Mfrc522 mfrc) { Uid uid = null; if (await mfrc.IsTagPresent()) { uid = await mfrc.ReadUid(); await mfrc.HaltTag(); } if (uid != null) { return(uid.ToString()); } else { return(null); } }
private void LectorRFID() { while (true) { if (rfid.IsTagPresent()) { var uniqueID = rfid.ReadUid(); Debug.WriteLine(uniqueID.ToString()); rfid.HaltTag(); for (int i = 0; i < usersID.Length; i++) { if (uniqueID.ToString() == usersID[i]) { textBoxUser.Text = string.Format("{0}", usersName[i].ToString()); imageUser.Source = new BitmapImage(new Uri("ms-appx:///Assets/User/" + usersImage[i])); } } break; } } }
/// <summary> /// RFID Presence Function /// </summary> private async void RFID_Presence() { //initialize the RFID Reader Mfrc522 mfrc = new Mfrc522(); await mfrc.InitIO(); //loop while (true) { //error handling try { //verify if the tag is present if (mfrc.IsTagPresent()) { //show the picture imgRFID.Visibility = Windows.UI.Xaml.Visibility.Visible; //read the UUID and show in UI var uid = mfrc.ReadUid(); txtUUID.Text = uid.ToString(); //rfid controller halt state mfrc.HaltTag(); } else { //reset the uuid txtUUID.Text = String.Empty; //hide the picture imgRFID.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } } catch { } //sleep await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(1)); } }