BAOS SDK v2  1.2.1
An SDK providing access to IP-BAOS devices through BAOS binary protocol version 2.x
SetDatapointValue.cpp

This sample shows how to set datapoint values via the connection API

Datapoint

Usage:

SetDatapointValue <ip_address>
// e.g.:
SetDatapointValue 10.0.0.102

Pre-condition: It assumes that the following datapoints are configured:

|---------|-----------------|-----------------------------|-------------|---------------|
| Number  |  DPT            |  Name                       |  SizeInBit  |  Flags        |
|         |                 |                             |             | C R W T U I   |
|---------|-----------------|-----------------------------|-------------|---------------|
|    1    | DPT 01 - 1 bit  | Actuator A - Switch         | 1           | C - W - - -   |
|---------|-----------------|-----------------------------|-------------|---------------|
|    2    | DPT 01 - 1 bit  | Actuator A - State          | 1           | C R - T - -   |
|---------|-----------------|-----------------------------|-------------|---------------|
|    3    | DPT 01 - 1 bit  | Actuator B - Switch         | 1           | C - W - - -   |
|---------|-----------------|-----------------------------|-------------|---------------|
|    4    | DPT 01 - 1 bit  | Actuator B - State          | 1           | C R - T - -   |
|---------|-----------------|-----------------------------|-------------|---------------|
|   100   | DPT 01 - 1 bit  | not linked with group       | 1           | - - W T - -   | <- not linked with a group address
|---------|-----------------|-----------------------------|-------------|---------------|
Note
Another possibility is via the device API.
See also: Sample 04_BaosDatapointValues.cpp
//
// Copyright (c) 2002-2026 WEINZIERL ENGINEERING GmbH
// All rights reserved.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
// WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
//
#include "Helper.h"
#include <baos/Sdk.h>
#include <wzcpp/features/utils.h>
#include <iostream>
#include <memory>
using namespace wz::baos;
using namespace wz::baos::ip;
using namespace wz::baos::protocol;
/******************************************
** Main
*******************************************/
int main(int argc, char* argv[])
{
try
{
std::cout << "******************************************" << std::endl;
std::cout << "SetDatapointValue sample" << std::endl;
std::cout << "******************************************" << std::endl;
std::cout << std::endl;
// Reduce log messages
setBaosLogLevel(wz::baos::LogLevel::warn);
// The CommandLineOptions::parse function
// validates the arguments and handles the help command
CommandLineOptions options;
options.parse(argc, argv);
if (options.wasHelpdisplayed())
{
return 0;
}
// Get the ip address from the parsed command line options
const std::string ipAddress = options.getIpAddress();
std::cout << " Connection requested for " << ipAddress << std::endl;
// Create a TPC/IP connection to the remote BAOS device
BaosTcpConnection connection;
connection.open(ipAddress);
// Set some datapoint values (single item per request)
std::cout << "Set some datapoint values (single item per request)" << std::endl;
// id = 1 (DPT 01 - 1 bit)
connection.setDpValue(1, DatapointChangeValue{{0x00}, DatapointSetCommand::SetNewValue});
// Set multiple datapoint values (multiple items per request)
std::cout << "Set multiple datapoint values (multiple items per request)" << std::endl;
// id = 1, 2, 3 and 4
connection.setDpValues(
DatapointChangeValues{{1, DatapointChangeValue{{0x01}, DatapointSetCommand::SetNewValue}},
{2, DatapointChangeValue{{0x01}, DatapointSetCommand::SetNewValueAndSendOnBus}},
{3, DatapointChangeValue{{0x00}, DatapointSetCommand::SetNewValue}},
{4, DatapointChangeValue{{0x00}, DatapointSetCommand::SetNewValueAndSendOnBus}}});
std::cout << std::endl;
// Set some datapoint values (check if the datapoint is linked with group address)
std::cout << "Set some datapoint values (check if the datapoint is linked with group address)" << std::endl;
// read configuration
std::cout << " Read datapoint configuration" << std::endl;
const auto result = connection.getDpDescription(100);
// validate
if (!result.has_value())
{
std::cout << "Warning: Datapoint not exist" << std::endl;
return -1;
}
const DatapointDescription& desc = result.value();
bool isDpValid = desc.flags.communication;
if (isDpValid)
{
std::cout << " Datapoint is config with group address" << std::endl;
try
{
connection.setDpValue(100, DatapointChangeValue{{0x00}, DatapointSetCommand::SetNewValue});
}
catch (const std::exception& e)
{
std::cerr << "Failed: " << e.what() << std::endl;
}
}
else
{
std::cout << " Datapoint is not config with group address" << std::endl;
}
}
catch (const std::exception& e)
{
std::cerr << "Failed: " << e.what() << std::endl;
return -1;
}
return 0;
}
Specialization for a TCP IP v4 BAOSConnection.
BaosConLessTcpConnection BaosTcpConnection
A specialization for (connection-less) connection to the BAOS device via a TCP connection.
Definition: BaosTcpConnection.h:168
Global BAOS protocol defines and types.
Global BAOS SDK function and options.
Definition: Helper.h:23
void open(const std::string &ip4Address, std::uint16_t port=12004)
Open a connection to physical BAOS device.
Groups BAOS binary protocol specific types , defines and classes for Indications, Responses etc.
Definition: Defines.h:33
std::map< std::uint16_t, DatapointChangeValue > DatapointChangeValues
Definition: Defines.h:617
Global BAOS sdk namespace.
Definition: config.h:69
BAOSLIB_EXPORT void setBaosLogLevel(wz::baos::LogLevel level)