Enumerate Devices

The example will enumerate all devices that could be found with the drivers that were provided. The driver directory has to be set properly, otherwise no devices and no drivers will be found.

C++

The source code of the example can be found in the file example_enumerate_devices.cpp:

  1#if defined(_WIN32) && defined(_MSC_VER)
  2#include <windows.h>
  3#endif
  4
  5#include <iostream>
  6#include <string>
  7#include <fstream>
  8#include <streambuf>
  9#include <algorithm>
 10#include <utility>
 11
 12#include <cstddef>
 13
 14#include <fluxEngine/fluxEngine>
 15
 16#include "paths.h"
 17#include "helpers.h"
 18
 19static std::string toString(fluxEngine::DriverState state)
 20{
 21    switch (state) {
 22    case fluxEngine::DriverState::Unknown: return "Unknown";
 23    case fluxEngine::DriverState::OK: return "OK";
 24    case fluxEngine::DriverState::LoadTimeout: return "LoadTimeout";
 25    case fluxEngine::DriverState::LoadError: return "LoadError";
 26    case fluxEngine::DriverState::EnumerationError: return "EnumerationError";
 27    case fluxEngine::DriverState::Crashed: return "Crashed";
 28    default: return "Unknown (Invalid state)";
 29    }
 30}
 31
 32static std::string toString(fluxEngine::ParameterInfo::Type type)
 33{
 34    switch (type) {
 35    case fluxEngine::ParameterInfo::Type::Unknown: return "Unknown";
 36    case fluxEngine::ParameterInfo::Type::Boolean: return "Boolean";
 37    case fluxEngine::ParameterInfo::Type::Integer: return "Integer";
 38    case fluxEngine::ParameterInfo::Type::Float: return "Float";
 39    case fluxEngine::ParameterInfo::Type::Enumeration: return "Enumeration";
 40    case fluxEngine::ParameterInfo::Type::String: return "String";
 41    case fluxEngine::ParameterInfo::Type::File: return "File";
 42    case fluxEngine::ParameterInfo::Type::Command: return "Command";
 43    default: return "Unknown (Invalid type)";
 44    }
 45}
 46
 47int main()
 48{
 49    try {
 50        std::cout << "fluxEngine version: " << fluxEngine::versionString() << std::endl;
 51        fluxEngine::Handle handle(readFile(g_licenseFileName));
 52        handle.setDriverBaseDirectory(g_driverDirectory);
 53        handle.setDriverIsolationExecutable(g_driverIsolationExecutable);
 54        handle.createProcessingThreads(4);
 55
 56        // Enumerate devices
 57        fluxEngine::EnumerationResult enumeratedDevices = fluxEngine::enumerateDevices(handle, -1, std::chrono::seconds{5});
 58        for (auto const& driver : enumeratedDevices.drivers)
 59            std::cout << "Found driver " << driver->name << " with state " << toString(driver->state) << "\n";
 60        for (auto const& error : enumeratedDevices.errors) {
 61            if (error.driver)
 62                std::cout << "Driver " << error.driver->name << " error: "  << error.message << "\n";
 63            else
 64                std::cout << "Global error: " << error.message << "\n";
 65        }
 66        for (auto const& warning : enumeratedDevices.warnings) {
 67            if (warning.driver)
 68                std::cout << "Driver " << warning.driver->name << " warning: "  << warning.message << "\n";
 69            else
 70                std::cout << "Global warning: " << warning.message << "\n";
 71        }
 72        for (auto const& device : enumeratedDevices.devices) {
 73            std::cout << "Found device for driver " << device->driver->name << "\n"
 74                      << "  - Display name: " << device->displayName << "\n"
 75                      << "  - Manufacturer: " << device->manufacturer << "\n"
 76                      << "  - Model: " << device->model << "\n"
 77                      << "  - Serial number: " << device->serialNumber << "\n";
 78            std::vector<std::string> const parameterNames = device->parameterInfo.parameterNames();
 79            std::size_t const parameterCount = parameterNames.size();
 80            if (parameterCount > 0) {
 81                std::cout << "  - Connection parameters:\n";
 82                for (auto const& parameterName : parameterNames) {
 83                    fluxEngine::ParameterInfo::AccessMode accessMode = device->parameterInfo.parameterAccessMode(parameterName);
 84                    if (accessMode == fluxEngine::ParameterInfo::AccessMode::ReadOnly || accessMode == fluxEngine::ParameterInfo::AccessMode::ReadWrite) {
 85                        std::string defaultValue = device->parameterInfo.parameterDefaultStringValue(parameterName);
 86                        if (device->parameterInfo.parameterType(parameterName) == fluxEngine::ParameterInfo::Type::Enumeration) {
 87                            int64_t defaultIntegerValue = device->parameterInfo.parameterDefaultIntegerValue(parameterName);
 88                            std::cout << "    - " << parameterName << " (" << toString(device->parameterInfo.parameterType(parameterName)) << "); default value = " << defaultValue << " (" << defaultIntegerValue << ")\n";
 89                        } else {
 90                            std::cout << "    - " << parameterName << " (" << toString(device->parameterInfo.parameterType(parameterName)) << "); default value = " << defaultValue << "\n";
 91                        }
 92                    } else {
 93                        std::cout << "    - " << parameterName << " (" << toString(device->parameterInfo.parameterType(parameterName)) << ", no default value)\n";
 94                    }
 95                    if (device->parameterInfo.parameterType(parameterName) == fluxEngine::ParameterInfo::Type::Enumeration) {
 96                        std::vector<std::string> const enumerationEntryNames = device->parameterInfo.enumerationEntryNames(parameterName);
 97                        for (auto const& entryName : enumerationEntryNames) {
 98                            int64_t value = device->parameterInfo.enumerationEntryValue(parameterName, entryName);
 99                            std::cout << "      - " << entryName << " = " << value << "\n";
100                        }
101                    }
102                }
103            } else {
104                std::cout << "  - No connection parameters\n";
105            }
106            std::cout << std::flush;
107        }
108    } catch (std::exception& e) {
109        std::cerr << "Error: " << e.what() << std::endl;
110        return 1;
111    } catch (...) {
112        std::cerr << "Unknown error." << std::endl;
113        return 1;
114    }
115
116    return 0;
117}

