UsbCtrlTransfer
Appearance
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]); } }