0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Read RFID tag in C# UWP

Last updated at Posted at 2019-08-05

A serial RFID reader can be read using DataReader with the help of SerialPort that is being used to find the connected port in the system.

private SerialDevice _serialPort;
private DataReader _dataReader;
private ObservableCollection<DeviceInformation> _deviceList;
private CancellationTokenSource _readCancellationTokenSource;

Then we need to configure the serial settings

try
{
   string devSel = SerialDevice.GetDeviceSelector();
   var dis = await DeviceInformation.FindAllAsync(devSel);
   if (dis.Count > 0)
   {
      DeviceInformation entry = (DeviceInformation)dis[0];
      this._serialPort = await SerialDevice.FromIdAsync(entry.Id);
      this._serialPort.ReadTimeout = TimeSpan.FromMilliseconds(1000);
      this._serialPort.BaudRate = 9600;
      this._serialPort.DataBits = 8;
      this._serialPort.StopBits = SerialStopBitCount.One;
      this._serialPort.Parity = SerialParity.None;
      this._serialPort.Handshake = SerialHandshake.None;
      this._readCancellationTokenSource = new CancellationTokenSource();
    }
} catch (Exception ex)
{
   Debug.WriteLine(ex.ToString());
}

And from that serial port InputStream, we can read the data from the serial device.

this._dataReader = new DataReader(this._serialPort.InputStream);
Task<UInt32> loadAsyncTask;
uint ReadBufferLength = 1024;
cancellationToken.ThrowIfCancellationRequested();

// create task and wait for the data on the input stream
loadAsyncTask = this._dataReader.LoadAsync(ReadBufferLength).AsTask(cancellationToken);
UInt32 bytesRead = await loadAsyncTask;

// this line will return the data from the serial RFID device
this._dataReader.ReadString(bytesRead);

Reference link: https://github.com/phanithken/RFIDReader

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?