I have been able to read data with ReadPipe, but I am not
sure I am getting all the data, and in any case, I am told
I need to learn asynchronous reading for my application.
I think I did the same as some folks on this list: I took
the USBSimpleExample and tried to adapt it for an
asynchronous read.
I am imitating without any understanding. In my program
the last argument of ReadPipeAsync is inpipe, in another
err. What should it be in my case?
I get no error, and one printout from mycallBackFunction,
but whatever it is being printed out, it does not look like
data: I guess my data should be in gbuffer.
Where and when do I access my data?
thanks
anne
----------------------------------------------------
MyCallBackFunction(void *dummy, IOReturn result, void *arg0)
{
printf("MyCallbackfunction: %d, %d, %d\n", (int)dummy,
(int)result, (int)arg0);
CFRunLoopStop(CFRunLoopGetCurrent());
}
void transferData(IOUSBInterfaceInterface **intf, UInt8
inPipeRef)
{
IOReturn err;
CFRunLoopSourceRef cfSource;
int i;
char gBuffer[8];
UInt32 numBytesRead;
numBytesRead = sizeof(gBuffer);
err = (*intf)->CreateInterfaceAsyncEventSource(intf,
&cfSource);
if (err)
{
printf("transferData: unable to create event source,
err = %08x\n", err);
return;
}
CFRunLoopAddSource(CFRunLoopGetCurrent(), cfSource,
kCFRunLoopDefaultMode);
printf("Asynchronous event source added to run
loop\n");
err = (*intf)->ReadPipeAsync(intf, inPipeRef,
gBuffer, numBytesRead, (IOAsyncCallback1)MyCallBackFunction,
(void*)(UInt32)inPipeRef);
if (err != kIOReturnSuccess)
{
printf("Unable to perform asynchronous bulk read
(%08x)\n", err);
CFRunLoopRemoveSource(CFRunLoopGetCurrent(),
cfSource, kCFRunLoopDefaultMode);
return;
}
printf("transferData: calling CFRunLoopRun\n");
CFRunLoopRun();
printf("transferData: returned from CFRunLoopRun\n");
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), cfSource,
kCFRunLoopDefaultMode);
}