Truxton usb get product id

From truxwiki.com
Jump to navigation Jump to search

This retrieves the identifier of the product of the USB device as assigned by the vendor. This corresponds to the [PID] column of the [USBDevice] table.

Syntax

uint64_t truxton_usb_get_product_id( uint64_t usb_handle );

Parameters

usb_handle

This handle comes from calling truxton_usb_create().

Return value

The product identifier as stored in the [PID] column in the [USBDevice] table.

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.