Device enumeration#
One of the key functionalities of the system is to enumerate and provide usable devices to the client code. Opto Engineering devices are controlled via the H_DEVICE
handle.
Warning
The maximum number of enumerated devices is 255. The maximum number of simultaneously created devices is 50.
Enumerate all available devices#
The quickest way to be up and running is to make the system look for devices across all network interfaces available.
The result of the enumeration performed by the system enable the user to retrive those data and store them as DeviceInfo
containing useful information about available devices. To start using a specific device, the client code must pick the proper DeviceInfo
and provide it to the system so that it can create the device instance.
Warning
The client code is responsible for device instances lifetime. The client code must destroy the device instances when they are no longer required.
//Look for connected devices across all network interfaces on the host.
//Stop the enumeration after an elapsed time of 700 milliseconds.
error = SYS_EnumerateDevices(700);
// Retrive the amount of devices found with previous enumeration
size_t numberOfDevices = 0;
error = SYS_GetDeviceCount(&numberOfDevices);
// Retrive the DeviceInfo at index 0 of the previous enumeration
DeviceInfo deviceInfo;
error = SYS_GetDeviceByIndex(0, &deviceInfo);
H_DEVICE hDevice = NULL;
error = SYS_CreateDevice(deviceInfo, &hDevice);
// Use the device
error = DEV_Dispose(hDevice);
hDevice = NULL;
Enumerate devices under specific network interfaces#
A more precise enumeration can be performed by specifing a target network interface. The proper InterfaceInfo
data must be passed to the system to specify under which interface the device enumeration must be performed. To obtain the InterfaceInfo
, an interface enumeration must be accomplished, via SYS_EnumerateInterfaces
.
// Enumerate the available interfaces on the host
error = SYS_EnumerateInterfaces();
// Retrive the amount of interfaces found on the host.
size_t numberOItf = 0;
error = SYS_GetInterfaceCount(&numberOItf);
// Retrive the InterfaceInfo at index 0 of the previous enumeration
InterfaceInfo itfInfo;
error = SYS_GetInterfaceByIndex(0, &itfInfo);
// Looks for connected devices under the specified interface.
// Stops the enumeration after an elapsed time of 700 milliseconds.
error = SYS_EnumerateDevicesByInterface(itfInfo, 700);
// Retrive the amount of devices found with previous enumeration
size_t numberOfDevices = 0;
error = SYS_GetDeviceCount(&numberOfDevices);
// Retrive the DeviceInfo at index 0 of the previous enumeration
DeviceInfo deviceInfo;
error = SYS_GetInterfaceByIndex(0, &deviceInfo);
H_DEVICE hDevice = NULL;
error = SYS_CreateDevice(deviceInfo, &hDevice);
// Use the device
error = DEV_Dispose(hDevice);
hDevice = NULL;