MPLAB Harmony USB Stack
|
The application can receive data from the host by using the USB_DEVICE_CDC_Read function. This function returns a transfer handle that allows the application to track the read request. The request is completed when the Host sends the required amount or less than required amount of data. The application must make sure that it allocates a buffer size that is at least the size or a multiple of the receive endpoint size. The return value of the function indicates the success of the request. A read request could fail if the function driver transfer queue is full. The completion of the read transfer is indicated by the USB_DEVICE_CDC_EVENT_READ_COMPLETE event. The request completes based on the amount of the data that was requested and size of the transaction initiated by the Host:
The following code shows an example of the USB_DEVICE_CDC_Read function:
// Shows an example of how to read. This assumes that // driver was opened successfully. USB_DEVICE_CDC_TRANSFER_HANDLE transferHandle; USB_DEVICE_CDC_RESULT readRequestResult; USB_DEVICE_CDC_HANDLE instanceHandle; readRequestResult = USB_DEVICE_CDC_Read(instanceHandle, &transferHandle, data, 128); if(USB_DEVICE_CDC_RESULT_OK != readRequestResult) { //Do Error handling here } // The completion of the read request will be indicated by the // USB_DEVICE_CDC_EVENT_READ_COMPLETE event.
MPLAB Harmony USB Stack
|