Jump to content

UsbDataTransfer: Difference between revisions

From EDM2
W.m.brul (talk | contribs)
updated syntax and added parameter descriptions and example code
W.m.brul (talk | contribs)
updated example code
Line 60: Line 60:
   UCHAR ucData[4096];
   UCHAR ucData[4096];
   UCHAR ucEndpoint;
   UCHAR ucEndpoint;
  ULONG ulNumBytes;
  ULONG ulTimeout = 8000;
   USHORT usFlags;
   USHORT usFlags;
  ULONG ulNumBytes = sizeof(ucData);
  ULONG ulTimeout = 8000;


   //device-to-host
   //device-to-host
   ucEndpoint = 0x81; usFlags = 0;
   ucEndpoint = 0x81; usFlags = 0;
   pucData = &ucData[0]; pulNumBytes = &ulNumBytes;
   pucData = &ucData[0]; pulNumBytes = &ulNumBytes; ulNumBytes = sizeof(ucData);
   ulrc = UsbDataTransfer(Handle,ucEndpoint,ucAltSetting,pulNumBytes,pucData,ulTimeout,usFlags);
   ulrc = UsbDataTransfer(Handle,ucEndpoint,ucAltSetting,pulNumBytes,pucData,ulTimeout,usFlags);
   printf("\nUsbDataTransfer - ulrc: 0x%04X (%hu)",ulrc,ulrc);
   printf("\nUsbDataTransfer - ulrc: 0x%04X (%hu)",ulrc,ulrc);
Line 77: Line 77:
   //host-to-device
   //host-to-device
   ucEndpoint = 0x02; usFlags = USB_TRANSFER_FULL_SIZE;
   ucEndpoint = 0x02; usFlags = USB_TRANSFER_FULL_SIZE;
   pucData = &ucData[0]; pulNumBytes = &ulNumBytes;
   pucData = &ucData[0]; pulNumBytes = &ulNumBytes; ulNumBytes = sizeof(ucData);
   ulrc = UsbDataTransfer(Handle,ucEndpoint,ucAltSetting,pulNumBytes,pucData,ulTimeout,usFlags);
   ulrc = UsbDataTransfer(Handle,ucEndpoint,ucAltSetting,pulNumBytes,pucData,ulTimeout,usFlags);
   printf("\nUsbDataTransfer - ulrc: 0x%04X (%hu)",ulrc,ulrc);
   printf("\nUsbDataTransfer - ulrc: 0x%04X (%hu)",ulrc,ulrc);

Revision as of 18:39, 7 February 2017

Description

Executes synchronous Bulk or Interrupt Transfer with a specific endpoint.

Syntax

ulrc = UsbDataTransfer(Handle,ucEndpoint,ucAltSetting,pulNumBytes,pucData,ulTimeout,usFlags)

Parameters

Handle
the Device Handle received from the previous UsbOpen.
ucEndpoint
the Endpoint Number appropriate for the data transfer.
ucAltSetting
the Alternate Setting of the interface having this endpoint.
ulTimeout
the timeout to wait for completion in milliseconds.
usFlags
use 1 to transfer all data or 0 to allow less transferred.

For device-to-host data transfer:

pulNumBytes
the address of the variable to specify/receive the number of bytes.
pucData
the address of the buffer to receive the data bytes transferred.

For host-to-device data transfer:

pulNumBytes
the address of the variable to specify/receive the number of bytes.
pucData
the address of the buffer with the data bytes to be transferred.

Return Code

0x0000 - NO_ERROR

Errors

0x0006 - ERROR_INVALID_HANDLE
0x0008 - ERROR_NOT_ENOUGH_MEMORY
0x0057 - ERROR_INVALID_PARAMETER
0x005F - ERROR_INTERRUPT
0x0122 - ERROR_TOO_MANY_HANDLES
0x0280 - ERROR_TIMEOUT
0x1B58 - USB_NOT_INIT
0x1B5B - USB_ERROR_INVALID_ENDPOINT
0x1B5C - USB_ERROR_LESSTRANSFERED
0x4000 - USB_IORB_REQUEST
0x80XX - USB_IORB_FAILED

Remarks

Example Code

//Code Snippet - UsbDataTransfer
{
  APIRET ulrc;
  PUCHAR pucData;
  PULONG pulNumBytes;
  UCHAR ucAltSetting = 0;
  UCHAR ucData[4096];
  UCHAR ucEndpoint;
  ULONG ulNumBytes;
  ULONG ulTimeout = 8000;
  USHORT usFlags;

  //device-to-host
  ucEndpoint = 0x81; usFlags = 0;
  pucData = &ucData[0]; pulNumBytes = &ulNumBytes; ulNumBytes = sizeof(ucData);
  ulrc = UsbDataTransfer(Handle,ucEndpoint,ucAltSetting,pulNumBytes,pucData,ulTimeout,usFlags);
  printf("\nUsbDataTransfer - ulrc: 0x%04X (%hu)",ulrc,ulrc);
  if (!ulrc) //success
  {
    int i; printf(" - bulk data:\n");
    for (i=0;i<ulNumBytes;i++) printf("%02X",ucData[i]);
  }

  //host-to-device
  ucEndpoint = 0x02; usFlags = USB_TRANSFER_FULL_SIZE;
  pucData = &ucData[0]; pulNumBytes = &ulNumBytes; ulNumBytes = sizeof(ucData);
  ulrc = UsbDataTransfer(Handle,ucEndpoint,ucAltSetting,pulNumBytes,pucData,ulTimeout,usFlags);
  printf("\nUsbDataTransfer - ulrc: 0x%04X (%hu)",ulrc,ulrc);
  if (!ulrc) //success
  {
    int i; printf(" - bulk data:\n");
    for (i=0;i<ulNumBytes;i++) printf("%02X",ucData[i]);
  }
}

Related Functions