|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <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 |
|
13 a USB connection. </shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
14 <section id="GUID-0197C58A-668F-4C8F-966B-A41F31F41A7A"><title>Read data</title> <p>To read data from the host to |
|
15 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 |
|
16 for it to complete. </p> <p>If the buffer already has data in it, |
|
17 it will return immediately with the code <codeph>KErrCompletion</codeph>. If there is no data in the buffer an asynchronous request is set |
|
18 up that will complete when data is available. <b>Note</b>: check the |
|
19 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; |
|
20 TRequestStatus status; |
|
21 |
|
22 TUsbcScChunkHeader chunkHeader(gChunk); |
|
23 |
|
24 chunkHeader.GetBuffer(0, 2, epInfo); |
|
25 TInt outBuffNum = epInfo->iBufferNo; |
|
26 |
|
27 r = gPort.ReadDataNotify(outBuffNum,status);</codeblock> <p>The first |
|
28 parameter required by <codeph>ReadDataNotify()</codeph> is the endpoint |
|
29 buffer number. The endpoint buffer number can be found in the alternate |
|
30 setting table in the chunk header. The location of the buffer can |
|
31 be found by looking at the buffer offset table, which is also in the |
|
32 chunk header. </p> <p>When the request has completed, process the |
|
33 data in the buffer that was read from the driver. </p> <p>The transfer |
|
34 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->iTail + iBase); |
|
35 ... // Process data |
|
36 iHeader->iTail = iTransfer->iNext;</codeblock> <p>If there is no more |
|
37 data to be read then close the channel and unload the driver. </p> </section> |
|
38 <section id="GUID-F015D0C6-0325-45CA-A6FD-2E6E1D7FB78D"><title>Next steps</title> <p>When you have finished reading |
|
39 and writing <xref href="GUID-BE73CFE6-D48D-5B92-AF49-E2D967ADF0EC.dita">Close and Unload the Driver</xref>. </p> </section> |
|
40 </conbody></concept> |