NordicID.NurApi.USBTransport
Technical Information
This library is designed to generate USB-based URIs, simplifying device discovery. Example URIs look like this on Windows: usb://com6/?deviceid=USB%5CVID_04E6%26PID_0112%5C100001011011
. For Linux, it would resemble: usb:///dev/ttyACM1?sid=100001011011
.
It operates alongside the Serial Transport Support Library to manage the transport layer.
Essentially, this library's primary function is to provide connection URIs for serial transport, specifically tailored for USB-based interactions. The USB devices discovered are solely Nordic ID devices.
Supported Platforms
- Windows
- Linux
Mandatory step: Initialize the Library
This should be called only once, during your application's initialization.
Warning
After initializing USBTransport, and if you would like to discover the FR 22 RFID reader,
please add this after the Support.Init() line: NordicID.NurApi.USBTransport.Support.EnableFTIDDiscovery = true;
NordicID.NurApi.USBTransport.Support.Init();
All done! Below is just an example of how to discover and connect to plugged USB devices.
1. USB 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[] { "usb" }); // Only devices with usb 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.
Under Windows the connection uri should look something along the lines of usb://com6/?deviceid=USB%5CVID_04E6%26PID_0112%5C100001011011
for Linux it would be something like usb:///dev/ttyACM1?sid=100001011011
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.
};
USB Auto Connect
The USB auto-connect feature simplifies device discovery and automatic connection. Use the following code snippet:
var nurApi = new NurApi();
nurApi.Connect("usb://autoconnect");
This continuously searches for devices. Upon discovery, it establishes an automatic connection. If the connection is lost, the USB auto-connect feature reinstates the procedure, attempting to reconnect to any available device.
However, setting nurApi.AutoReconnect
to false disables this functionality, preventing automatic reconnection in case of connection loss.