This source file will compile to the executable ExampleEnumerateDevices.

The following classes and methods are among those used in this example:

.NET

The source code of the example can be found in the file ExampleEnumerateDevices\Program.cs.

 1using System;
 2
 3namespace ExampleEnumerateDevices
 4{
 5    class Program
 6    {
 7        static void Main(string[] args)
 8        {
 9            Console.WriteLine("fluxEngine version: " + LuxFlux.fluxEngineNET.Version.String);
10            var handle = new LuxFlux.fluxEngineNET.Handle(ExampleHelpers.IO.ReadLicenseFile());
11            handle.SetDriverBaseDirectory(ExampleHelpers.Paths.DriverDirectory);
12            handle.CreateProcessingThreads(4);
13
14            var enumeratedDevices = LuxFlux.fluxEngineNET.DeviceEnumeration.EnumerateDevices(handle, null, TimeSpan.FromSeconds(5));
15            foreach (var driver in enumeratedDevices.Drivers)
16            {
17                Console.WriteLine($"Found driver {driver.Name} with state {driver.State}");
18            }
19            foreach (var error in enumeratedDevices.Errors)
20            {
21                if (error.Driver != null)
22                    Console.WriteLine($"Driver {error.Driver.Name} error: {error.Message}");
23                else
24                    Console.WriteLine($"Global error: {error.Message}");
25            }
26            foreach (var warning in enumeratedDevices.Warnings)
27            {
28                if (warning.Driver != null)
29                    Console.WriteLine($"Driver {warning.Driver.Name} warning: {warning.Message}");
30                else
31                    Console.WriteLine($"Global warning: {warning.Message}");
32            }
33            foreach (var device in enumeratedDevices.Devices)
34            {
35                Console.WriteLine($"Found device for driver {device.Driver.Name}");
36                Console.WriteLine($"  - Display name: {device.DisplayName}");
37                Console.WriteLine($"  - Manufacturer: {device.Manufacturer}");
38                Console.WriteLine($"  - Model: {device.Model}");
39                Console.WriteLine($"  - Serial Number: {device.SerialNumber}");
40                var parameterNames = device.ConnectionParameterList.ParameterNames;
41                if (parameterNames.Count > 0)
42                {
43                    Console.WriteLine("  - Connection parameters:");
44                    foreach (var parameterName in parameterNames)
45                    {
46                        var accessMode = device.ConnectionParameterList.ParameterAccessMode(parameterName);
47                        var type = device.ConnectionParameterList.ParameterType(parameterName);
48                        if (accessMode == LuxFlux.fluxEngineNET.ParameterList.AccessMode.ReadOnly || accessMode == LuxFlux.fluxEngineNET.ParameterList.AccessMode.ReadWrite)
49                        {
50                            string defaultValue = device.ConnectionParameterList.ParameterDefaultStringValue(parameterName);
51                            if (type == LuxFlux.fluxEngineNET.ParameterList.Type.Enumeration)
52                            {
53                                Int64 defaultIntegerValue = device.ConnectionParameterList.ParameterDefaultIntegerValue(parameterName);
54                                Console.WriteLine($"    - {parameterName} ({type}); default value = {defaultValue} ({defaultIntegerValue})");
55                            }
56                            else
57                            {
58                                Console.WriteLine($"    - {parameterName} ({type}); default value = {defaultValue}");
59                            }
60                        }
61                        else
62                        {
63                            Console.WriteLine($"    - {parameterName} ({type}); no default value");
64                        }
65                        if (type == LuxFlux.fluxEngineNET.ParameterList.Type.Enumeration)
66                        {
67                            var entryNames = device.ConnectionParameterList.EnumerationEntryNames(parameterName);
68                            foreach (var entryName in entryNames)
69                            {
70                                Int64 value = device.ConnectionParameterList.EnumerationEntryValue(parameterName, entryName);
71                                Console.WriteLine($"      - {entryName} = {value}");
72                            }
73                        }
74                    }
75                }
76                else
77                {
78                    Console.WriteLine($"  - No connection parameters");
79                }
80            }
81
82            handle.Dispose();
83        }
84    }
85}

