Jump to content

UsbCtrlTransfer: Difference between revisions

From EDM2
Created page with "==Description== Executes synchronous Control Transfer with a specific endpoint. ==Syntax== <pre> ulrc=UsbCtrlTransfer(Handle,Endpoint,AltInterface,ucRequestType,ucRequest,usV..."
 
W.m.brul (talk | contribs)
 
(2 intermediate revisions by the same user not shown)
Line 4: Line 4:
==Syntax==
==Syntax==
<pre>
<pre>
ulrc=UsbCtrlTransfer(Handle,Endpoint,AltInterface,ucRequestType,ucRequest,usValue,usIndex,*pusLength,*pucData,ulTimeout)
ulrc = UsbCtrlTransfer(Handle,ucEndpoint,ucAltSetting,ucRequestType,ucRequest,usValue,usIndex,pusLength,pucData,ulTimeout)
</pre>
</pre>


==Parameters==
==Parameters==
; Handle :  
; Handle : the Device Handle received from the previous UsbOpen.


; Endpoint :
; ucEndpoint : the Endpoint Number appropriate for the control transfer.


; AltInterface :  
; ucAltSetting : the Alternate Setting of the interface having this endpoint.


; ucRequestType :  
; ucRequestType : the characteristics of the Standard Device Request.


; ucRequest :  
; ucRequest : the specific request code of the Standard Device Request.


; sValue :  
; usValue : the request dependent value of the Standard Device Request.


; usIndex :  
; usIndex : the request dependent index of the Standard Device Request.


; *pusLength :  
; ulTimeout : the timeout to wait for completion in milliseconds.


; *pucData :  
''For device-to-host data transfer:''


; ulTimeout :
; pusLength : 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:''
 
; pusLength : 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==
==Return Code==
 
<pre>
0x0000 - NO_ERROR
</pre>
===Errors===
===Errors===
 
<pre>
  [0000] - NO_ERROR
0x0006 - ERROR_INVALID_HANDLE
  [0006] - ERROR_INVALID_HANDLE
0x0008 - ERROR_NOT_ENOUGH_MEMORY
  [0008] - ERROR_NOT_ENOUGH_MEMORY
0x0057 - ERROR_INVALID_PARAMETER
  [0057] - ERROR_INVALID_PARAMETER
0x005F - ERROR_INTERRUPT
  [005F] - ERROR_INTERRUPT (95)
0x0122 - ERROR_TOO_MANY_HANDLES
  [0122] - ERROR_TOO_MANY_HANDLES (290)
0x0280 - ERROR_TIMEOUT
  [0280] - ERROR_TIMEOUT (640)
0x1B58 - USB_NOT_INIT
  [1B58] - USB_NOT_INIT (7000)
0x4000 - USB_IORB_REQUEST
  [4000] - USB_IORB_REQUEST
0x80XX - USB_IORB_FAILED
  [80XX] - USB_IORB_FAILED
0xFF0D - ERROR_INVALID_DATA
0xFF13 - ERROR_I24_INVALID_PARAMETER
0xFF13 - USB_IDC_PARMERR
0xFF18 - USB_IDC_ADDRINV
0xFF37 - ERROR_DEV_NOT_EXIST
0xFF5D - EROR_NO_ITEMS
0xFFA7 - ERROR_LOCK_FAILED
</pre>


==Remarks==
==Remarks==
Line 47: Line 64:
==Example Code==
==Example Code==
<pre>
<pre>
//Code Snippet - UsbCtrlTransfer
{
  APIRET ulrc;
  PUCHAR pucReport;
  PUSHORT pusLength;
  UCHAR ucAltSetting = 0;
  UCHAR ucEndPoint = 0;
  UCHAR ucReport[4096];
  UCHAR ucRequestType;
  UCHAR ucRequest;
  ULONG ulTimeout = 8000;
  USHORT usIndex;
  USHORT usLength;
  USHORT usValue;
  //device-to-host
  pucReport = &ucReport[0]; pusLength = &usLength;
  ucRequestType = 0xA1; ucRequest = 0x01; //get interface class report
  usIndex = 0x0000; usValue = 0x0300; usLength = 8; //hid feature report
  ulrc = UsbCtrlTransfer(Handle,ucEndPoint,ucAltSetting,ucRequestType,ucRequest,usValue,usIndex,pusLength,pucReport,ulTimeout);
  printf("\nUsbCtrlTransfer - ulrc: 0x%04X (%hu)",ulrc,ulrc);
  if (!ulrc) //success
  {
    int i; printf(" - hid feature report:\n");
    for (i=0;i<usLength;i++) printf("%02X",ucReport[i]);
  }
  //host-to-device
  pucReport = &ucReport[0]; pusLength = &usLength;
  ucRequestType = 0x21; ucRequest = 0x09; //set interface class report
  usIndex = 0x0000; usValue = 0x0300; usLength = 8; //hid feature report
  ulrc = UsbCtrlTransfer(Handle,ucEndPoint,ucAltSetting,ucRequestType,ucRequest,usValue,usIndex,pusLength,pucReport,ulTimeout);
  printf("\nUsbCtrlTransfer - ulrc: 0x%04X (%hu)",ulrc,ulrc);
  if (!ulrc) //success
  {
    int i; printf(" - hid feature report:\n");
    for (i=0;i<usLength;i++) printf("%02X",ucReport[i]);
  }
}
</pre>
</pre>
==Related Functions==
==Related Functions==
* [[UsbCtrlMessage]]
* [[UsbStartCtrlTransfer]]
* [[UsbOpen]]


