15 #       include <setupapi.h>    25 #define XSENS_VENDOR_ID                         0x2639    26 #define ATMEL_VENDOR_ID                         0x03eb // needed for old MTw    27 #define ATMEL_BORROWED_PRODUCT_ID       0x2307 // needed for old MTw    42         ULONG requiredLength=0;
    45         GUID guid = { 0xfd51225c, 0x700a, 0x47e5, { 0x99, 0x99, 0xb2, 0xd9, 0x3, 0x1b, 0x88, 0xed } };
    48         SP_DEVICE_INTERFACE_DATA interfaceData;
    49         PSP_DEVICE_INTERFACE_DETAIL_DATA_A detailData = NULL;
    51         deviceInfo = SetupDiGetClassDevs(&guid, NULL, NULL,     DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
    54         interfaceData.cbSize = 
sizeof(SP_INTERFACE_DEVICE_DATA);
    56         for (DWORD dwIndex = 0; port == 0; ++dwIndex)
    58                 BOOL bRet = SetupDiEnumDeviceInterfaces( deviceInfo, NULL, &guid, dwIndex, &interfaceData);
    61                         if (GetLastError() == ERROR_NO_MORE_ITEMS)
    66                         if (!SetupDiGetDeviceInterfaceDetail(deviceInfo, &interfaceData, NULL, 0, &requiredLength, NULL))
    68                                 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
    70                                         SetupDiDestroyDeviceInfoList(deviceInfo);
    74                         detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA_A)LocalAlloc(LMEM_FIXED, requiredLength);
    75                         if (NULL == detailData)
    77                                 SetupDiDestroyDeviceInfoList(deviceInfo);
    81                         detailData->cbSize = 
sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
    83                         SP_DEVINFO_DATA DevInfoData;
    84                         DevInfoData.cbSize = 
sizeof(SP_DEVINFO_DATA);
    85                         bResult = SetupDiGetDeviceInterfaceDetailA(deviceInfo, &interfaceData, detailData, 
length, &requiredLength, &DevInfoData);
    89                                 LocalFree(detailData);
    90                                 SetupDiDestroyDeviceInfoList(deviceInfo);
    94                         unsigned char serialNumber[256];
    95                         char* ptrEnd, *ptrStart = strchr(detailData->DevicePath, 
'#');
    98                         ptrStart = strchr(ptrStart+1, 
'#');
   101                         ptrEnd = strchr(ptrStart+1, 
'#');
   105                         strncpy((
char*)serialNumber, ptrStart+1, ptrEnd-ptrStart-1);
   106                         serialNumber[ptrEnd-ptrStart-1] = 
'\0';
   108                         current.setPortName(detailData->DevicePath);
   111                         sscanf((
const char *)serialNumber, 
"%X", &
id);
   114                         ports.push_back(current);
   118         SetupDiDestroyDeviceInfoList(deviceInfo);
   122         libusb_context *context;
   123         int result = libUsb.
init(&context);
   124         if (result != LIBUSB_SUCCESS)
   127         libusb_device **deviceList;
   129         for (ssize_t i = 0; i < deviceCount; i++)
   131                 libusb_device *device = deviceList[i];
   132                 libusb_device_descriptor desc;
   134                 if (result != LIBUSB_SUCCESS)
   140                 libusb_device_handle *handle;
   141                 result = libUsb.
open(device, &handle);
   142                 if (result != LIBUSB_SUCCESS)
   148                 unsigned char serialNumber[256];
   153                         unsigned char productName[256];
   156                         if (strcmp(
"Xsens COM port", (
const char *)productName) != 0)
   158                                 libUsb.
close(handle);
   163                 libusb_config_descriptor *configDesc;
   165                 if (result != LIBUSB_SUCCESS)
   168                 bool kernelActive = 
false;
   169                 for (
uint8_t ifCount = 0; ifCount < configDesc->bNumInterfaces; ++ifCount) {
   171                         kernelActive |= (
res == 1);
   182                         current.setPortName(
name);
   185                         sscanf((
const char *)serialNumber, 
"%d", &
id);
   187                         ports.push_back(current);
   191                         JLDEBUG(gJournal, 
"Kernel driver active on USB" <<
   193                                         " device " << serialNumber);
   196                 libUsb.
close(handle);
   199         libUsb.
exit(context);
 
libUSB_unref_device unref_device
 
libUSB_free_config_descriptor free_config_descriptor
 
#define ATMEL_BORROWED_PRODUCT_ID
 
libUSB_get_string_descriptor_ascii get_string_descriptor_ascii
 
libUSB_free_device_list free_device_list
 
bool xsEnumerateUsbDevices(XsPortInfoList &ports)
Enumerate Xsens USB devices. 
 
libUSB_get_device_list get_device_list
 
libUSB_get_device_descriptor get_device_descriptor
 
libUSB_kernel_driver_active kernel_driver_active
 
GLuint GLsizei GLsizei * length
 
GLuint const GLchar * name
 
int BASE_IMPEXP sprintf(char *buf, size_t bufSize, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
 
libUSB_get_device_address get_device_address
 
unsigned __int32 uint32_t
 
libUSB_get_bus_number get_bus_number
 
libUSB_get_active_config_descriptor get_active_config_descriptor