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
#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)
if (deviceInfo.getConnectionString().toStdString().find("daq.opcua://") != std::string::npos)
std::cout << "Name: " << deviceInfo.getName() << ", Address: " << deviceInfo.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
available_devices_info = instance.available_devices
for device_info in available_devices_info:
if 'daq.opcua://' in device_info.connection_string:
print('Name:', device_info.name, 'Address:', device_info.connection_string)
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
#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()
devices = []
# Discover and connect to all openDAQ(TM) devices
available_devices_info = instance.available_devices
for device_info in available_devices_info:
if 'daq.opcua://' in device_info.connection_string:
devices.append(instance.add_device(device_info.connection_string))
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.nsd://" and
the openDAQ™ ws_stream_cl_module
uses addresses prefixed with "daq.ws://".
-
Cpp
-
Python
#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()
devices = []
# Discover and add all openDAQ(TM) reference devices
available_devices = instance.enumerate_available_devices()
for device_info in available_devices:
if 'daqref://' in device_info.connection_string:
devices.append(instance.add_device(device_info.connection_string))