The following classes and methods are among those used in this example:

Python

The source code of the example can be found in the file example_enumerate_devices.py:

 1#!/usr/bin/env python3
 2
 3import os
 4import fluxEngine
 5
 6import fluxEngine_example_paths as paths
 7
 8print('fluxEngine version {}'.format(fluxEngine.versionString()))
 9with open(paths.licenseFileName, 'rb') as f:
10    handle = fluxEngine.Handle(f.read())
11handle.setDriverBaseDirectory(paths.driverDirectory)
12handle.createProcessingThreads(4)
13
14enumeratedDevices = fluxEngine.enumerateDevices(handle, -1, 5000)
15for driver in enumeratedDevices.drivers:
16    print("Found driver {}, type {}, description and version: {} {}".
17        format(driver.name, driver.type,
18                driver.description, driver.version))
19for error in enumeratedDevices.errors:
20    if error.driver:
21        print("Driver {} error: {}".format(error.driver.name, error.message))
22    else:
23        print("Global error: {}".format(error.message))
24for warning in enumeratedDevices.warnings:
25    if warning.driver:
26        print("Driver {} warning: {}".format(warning.driver.name, warning.message))
27    else:
28        print("Global warning: {}".format(warning.message))
29for device in enumeratedDevices.devices:
30    print("Found device for driver {}".format(device.driver.name))
31    print("  - Display name: {}".format(device.displayName))
32    print("  - Manufacturer: {}".format(device.manufacturer))
33    print("  - Model: {}".format(device.model))
34    print("  - Serial Number: {}".format(device.serialNumber))
35    parameters = device.parameterInfo.parameters()
36    if len(parameters) > 0:
37        print("  - Connection parameters:")
38        for parameter in parameters:
39            if parameter.accessMode == fluxEngine.ParameterInfo.AccessMode.ReadOnly or parameter.accessMode == fluxEngine.ParameterInfo.AccessMode.ReadWrite:
40                print("    - {} ({}); default value = {}".format(parameter.name, parameter.type, parameter.defaultValue))
41            else:
42                print("    - {} ({}); no default value".format(parameter.name, parameter.type))
43    else:
44        print("  - No connection parameters:")

The following classes and methods are among those used in this example:

Expected Output

When only the virtual pushbroom camera driver is available in the drivers directory, the following output will appear (after 10s):

fluxEngine version: [...]
Found driver VirtualHyperCamera with state OK
Found device for driver VirtualHyperCamera
- Display name: Virtual Hyper Camera Driver
- Manufacturer:
- Model: Virtual Hyper Camera Driver
- Serial number:
- Connection parameters:
  - CameraType (Enumeration); default value = PushBroom (0)
    - PushBroom = 0
  - Cube (File); default value =
  - DarkReferenceCube (File); default value =
  - WhiteReferenceCube (File); default value =