[[Category:USBCalls]]
[[Category:USBCalls]]

Latest revision as of 17:31, 12 February 2017

Description

Executes synchronous Control Transfer with a specific endpoint.

Syntax

ulrc = UsbCtrlTransfer(Handle,ucEndpoint,ucAltSetting,ucRequestType,ucRequest,usValue,usIndex,pusLength,pucData,ulTimeout)

Parameters

Handle
the Device Handle received from the previous UsbOpen.
ucEndpoint
the Endpoint Number appropriate for the control transfer.
ucAltSetting
the Alternate Setting of the interface having this endpoint.
ucRequestType
the characteristics of the Standard Device Request.
ucRequest
the specific request code of the Standard Device Request.
usValue
the request dependent value of the Standard Device Request.
usIndex
the request dependent index of the Standard Device Request.
ulTimeout
the timeout to wait for completion in milliseconds.

For device-to-host data transfer:

pusLength
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:

pusLength
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
0x4000 - USB_IORB_REQUEST
0x80XX - USB_IORB_FAILED
0xFF0D - ERROR_INVALID_DATA
0xFF13 - ERROR_I24_INVALID_PARAMETER
0xFF13 - USB_IDC_PARMERR
0xFF18 - USB_IDC_ADDRINV
0xFF37 - ERROR_DEV_NOT_EXIST
0xFF5D - EROR_NO_ITEMS
0xFFA7 - ERROR_LOCK_FAILED

Remarks

Example Code

//Code Snippet - UsbCtrlTransfer
{
  APIRET ulrc;
  PUCHAR pucReport;
  PUSHORT pusLength;
  UCHAR ucAltSetting = 0;
  UCHAR ucEndPoint = 0;
  UCHAR ucReport[4096];
  UCHAR ucRequestType;
  UCHAR ucRequest;
  ULONG ulTimeout = 8000;
  USHORT usIndex;
  USHORT usLength;
  USHORT usValue;

  //device-to-host
  pucReport = &ucReport[0]; pusLength = &usLength;
  ucRequestType = 0xA1; ucRequest = 0x01; //get interface class report
  usIndex = 0x0000; usValue = 0x0300; usLength = 8; //hid feature report
  ulrc = UsbCtrlTransfer(Handle,ucEndPoint,ucAltSetting,ucRequestType,ucRequest,usValue,usIndex,pusLength,pucReport,ulTimeout);
  printf("\nUsbCtrlTransfer - ulrc: 0x%04X (%hu)",ulrc,ulrc);
  if (!ulrc) //success
  {
    int i; printf(" - hid feature report:\n");
    for (i=0;i<usLength;i++) printf("%02X",ucReport[i]);
  }

  //host-to-device
  pucReport = &ucReport[0]; pusLength = &usLength;
  ucRequestType = 0x21; ucRequest = 0x09; //set interface class report
  usIndex = 0x0000; usValue = 0x0300; usLength = 8; //hid feature report
  ulrc = UsbCtrlTransfer(Handle,ucEndPoint,ucAltSetting,ucRequestType,ucRequest,usValue,usIndex,pusLength,pucReport,ulTimeout);
  printf("\nUsbCtrlTransfer - ulrc: 0x%04X (%hu)",ulrc,ulrc);
  if (!ulrc) //success
  {
    int i; printf(" - hid feature report:\n");
    for (i=0;i<usLength;i++) printf("%02X",ucReport[i]);
  }
}

Related Functions