Jump to content

UsbCtrlMessage: Difference between revisions

From EDM2
W.m.brul (talk | contribs)
Ak120 (talk | contribs)
mNo edit summary
 
(One intermediate revision by one other user not shown)
Line 3: Line 3:


==Syntax==
==Syntax==
<pre>
ulrc = UsbCtrlMessage(Handle,ucRequestType,ucRequest,usValue,usIndex,usLength,pucData,ulTimeout)
ulrc = UsbCtrlMessage(Handle,ucRequestType,ucRequest,usValue,usIndex,usLength,pucData,ulTimeout)
</pre>


==Parameters==
==Parameters==
; Handle : the Device Handle received from the previous UsbOpen.
; Handle : the Device Handle received from the previous [[UsbOpen]].
 
; ucRequestType : the characteristics of the Standard Device Request.  
; ucRequestType : the characteristics of the Standard Device Request.  
; ucRequest : the specific request code 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.
; usValue : the request dependent value of the Standard Device Request.
; usIndex : the request dependent index of the Standard Device Request.
; usIndex : the request dependent index of the Standard Device Request.
; ulTimeout : the timeout to wait for completion in milliseconds.
; ulTimeout : the timeout to wait for completion in milliseconds.
''For device-to-host data transfer:''
''For device-to-host data transfer:''
; usLength : the number of bytes to be transferred or 0 for no data transfer.
; usLength : the number of bytes to be transferred or 0 for no data transfer.
; pucData : the address of the buffer to receive the data bytes transferred.  
; pucData : the address of the buffer to receive the data bytes transferred.  
''For host-to-device data transfer:''
''For host-to-device data transfer:''
; usLength : the number of bytes to be transferred or 0 for no data transfer.
; usLength : the number of bytes to be transferred or 0 for no data transfer.
; pucData : the address of the buffer with the data bytes to be transferred.
; pucData : the address of the buffer with the data bytes to be transferred.


==Return Code==
==Return Code==
<pre>
0x0000 - NO_ERROR
0x0000 - NO_ERROR
 
</pre>
===Errors===
===Errors===
<pre>
<pre>
Line 99: Line 85:


==Related Functions==
==Related Functions==
* [[UsbDeviceGetDescriptor]]
* [[UsbConfigurationGetDescriptor]]
* [[UsbDeviceSetConfiguration]]
* [[UsbInterfaceSetAltSetting]]
* [[UsbEndpointClearHalt]]
* [[UsbQueryDeviceReport]]
* [[UsbOpen]]


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

Latest revision as of 20:45, 13 September 2021

Description

Executes synchronous Control Transfer with the default endpoint.

Syntax

ulrc = UsbCtrlMessage(Handle,ucRequestType,ucRequest,usValue,usIndex,usLength,pucData,ulTimeout)

Parameters

Handle
the Device Handle received from the previous UsbOpen.
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:

usLength
the number of bytes to be transferred or 0 for no data transfer.
pucData
the address of the buffer to receive the data bytes transferred.

For host-to-device data transfer:

usLength
the number of bytes to be transferred or 0 for no data transfer.
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 - UsbCtrlMessage
{
  APIRET ulrc;
  PUCHAR pucReport;
  UCHAR ucReport[4096];
  UCHAR ucRequestType;
  UCHAR ucRequest;
  ULONG ulTimeout = 8000;
  USHORT usIndex;
  USHORT usLength;
  USHORT usValue;

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

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

Related Functions