DeviceDetection.Net

The DeviceDetection.Net provides a .Net assembly that implements the Device Detection protocol of the SoM/iRJ45. This allows the device configuration by other applications such as web base management software etc.

Visual Studio Project Setup

To setup a new project with DeviceDetection.Net support follow these steps:

  1. Create a new project e.g. C# .Net Console application

  2. Select the .Net 6.0 framework

  3. Copy the DeviceDetection.dll assembly to the project

  4. Add the reference to the assembly via right-click on “Dependencies” in the Solution Explorer

  5. Add the variable database goal_db.json file to the project

  6. Install Newtonsoft.JSON via NuGet to the project

Detecting devices in the network

To detect devices in the network, instantiate DeviceDetectionProtocol providing the file containing the database of GOAL variables:

using DeviceDetection; string goal_db_file = "goal_db.json"; /* Initialize the protocol */ DeviceDetectionProtocol proto = new(goal_db_file);

Devices can be detected by invoking the function DetectDevices of class DeviceDetectionProtocol providing the local IP to use as the source address for sending UDP packets and a timeout:

/* settings */ string localIp = "192.168.0.200"; int detectTimeout = 200; /* detect devices in the network */ var devices = proto.DetectDevices(localIp, timeout);

This function returns a List<Device> instance containing the found devices.

Reading network parameters

The network parameters of a device can be read by invoking ReadNetworkParams of class DeviceDetectionProtocol. This function returns a tuple containing the IP settings of the device:

(string? ip, string? netmask, string? gw, string? dns0, string? dns1) = proto.ReadNetworkParams(device, localIp, rwTimeout);

As the parameters, the function expects the Device instance to read from, the local IP to use as well as the timeout for the reply.

Setting network parameters

The network parameters of a device can set by invoking SetNetworkParams of class DeviceDetectionProtocol. The function returns true if the operation was successful otherwise false.

The function expects the following parameters:

  • device: the Device instance to set the parameters

  • localIp: the local IP to use

  • ipToSet: the IP address as dotted string notation

  • netmask: the net mask to set as dotted string notation

  • gw: the gateway address to set as dotted string notation

  • dns0: the first DNS server IP as dotted string notation

  • dns1: the second DNS server IP as dotted string notation

  • apply: set to true to immediately apply and use the new IP address after setting, otherwise false

  • permanent: set to true to store the new IP settings permanently to flash. If false, the setting is lost after reboot