Save and load Configuration

openDAQ™ provides features to save the current Configuration to JSON format. The Configuration is defined as the current state of the complete openDAQ tree. It consists of:

  • Devices and their properties,

  • Device Channels and their properties,

  • Device custom components and their properties,

  • Subdevices (recursively) and their properties,

  • Function Blocks and their properties,

  • Signals and their properties,

  • Input Ports with connections to Signals.

When loading a Configuration from JSON format all components except Function Blocks are matched by their local ID and the properties are applied from JSON to the objects themselves. Function Blocks are first constructed from their type ID (if a module exists) and then the properties are applied from JSON.

Save Configuration

The SDK provides a method on the instance interface to save the Configuration to a string. The application can use this string to save the Configuration to a file or any other media.

  • Cpp

  • Python

  • C#

// Save Configuration to string
std::string jsonStr = instance.saveConfiguration();
// Write Configuration string to file
std::ofstream configFile("config.json");
configFile << jsonStr;
configFile.close();
# Save Configuration to string
json_str = instance.save_configuration()
# Write Configuration string to file
config_file = open("config.json", "w")
config_file.write(json_str)
config_file.close()
// Save Configuration to string
string jsonStr = instance.SaveConfiguration();
// Write Configuration string to file
File.WriteAllText("openDAQconfig.json", jsonStr, System.Text.Encoding.UTF8);

Saving Configuration will produce a string similar to this:

"refch0": {
    "__type": "Channel",
    "typeId": "ref_channel",
    "sig": {
        "__type": "Folder",
        "items": {
            "ai0": {
                "__type": "Signal",
                "domainSignalId": "dev/ref_dev0/io/ai/refch0/sig/ai0_time"
            },
            "ai0_time": {
                "__type": "Signal"
            }
        }
    },
    "propValues": {
        "Amplitude": 1.0,
        "TestReadOnly": true
    }
}

Because the Configuration string can be very long, the one shown above has been trimmed to show only a part of it.

Load Configuration

Once the Configuration has been saved, it can be applied to the openDAQ instance. The Configuration is passed as a string parameter which can be read from a file or any other media.

  • Cpp

  • Python

  • C#

// Read Configuration from file
std::ifstream configFile("config.json");
std::stringstream jsonStr;
jsonStr << configFile.rdbuf();
// Load Configuration from string
instance.loadConfiguration(jsonStr.str());
# Read Configuration from file
config_file = open("config.json", "r")
json_str = config_file.read()
config_file.close()
# Load Configuration from string
instance.load_configuration(json_str)
// Read Configuration from file
string jsonStr = File.ReadAllText("openDAQconfig.json", System.Text.Encoding.UTF8);
// Load Configuration from string
instance.LoadConfiguration(jsonStr);

The current implementation of SDK does not add Devices that are described in the Configuration string. Devices must be already mounted in the openDAQ tree. However, Function Blocks present in the Configuration string will be instantiated and added under the Function Blocks folder before they are configured from JSON Configuration string.

Saving and loading Configuration of specific components

openDAQ SDK also supports storing and loading of Configuration for individual components (Device, Channel, Function Block, etc …​)