Home    Prev Next    
Contents
Programming For USB Device
Overview
Programmers Guide
Scenario
Data transfer
Synchronous Transfer
Asynchronous Transfer
Reading Descriptors
USB Support Routines And Structures
Common Procedures
UsbEnumerateDevices
OpenRapidUsb
IsRapidUsbOpened
CloseRapidUsb
Descriptors
UsbGetDescriptor
UsbGetDeviceDescriptor
UsbGetStringDescriptor
UsbGetConfigDescriptor
UsbFreeConfigDescriptor
UsbGetInterfaceDescriptor
UsbFreeInterfaceDescriptor
UsbGetEndpointDescriptor
Configure Device
UsbGetDeviceInfo
UsbUnconfigureDevice
UsbSelectConfig
UsbGetConfig
UsbSelectInterface
UsbGetInterface
UsbResetDevice
UsbGetBandwidthInfo
UsbCyclePort
Features and Status
UsbSetFeature
UsbClearFeature
UsbGetStatus
Vendor/Class Requests
UsbVendorRequestIn
UsbVendorRequestOut
UsbClassRequestIn
UsbClassRequestOut
Pipes
IsRapidUsbPipeOpened
UsbPipeOpen
UsbPipeClose
UsbGetPipeCount
UsbPipeGetInfo
UsbPipeDirectionIn
UsbPipeGetType
UsbTransfer
UsbTransferAsync
TRANSFER_COMPLETION_ROUTINE
UsbCancelTransfer
UsbPipeReset
UsbPipeAbort
Other
UsbGetPortStatus
UsbGetCurrentFrameNumber
USB Structures and Types
RDUSB_DEVICE_INFORMATION
RDUSB_PIPE_INFORMATION
RDUSB_PIPE_TYPE
RDUSB_BANDWIDTH_INFORMATION
UsbGetStringDescriptor
Go to RapidDriver Main Page


Language

Description

C/C++
BOOL UsbGetStringDescriptor(IN  USB_DEVICE_HANDLE hUsb, 
IN  UCHAR Index,   
IN  LANGID LanguageId,  
OUT PUSB_STRING_DESCRIPTOR pStrDescr,  
IN OUT PULONG pStrLen);  
Delphi
function UsbGetStringDescriptor(hUsd         : USB_DEVICE_HANDLE;
                                Index        : UCHAR;
                                LanguaugeId  : LANGID;
                                var StrDescr : USB_STRING_DESCRIPTOR;
                                var StrLen   : Longint) : BOOL; stdcall;

VB
Function UsbGetStringDescriptor (ByVal hUsb As Long, _
                                 ByVal StrIndex As Byte, _
                                 ByVal LanguageId As Integer, _
                                 ByRef pDesc As USB_STRING_DESCRIPTOR, _
                                 ByRef Length As Long) As Boolean


Parameters
 
hUsb  
Specifies Handle to USB device.  
 
Index  
Specifies index of string descriptor.  
 
LanguageId  
Language ID of string descriptor.  
 
pStrDescr  
Points to user allocated memory. If function succeeds this buffer is filled with data from requested descriptor up to pStrLen length.  
 
pStrLen  
Length of pStrDescr buffer as input parameter. On successful return pStrLen equals to pStrDescr->bLength.  

Return Value
 
If function fails it return FALSE. To detect error call GetLastError function.  

Description
 
Use this function to retrieve string contained in USB string descriptor. This function can be used only after getting valid handle from OpenRapidUsb function.  

Example

   // open first RapidUSB device

   USB_HANDLE hUsb = OpenRapidUsb(0
);

   USB_STRING_DESCRIPTOR StrDescr;
   PUSB_STRING_DESCRIPTOR pStrDescr;
   ULONG nBytes;

   BOOL success;
   
   nBytes = sizeof(USB_STRING_DESCRIPTOR);

   // get length of string descriptor

   if (UsbGetStringDescriptor(hUsb, 1
, 0x409
, &StrDescr, &nBytes))
   {
      pStrDescr = (PUSB_STRING_DESCRIPTOR) calloc(1, nBytes + 2);
      
      if (UsbGetStringDescriptor(hUsb,StrIndex,LanguageId, pStrDescr, &nBytes))
      {
         // String retrieved successfully
      }

      free(pStrDescr);
   }

   CloseRapidUsb(hUsb);