I took /Developer/Examples/IOKit/usb/USBSimple Example
and modified it so that it actually transfers some data to (and hopefully soon from) the device.
Here's my transferData function (commented):
void transferData(IOUSBInterfaceInterface245 **intf, UInt8 inPipeRef, UInt8 outPipeRef)
{
IOReturn err;
CFRunLoopSourceRef cfSource;
err = (*intf)->CreateInterfaceAsyncEventSource(intf, &cfSource);
if(err) {
printf("transferData: unable to create event source, err = %08x\n", err);
return;
}
// this is what I need to send to the device
outBuf[0] = 0;
outBuf[1] = 0;
outBuf[2] = 0x18;
[... snip ...]
// the following works, although I have no confirmation
// that the data actually arrives to the device but err is 0 afterwards
err = (*intf)->WritePipe(intf, outPipeRef, outBuf, 64);
if(err) {
printf("transferData: WritePipeFailed, err = %08x\n", err);
return;
}
UInt32 numBytesRead;
numBytesRead = sizeof(inBuf);
// this hangs until I disconnect the device
err = (*intf)->ReadPipe(intf, inPipeRef, inBuf, &numBytesRead);
if(err) {
printf("transferData: ReadPipeFailed, err = %08x\n", err);
return;
}
}
So the read part of the code hangs until I disconnect the device when it outputs transferData: ReadPipeFailed, err = e00002ed
- which confirms that I'm actually talking / listening to the device.
I went for this synchronous method as opposed to Apple's example which uses an asynchronous approach to simplify things but to no avail. Isn't the device responding? But if it doesn't shouldn't the method just skip and return 0 in numBytesRead?
Any hints? I admit I'm a newbie to Mac OS X programming but I turned this inside out almost all day today without any luck.