NordicID.NurApi.SerialTransport
Technical Information
- This library is designed to generate serial based URIs, simplifying device discovery.
- Example URIs look like this:
ser://port-name
.
Supported Platforms
- Windows
- Linux
Mandatory step: Initialize the Library
This should be called only once, during your application's initialization.
NurApiDotNet.SerialTransport.Support.Init();
All done, the contents below is just an example of how to do basic device discovery and connect to it with NurApi.
1. Serial Device Discovery
First, we have to create a device discovery callback, this callback is used to receive the connection Uri's of the connected devices.
private readonly NurDeviceDiscoveryCallback deviceDiscoveryCallback;
// ...
deviceDiscoveryCallback = new NurDeviceDiscoveryCallback((sender, args) =>
{
Debug.WriteLine($"Found a device with the following connection URI: {args.Uri}");
});
2. Starting the device discovery
Next, we will be starting a device discovery and give the device discovery callback that we have created.
NurDeviceDiscovery.Start(deviceDiscoveryCallback);
Additionally, an explicit transport scheme can be specified when calling NurDeviceDiscovery.Start. For example:
NurDeviceDiscovery.Start(deviceDiscoveryCallback, new string[] { "ser" }); // Only devices with ser uri scheme
3. Connecting with a URI received from the NurDeviceDiscoveryCallback.
The Uri's that are used in NurApi.Connect(Uri)
will be received from the event arguments.
var api = new NurApi();
deviceDiscoveryCallback = new NurDeviceDiscoveryCallback((sender, args) =>
{
//args.Uri contains a connection Uri that can be used in the NurApi.Connect method to connect to the RFID reader.
});
Additionally, if you wish to update your app based on changes in the connection status, subscribe to the NurApi instance's ConnectionStatusEvent. This would look something like:
var api = new NurApi();
api.ConnectionStatusEvent += (sender, status) =>
{
Debug.WriteLine(status.ToString()); // Printing the changed NurTransportStatus.
};