UsbCtrlTransfer: Difference between revisions
Appearance
Created page with "==Description== Executes synchronous Control Transfer with a specific endpoint. ==Syntax== <pre> ulrc=UsbCtrlTransfer(Handle,Endpoint,AltInterface,ucRequestType,ucRequest,usV..." |
updated syntax and added parameter descriptions and example code |
||
Line 4: | Line 4: | ||
==Syntax== | ==Syntax== | ||
<pre> | <pre> | ||
ulrc=UsbCtrlTransfer(Handle, | 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. | ||
; | ; 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. | ||
; | ; usValue : the request dependent value of the Standard Device Request. | ||
; usIndex : | ; 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== | |||
<pre> | |||
0x0000 - NO_ERROR | |||
</pre> | |||
===Errors=== | |||
<pre> | |||
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 | |||
</pre> | |||
==Remarks== | ==Remarks== | ||
==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== | ||
[[Category:USBCalls]] | [[Category:USBCalls]] |
Revision as of 17:46, 25 January 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
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]); } }