Query Serial-Number from All Connected Devices and Open Device by specify Serial-Number
About
This is utility functions for query serial number and open device by specify serial number.
You can open device by specify serial number in Azure Kinect SDK similar to RealSense SDK.
I think these functions will be useful for all Azure Kinect developers.
There is no need to make any changes to the Azure Kinect SDK to use these functions.
Just add these file to your project.
Sample
- C++
#include <iostream>
#include <sstream>
#include <k4a/k4a.hpp>
#include "utility.h"
int main( int argc, char* argv[] )
{
try{
// Query serial numbers from all connected devices
std::vector<std::string> serial_numbers = k4a::device_query();
if( serial_numbers.empty() ){
throw k4a::error( "serial_numbers is empty!" );
}
// Open device by specify serial number
k4a::device device = k4a::device_open( serial_number[0] ); // Specify string retrieved from k4a::device_query()
//k4a::device device = k4a::device_open( "000000000000" ); // Specify 12-digits string directly
if( !device.is_valid() ){
throw k4a::error( "failed open device!" );
}
device.close();
}
catch( k4a::error& error ){
std::cout << error.what() << std::endl;
}
return 0;
}
- C#
using System;
using System.Linq;
using System.Collections.Generic;
using K4A = Microsoft.Azure.Kinect.Sensor;
class Program
{
static void Main(string[] args)
{
try
{
// Query serial numbers from all connected devices
var serial_numbers = K4A.Utility.Device.Query();
if (!serial_numbers.Any())
{
throw new K4A.AzureKinectException("devices not found!");
}
// Open device by specify serial number
var device = K4A.Utility.Device.Open(serial_numbers[0]); // Specify string retrieved from Device.Query()
//var device = K4A.Utility.Device.Open("000000000000"); // Specify 12-digits string directly
if (device == null)
{
throw new K4A.AzureKinectException("failed open device!");
}
device.Dispose();
device = null;
}
catch (K4A.AzureKinectException error)
{
Console.WriteLine(error.Message);
}
}
}