C# Reading RFID

328 views Asked by At

I need to read the RFID off of a badges and for example write it to a Textbox. The program needs to work on multiple devices. I have for example a MPI Tablet and a Rugged Tablet. Both with Windows 10.

I've tried to implement it in C# WPF and in UWP. In which of both is irrelevant.

https://github.com/Nellymandela/nfc-card-reader-winform I've tried a solution like that but just in WPF. Both solutions just worked on the Rugged Tablet but on the MPI tablet just nothing happened.

Didn't work on any of those both tablets.

It looked like that: (using Windows.Networking.Proximity)

    private ProximityDevice proximityDevice;
    private long subscribedMessageId = -1;

    public MainPage()
    {
        
        InitializeComponent();

        proximityDevice = ProximityDevice.GetDefault();

        if(proximityDevice != null)
        {
            subscribedMessageId = proximityDevice.SubscribeForMessage("NDEF", messageReceived); 
            
        }

    }
    private void messageReceived(ProximityDevice sender, ProximityMessage msg)
    {
        UIDTextBox.Text = msg.DataAsString;
    }

Can somebody help me?

Edit: proximityDevice wasn't null. I also tried the following code, where proximityDevice wasn't as well null. One thing that makes it complicated, that the device where I program has no integrated NFC Reader, so I test it on the tablets. They both have integrated NFC Readers (Proximity Devices):

    private long _messageSubscribeId = -1;

    private ProximityDevice proximityDevice;
    private long subscribedMessageId = -1;

    public MainPage()
    {

        InitializeComponent();

        InitializeProximity();

    }

    private async void InitializeProximity()
    {
        proximityDevice = ProximityDevice.GetDefault();
        string selectorString = ProximityDevice.GetDeviceSelector();

        var deviceInfoCollection = await DeviceInformation.FindAllAsync(selectorString, null);

        if(deviceInfoCollection.Count > 0)
        {
            proximityDevice = ProximityDevice.FromId(deviceInfoCollection[0].Id);
            txtBoxA.Text = proximityDevice.DeviceId + " " + proximityDevice.ToString();
            subscribedMessageId = proximityDevice.SubscribeForMessage("NDEF", messageReceived);
            proximityDevice.DeviceArrived += deviceArrivedHandler;
        } else
        {
            proximityDevice = null;
        }

    }


        private void messageReceived(ProximityDevice sender, ProximityMessage msg)
    {
        UIDTextBox.Text = msg.DataAsString;
    }
0

There are 0 answers