USB Libraries Help > USB Host Libraries > USB CDC Host Library > Library Interface > b) Data Transfer Functions > USB_HOST_CDC_Read Function
MPLAB Harmony USB Stack
USB_HOST_CDC_Read Function

This function will read data from the attached CDC device. The function will try to read size amount of bytes but will stop reading when the device terminates the USB transfer (sends a short packet or a ZLP). If the request was accepted, transferHandle will contain a valid transfer handle, else it will contain USB_HOST_CDC_TRANSFER_HANDLE_INVALID. The completion of the request will be indicated by the USB_HOST_CDC_EVENT_READ_COMPLETE event. The transfer handle will be returned in the event.

C
USB_HOST_CDC_RESULT USB_HOST_CDC_Read(
    USB_HOST_CDC_HANDLE handle, 
    USB_HOST_CDC_TRANSFER_HANDLE * transferHandle, 
    void * data, 
    size_t size
);
Preconditions

The client handle should be valid.

Parameters
Parameters 
Description 
handle 
handle to the CDC device instance to which the request should be sent.
 
transferHandle 
Pointer to USB_HOST_CDC_TRANSFER_HANDLE type of a variable. This will contain a valid transfer handle if the request was successful.
 
data 
pointer to the buffer where the received data will be stored. The contents of the buffer will be valid only when the USB_HOST_CDC_EVENT_READ_COMPLETE event has occurred.
 
size 
size of the data buffer. Only these many bytes or less will be read. 
Returns

USB_HOST_CDC_RESULT_SUCCESS - The operation was successful. 

USB_HOST_CDC_RESULT_DEVICE_UNKNOWN - The device that this request was targeted to does not exist in the system. 

USB_HOST_CDC_RESULT_BUSY - The request could not be scheduled at this time. The client should try again. 

USB_HOST_CDC_RESULT_INVALID_PARAMETER - An input parameter was NULL. 

USB_HOST_CDC_RESULT_FAILURE - An unknown failure occurred. 

USB_HOST_CDC_RESULT_HANDLE_INVALID - The client handle is not valid.

Remarks

None.

Example