DOC Skip to main content

C++ Sample Device Control

Update on 2025-07-25 07:09:21

Function description: Demonstrate Device control operations

| This example is based on the C++low level API for demonstration

Get device list

// Create a Context.
ob::Context context;

// Query the list of connected devices
auto deviceList = context.queryDeviceList();

Get device and output device information

if(deviceList->deviceCount() > 0) {
    if(deviceList->deviceCount() <= 1) {
        // If a single device is plugged in, the first one is selected by default
        device = deviceList->getDevice(0);
    }
    else {
        device = selectDevice(deviceList);
    }
    auto deviceInfo = device->getDeviceInfo();
    std::cout << "\n------------------------------------------------------------------------\n";
    std::cout << "Current Device: "
                << " name: " << deviceInfo->name() << ", vid: 0x" << std::hex << deviceInfo->vid() << ", pid: 0x" << std::setw(4) << std::setfill('0')
                << deviceInfo->pid() << ", uid: 0x" << deviceInfo->uid() << std::dec << std::endl;
}

Follow the prompts to get all properties

std::cout << "Input \"?\" to get all properties." << std::endl;
std::getline(std::cin, choice);

Input parameter prompt

std::cout << "Property control usage: [property index] [set] [property value] or [property index] [get]" << std::endl;

Get property

getPropertyValue(device, propertyItem);

Set property

setPropertyValue(device, propertyItem, controlVec.at(2));

Expected Output

ON THIS PAGE

Add

  • Name:

  • Link Address:

Cancel

Add

  • Name:

  • Link Address:

Cancel
Questions or
Feedback?

Feedback

  • Your feedback matters! Share your thoughts on this page, report errors, or let us know how we can improve to better support your needs. If applicable, please include the specific sentence or section to help us identify and address the issue.