This example demonstrates usage of the C++ API to enumerate devices, channels and attributes.
#include <iostream>
#include <iomanip>
using namespace std;
string get(
Attr const & att)
{
att.read_raw(value, sizeof(value));
}
void enumerateIioEntities()
{
cout << boolalpha;
for (
Device device : *context)
{
cout << "Device:" << endl;
cout << " id: " << quoted(string(device.id())) << endl;
cout << " name: ";
if (auto name = device.name())
cout << quoted(string(*name));
cout << endl;
cout << " is trigger: " << device.is_trigger() << endl;
for (auto att : device.attrs)
cout << " attribute " << att.name() << " = " << quoted(get(att)) << endl;
for (auto att : device.debug_attrs)
cout << " debug attribute " << att.name() << " = " << quoted(get(att)) << endl;
{
cout << " Channel: " << channel.id() << endl;
cout << " name: ";
if (auto name = channel.name())
cout << quoted(string(*name));
cout << endl;
cout << " is output: " << channel.is_output() << endl;
for (auto att : channel.attrs)
cout << " attribute " << quoted(att.name().c_str()) << " = " << quoted(get(att)) << endl;
}
}
ScanPtr s = scan(
nullptr,
nullptr);
cout << "scan returned " << s->size() << " results" << endl;
for (ScanResult r : *s)
{
cout << " uri: " << quoted(r.uri().c_str()) << endl;
cout << " description: " << quoted(r.description().c_str()) << endl;
}
}
int main(int argc, char ** argv)
{
try
{
enumerateIioEntities();
}
{
cerr << "ERROR " << e.code().value() << ": " << e.what() << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}