BAOS SDK v2  1.0.1
An SDK providing access to IP-BAOS devices through BAOS binary protocol version 2.x
03_BaosDatapointConfiguration.cpp

This demo shows how to read datapoint descriptions via the device API.

Usage:

03_BaosDatapointConfiguration <ip_address>
// e.g.:
03_BaosDatapointConfiguration 10.0.0.102
Note
Another possibility is via the connection API.
See also: Sample GetDatapointDescription.cpp and GetDatapointDescriptionString.cpp
//
// Copyright (c) 2002-2023 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 <iostream>
#include <memory>
using namespace wz::baos;
using namespace wz::baos::ip;
int main(int argc, char* argv[])
{
try
{
std::cout << "******************************************" << std::endl;
std::cout << "03_BaosDatapointConfiguration sample" << std::endl;
std::cout << "******************************************" << std::endl;
std::cout << std::endl;
// Reduce log messages
setBaosLogLevel(wzcpp::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 with the remote BAOS device
BaosIp4Device baosDevice(ipAddress);
// reads all configured (enabled) datapoint descriptions from the device
DatapointConfigurations configurations = baosDevice.getAllDpConfigurations();
// trace the descriptions
for (const auto& item : configurations)
{
std::cout << "Datapoint id " << item.first << ": ";
const DatapointConfig& desc = item.second;
std::cout << toString(desc) << std::endl;
}
if (configurations.size() == 0)
{
std::cout << "No datapoints configured on the device" << std::endl;
}
}
catch (const std::exception& e)
{
std::cerr << "Failed: " << e.what() << std::endl;
return -1;
}
return 0;
}
Specialization for a IP v4 BAOSDevice.
Specialization for a TCP IP v4 BAOSConnection.
Global BAOS SDK function and options.
Definition: Helper.h:23
Global BAOS sdk namespace.
Definition: config.h:62
std::map< std::uint16_t, DatapointConfig > DatapointConfigurations
Definition: BaosDeviceDataTypes.h:212
void setBaosLogLevel(wzcpp::LogLevel level)
std::string toString(IOEvent::Type typ)
Provides a human readable string for an IOEvent type.
Definition: IOEvent.h:92