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
Synchronous Transfer
Go to RapidDriver Main Page

Synchronous Transfer
Transfer data in synchronous mode using function UsbTransfer is rather simple but it blocks calling thread execution until transfer completes. The following is an example of blocking transfer assuming that all handles are opened. Error checks are omitted. For extended information about synchronous transfer refer to 'Pipes' example.
   
   
   USB_DEVICE_HANDLE hUsb;
   USB_PIPE_HANDLE hPipe;
   PVOID pBuffer;
   ULONG BufferLength, BytesReturned;

   // Open first RapidUSB device
   hUsb = OpenRapidUsb(0);
   
   // Open first RapidUSB device pipe
   hPipe = UsbPipeOpen(hUsb, 0);

   // Allocate transfer buffer
   pBuffer = malloc(BufferLength);
   
   // Start transfer...
   BOOL success = UsbTransfer(hPipe, pBuffer, BufferLength, &BytesReturned);

   // thread waits transfer operation to finish
   
   if ( success)
   {
      // Transfer successful...
   }
   else
   {
      // Transfer failed....
   }

   free(pBuffer);

   UsbPipeClose(hPipe);
   CloseRapidUsb(hUsb);