Connect to a Device

openDAQ™ provides Device connectivity features through Modules. Said Modules contain mechanisms for discovering and connecting to Devices. By listing available Devices, Modules are asked to return meta-information about Devices they can connect to. This metadata contains an address (connection string) at which the Device is accessible. The procedure of querying Modules for available Devices, as well as selecting the appropriate Module when connecting to a Device is done automatically by the openDAQ™ Instance and its default Root Device.

Related articles:

Connecting to openDAQ™ OPC UA devices

openDAQ™ provides three client and three server modules. They enable us to connect to openDAQ™ devices, as well as transfer their signal data. The openDAQ™ opcua_client_module uses an OPC UA client to connect to openDAQ™ OPC UA-compatible devices that are running a compatible OPC UA server. openDAQ™ OPC UA devices are discovered at an address prefixed with "daq.opcua://".

  • Cpp

  • Python

  • C#

#include <opendaq/opendaq.h>
#include <iostream>

int main(int argc, const char* argv[])
{
    // Create an openDAQ(TM) instance, loading modules from the current directory
    daq::InstancePtr instance = daq::Instance(MODULE_PATH);

    // Discover and print the names and connection strings of openDAQ(TM) devices
    daq::ListPtr<daq::IDeviceInfo> availableDevicesInfo = instance.getAvailableDevices();
    for (const auto& deviceInfo : availableDevicesInfo)
    {
        for (const auto & capability : deviceInfo.getServerCapabilities())
        {
            if (capability.getProtocolName() == "openDAQ OpcUa")
            {
                std::cout << "Name: " << deviceInfo.getName() << ", Address: " << capability.getConnectionString() << std::endl;
            }
        }
    }

    return 0;
}
import opendaq

# Create an openDAQ(TM) instance
instance = opendaq.Instance()

# Discover and print the names and connection strings of openDAQ(TM) devices
for device_info in instance.available_devices:
    for capability in device_info.server_capabilities:
        if capability.protocol_name == 'openDAQ OpcUa':
            device = instance.add_device(capability.connection_string)
            break
using Daq.Core.Types;
using Daq.Core.Objects;
using Daq.Core.OpenDAQ;

// Create an openDAQ(TM) instance, loading modules from the current directory
Instance instance = OpenDAQFactory.Instance(MODULE_PATH);

// Discover and print the names and connection strings of openDAQ(TM) devices
IListObject<DeviceInfo> availableDevicesInfo = instance.GetAvailableDevices();
foreach (var deviceInfo in availableDevicesInfo)
    if (deviceInfo.GetConnectionString().StartsWith("daq.opcua://"))
        Console.WriteLine($"Name: {deviceInfo.GetName()}, Address: {deviceInfo.GetConnectionString()}");

The connection string of discovered devices can be used to connect to them. Doing so adds the remote device as a child of the Root device. The device can now be viewed, configured, and its data can be streamed. For configuration and inspection of its properties, OPC UA is used. Native streaming protocol is used to stream the device’s data.

  • Cpp

  • Python

  • C#

#include <opendaq/opendaq.h>
#include <iostream>

int main(int argc, const char* argv[])
{
    // Create an openDAQ(TM) instance, loading modules from the current directory
    daq::InstancePtr instance = daq::Instance(".");

    ListPtr<IDevice> devices = List<IDevice>();
    // Discover and connect to all openDAQ(TM) devices
    for (const auto& deviceInfo : instance.getAvailableDevices())
        if (deviceInfo.getConnectionString().toStdString().find("daq.opcua://") != std::string::npos)
            devices.pushBack(instance.addDevice(deviceInfo.getConnectionString()));

    return 0;
}
import opendaq

# Create an openDAQ(TM) instance
instance = opendaq.Instance()

# Discover and connect to all openDAQ(TM) devices
devices = [instance.add_device(d.connection_string)
           for d in instance.available_devices
           if d.connection_string.startswith('daq.opcua://')]
using Daq.Core.Types;
using Daq.Core.Objects;
using Daq.Core.OpenDAQ;

// Create an openDAQ(TM) instance, loading modules from the current directory
Instance instance = OpenDAQFactory.Instance(MODULE_PATH);

IListObject<Device> devices = CoreTypesFactory.CreateList<Device>();
// Discover and connect to all openDAQ(TM) devices
foreach (var deviceInfo in instance.GetAvailableDevices())
if (deviceInfo.GetConnectionString().StartsWith("daq.opcua://"))
    devices.Add(instance.AddDevice(deviceInfo.GetConnectionString()));

Connecting to other devices

The openDAQ™ opcua_client_module allows for connecting to specifically openDAQ™ OPC UA-enabled devices. However, openDAQ™ modules can be written to connect to different kinds of devices (local or remote). For example, the openDAQ™ ws_stream_cl_module (Web-socket streaming client module) and the openDAQ™ native_stream_cl_module (Native streaming client module) allow for connecting to remote devices without using of OPC UA protocol. Another example is the openDAQ™ reference device module, which allows for the creation of reference devices that simulate sine wave signals.

Depending on the modules loaded we can connect to different types of devices. When a device is integrated into openDAQ™, it is added/connected to in the same manner as a openDAQ™ OPC UA device, but using its own discovery mechanism and connection string format. For example, the openDAQ™ reference device module uses addresses prefixed with "daqref://", the openDAQ™ native_stream_cl_module uses addresses prefixed with "daq.ns://" and the openDAQ™ ws_stream_cl_module uses addresses prefixed with "daq.lt://".

  • Cpp

  • Python

  • C#

#include <opendaq/opendaq.h>
#include <iostream>

int main(int argc, const char* argv[])
{
    // Create an openDAQ(TM) instance, loading modules from the current directory
    daq::InstancePtr instance = daq::Instance(MODULE_PATH);

    ListPtr<IDevice> devices = List<IDevice>();
    // Discover and add all openDAQ(TM) reference devices
    for (const auto& deviceInfo : instance.getAvailableDevices())
        if (deviceInfo.getConnectionString().toStdString().find("daqref://") != std::string::npos)
            devices.pushBack(instance.addDevice(deviceInfo.getConnectionString()));

    return 0;
}
import opendaq

# Create an openDAQ(TM) instance
instance = opendaq.Instance()

# Discover and add all openDAQ(TM) reference devices
devices = [instance.add_device(d.connection_string)
           for d in instance.enumerate_available_devices()
           if d.connection_string.startswith('daqref://')]
using Daq.Core.Types;
using Daq.Core.Objects;
using Daq.Core.OpenDAQ;

// Create an openDAQ(TM) instance, loading modules from the current directory
Instance instance = OpenDAQFactory.Instance(MODULE_PATH);

IListObject<Device> devices = CoreTypesFactory.CreateList<Device>();
// Discover and connect to all openDAQ(TM) reference devices
foreach (var deviceInfo in instance.GetAvailableDevices())
    if (deviceInfo.GetConnectionString().StartsWith("daqref://"))
        devices.Add(instance.AddDevice(deviceInfo.GetConnectionString()));