Truxton usb get device id

From truxwiki.com
Jump to navigation Jump to search

This retrieves the identifier of the device as assigned by Windows. This corresponds to the [DeviceID] column of the [USBDevice] table.

Syntax

void truxton_usb_get_device_id( uint64_t usb_handle, char * destination_string, size_t max_size );

Parameters

usb_handle

This handle comes from calling truxton_usb_create().

destination_string

The string to be written to.

max_size

The maximum number of characters that can be written to destination_string.

Sample

void dump_usb(uint64_t usb_handle)
{
   uint64_t integer_value = 0;

   char temp_string[ 1024 ];

   truxton_usb_get_id( usb_handle, temp_string, sizeof(temp_string) );
   printf( "USB ID is %s\n", temp_string );

   truxton_usb_get_media_id( usb_handle, temp_string, sizeof(temp_string) );
   printf( "Media ID is %s\n", temp_string );

   truxton_usb_get_file_id( usb_handle, temp_string, sizeof(temp_string) );
   printf( "File ID is %s\n", temp_string );

   truxton_usb_get_device_id( usb_handle, temp_string, sizeof(temp_string) );
   printf( "Device ID is \"%s\"\n", temp_string );

   integer_value = truxton_usb_get_device_type( usb_handle );
   printf( "Device type is %" PRIu64 "\n", integer_value );

   integer_value = truxton_usb_get_file_offset( usb_handle );
   printf( "File offset is %" PRIu64 "\n", integer_value );

   integer_value = truxton_usb_get_vendor_id( usb_handle );
   printf( "VID is %" PRIu64 "\n", integer_value );

   integer_value = truxton_usb_get_product_id( usb_handle );
   printf( "PID is %" PRIu64 "\n", integer_value );

   integer_value = truxton_usb_get_revision( usb_handle );
   printf( "Revision is %" PRIu64 "\n", integer_value );

   integer_value = truxton_usb_get_when( usb_handle );
   printf( "When is %" PRIu64 "\n", integer_value );
}

The PRIu64 in the sample code above is a standard way of formatting a 64-bit unsigned integer in C. Over the years, different compilers on different operating systems used different format specifiers for things, these PRI macros, along with some tricky string concatenation the compilers perform for you, allow you to maintain a single code base without a bunch of macro magic.