Using RFID RC522 Library for Windows IOT Core

1.7k Views Asked by At

I used Raspberry Pi 2 Model B with Windows 10 IOT Core Operating System.

I used the library provided in RFID RC522 Raspberry PI 2 Windows IOT

the problem is when I put this code in the MainPage.xaml.cs

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

    while (true)
    {
        if (mfrc.IsTagPresent())
        {
            var uid = mfrc.ReadUid();

            mfrc.HaltTag();
        }

    }

visual studio says that await operator can only be used within an async method. I don't have any idea on where to start. I only need the RFID to read tags and then show the RFID no/UID in a textbox

1

There are 1 best solutions below

0
On

You can put these code lines in a asynchronous method and call it in MainPage() like this:

    public MainPage()
    {
        this.InitializeComponent();
        InitRC522Async();
    }

    private async void InitRC522Async()
    {
        var mfrc = new Mfrc522();
        await mfrc.InitIO();

        while (true)
        {
            if (mfrc.IsTagPresent())
            {
                var uid = mfrc.ReadUid();

                mfrc.HaltTag();
            }
        }
    }