tags:

views:

131

answers:

2

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.

+1  A: 

I don't know the answer, but if you don't have any luck here, a great place to ask this question would be the Apple USB development mailing list. http://lists.apple.com/mailman/listinfo/usb

It's a fairly active email list and is well staffed by some great Apple USB engineers.

Ken Aspeslagh
I've searched the archives of the USB list until my eyes fell out. :) Anyway, if I'll hit other snags like this I'll subscribe and ask there too. Thanks for the tip.
kitsched
+2  A: 

I figured it out.

The problem was that I was receiving incorrect pipe numbers from the function that was enumerating them and then calling this function - that was untouched Apple example code.

Something like, I was writing to pipe 1 and waiting for response on pipe 2. Through a ton of trial and error and a Windows utility that was allowing me to send and watch for data on different pipes, I realized that I needed to write to pipe 3 and read from pipe 4. The pipe numbers might be exchanged (I'm not too good with numbers) but the grouping is OK - had to use 3 and 4 instead of 1 and 2.

kitsched