title: Mac application hangs on ReadPipe from USB device
body: <p>I took <code>/Developer/Examples/IOKit/usb/USBSimple Example</code> and modified it so that it actually transfers some data to (and hopefully soon from) the device.</p>
  
  <p>Here's my transferData function (commented):</p>
  
  <pre><code>void transferData(IOUSBInterfaceInterface245 **intf, UInt8 inPipeRef, UInt8 outPipeRef)
  {
      IOReturn err;
      CFRunLoopSourceRef cfSource;
  
      err = (*intf)-&gt;CreateInterfaceAsyncEventSource(intf, &amp;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)-&gt;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)-&gt;ReadPipe(intf, inPipeRef, inBuf, &amp;numBytesRead);
      if(err) {
          printf("transferData: ReadPipeFailed, err = %08x\n", err);
          return;
      }
  }
  </code></pre>
  
  <p>So the read part of the code hangs until I disconnect the device when it outputs <code>transferData: ReadPipeFailed, err = e00002ed</code> - which confirms that I'm actually talking / listening to the device.</p>
  
  <p>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?</p>
  
  <p>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.</p>