Adaptation/GUID-4C4515EA-A5DD-56B4-94B0-EE48D66013F7.dita
author Graeme Price <GRAEME.PRICE@NOKIA.COM>
Fri, 15 Oct 2010 14:32:18 +0100
changeset 15 307f4279f433
permissions -rw-r--r--
Initial contribution of the Adaptation Documentation.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="GUID-4C4515EA-A5DD-56B4-94B0-EE48D66013F7" xml:lang="en"><title>Read Data from USB using Shared Chunks </title><shortdesc>This tutorial describes how to read shared chunk data from
a USB connection. </shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
<section id="GUID-0197C58A-668F-4C8F-966B-A41F31F41A7A"><title>Read data</title> <p>To read data from the host to
the device (<codeph>Out</codeph>) call the function <xref href="GUID-4D1AE286-41EE-3361-948A-3E8634D81DBA.dita#GUID-4D1AE286-41EE-3361-948A-3E8634D81DBA/GUID-4BE585C8-89BF-31D6-865D-85F6C7CBF88B"><apiname>RDevUsbcScClient::ReadDataNotify()</apiname></xref> to make a request to wait for data in the specified buffer and wait
for it to complete. </p> <p>If the buffer already has data in it,
it will return immediately with the code <codeph>KErrCompletion</codeph>. If there is no data in the buffer an asynchronous request is set
up that will complete when data is available. <b>Note</b>: check the
return code before attempting to wait for the request to complete. </p> <codeblock id="GUID-655AFB03-5EC8-5CA5-A15B-8DFC33126026" xml:space="preserve">TUsbcScHdrEndpointRecord* epInfo;
TRequestStatus status;

TUsbcScChunkHeader chunkHeader(gChunk);
    
chunkHeader.GetBuffer(0, 2, epInfo);  
TInt outBuffNum = epInfo-&gt;iBufferNo;

r = gPort.ReadDataNotify(outBuffNum,status);</codeblock> <p>The first
parameter required by <codeph>ReadDataNotify()</codeph> is the endpoint
buffer number. The endpoint buffer number can be found in the alternate
setting table in the chunk header. The location of the buffer can
be found by looking at the buffer offset table, which is also in the
chunk header. </p> <p>When the request has completed, process the
data in the buffer that was read from the driver. </p> <p>The transfer
buffer for an IN endpoint is always pointed to by the <codeph>iTail</codeph> member of the endpoint buffer struct <xref href="GUID-8A844723-82FA-3BB8-B6AD-4E5FC6B5431B.dita"><apiname>SUsbcScBufferHeader</apiname></xref>. When finished processing the current chunk move <codeph>iTail</codeph> to point to the next transfer buffer. </p> <codeblock id="GUID-FA53E100-1C6F-5252-9FC3-586EF4467EC6" xml:space="preserve">iTransfer = (TUsbcScTransferHeader*) (iHeader-&gt;iTail + iBase);
... // Process data
iHeader-&gt;iTail = iTransfer-&gt;iNext;</codeblock> <p>If there is no more
data to be read then close the channel and unload the driver. </p> </section>
<section id="GUID-F015D0C6-0325-45CA-A6FD-2E6E1D7FB78D"><title>Next steps</title> <p>When you have finished reading
and writing <xref href="GUID-BE73CFE6-D48D-5B92-AF49-E2D967ADF0EC.dita">Close and Unload the Driver</xref>. </p> </section>
</conbody></concept>