This tutorial describes how to write shared chunk data to a USB connection.
To write data from the device to the host (In), read some data (e.g. from a media card on the device) to a shared chunk and make a write request to the driver. Use RDevUsbcScClient::WriteData() to send data placed inside a shared chunk to the USB hardware.
TUsbcScChunkHeader chunkHeader(gChunk); TUsbcScHdrEndpointRecord* epInfo; TRequestStatus status; TUsbcScBufferRecord* buff = chunkHeader.GetBuffer(0, 1, epInfo); TInt inBuffNum = epInfo->iBufferNo; TUint bufferOffset = buff->Offset(); TUint length = buff->Size(); gPort.WriteData(inBuffNum, bufferOffset, length, 1, status);
The function WriteData() does not take an endpoint as a parameter. To send data to a particular endpoint the data must be put in the correct buffer. Find the buffer number in the chunk header with the endpoint number and the current alternate setting. See Setting the interface to see how alternate settings are created.
When sending buffers using this function, if a second buffer is ready to send before the first has finished transmitting then the second buffer can be sent to the LDD. The LDD will start sending the data in the second buffer when the first has finished. This reduces the delay between finishing one and transmitting the next. To do this the TRequestStatus objects must be kept track of as only one of these can be used with each request.
Note: an offset is provided that allows a buffer to be split into parts. This allows you to fill one half while sending the other.
When the request has completed, if there is no more data to be sent then close the channel and unload the driver.
When you have finished reading and writing Close and Unload the Driver.