Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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();
            }
        }
Exemplo n.º 4
0
        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();
            }
        }
Exemplo n.º 5
0
        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;
                }
            }
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
        /// <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));
            }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            Debug.WriteLine("Running....");
            InitGPIO();
            pin.Write(GpioPinValue.High);

            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

            mfrc = new Mfrc522();
            await mfrc.InitIO();

            // Main loop
            while (true)
            {
                //true when an RFiD tag is detected
                if (mfrc.IsTagPresent())
                {
                    pin.Write(GpioPinValue.Low);
                    Debug.WriteLine("IsTagPresent() == True.");
                    //read the UUID from the card
                    Uid uid = mfrc.ReadUid();
                    Debug.WriteLine("Tag value == " + uid.ToString());
                    //rfid controller halt state
                    //mfrc.HaltTag();

                    //Send message to IoT Hub
                    await AzureIoTHub.SendDeviceToCloudMessageAsync(uid.ToString());

                    pin.Write(GpioPinValue.High);
                }

                //sleep
                await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(1));
            }
            //deferral.Complete();
        }
Exemplo n.º 9
0
        public static async Task <CardModel> BuildCardModelAsync(Mfrc522 mfrc)
        {
            string SmartCardId = await GetSmartCardIdAsync(mfrc);

            return(new CardModel(SmartCardId));
        }
Exemplo n.º 10
0
        public static async Task <CardModel> GetCard(Mfrc522 mfrc)
        {
            CardModel card = await CardModel.BuildCardModelAsync(mfrc);

            return(card);
        }
Exemplo n.º 11
0
 public async Task InitializeAsync(int initialDelay, int period, Mfrc522 obj)
 {
     _timer = new Timer(OnTimerAsync, obj, initialDelay, period);
 }