2009-12-07 85 views
1

我花了/Developer/Examples/IOKit/usb/USBSimple Example並修改它,以便它實際上將一些數據傳輸給設備(並希望很快)。Mac應用程序掛在USB設備上的ReadPipe

這是我的transferData功能(評論):

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; 
    } 
} 

因此,代碼的讀取部分掛起,直到我斷開該設備時,其輸出transferData: ReadPipeFailed, err = e00002ed - 這證實了我其實是在說/聽設備。

我去了這個同步方法,而不是蘋果的例子,它使用異步方法來簡化事情,但無濟於事。設備是否響應?但是,如果它不應該該方法只是跳過並在numBytesRead返回0?

任何提示?我承認我是Mac OS X編程的新手,但今天我幾乎整天都把它翻了出來,沒有任何運氣。

+0

Did一個快速的谷歌,看到圍繞這個東西的一些問題是相當複雜的。可能需要一段時間才能解決這個問題...我對這個問題很感興趣,因爲我想爲Mac編寫一些USB代碼,所以如果我有一些時間,我可以深入瞭解一下。與此同時,我發現了一個引用,暗示numBytesRead的值可能很重要。我認爲,您應該瞭解與Mac驅動程序軟件一樣多的設備,這一點很重要。 – 2009-12-08 04:23:06

+0

我不知道答案,但如果您在這裏沒有任何運氣,問這個問題的好地方將是Apple USB開發郵件列表。 [http://lists.apple.com/mailman/listinfo/usb](http://lists.apple.com/mailman/listinfo/usb)這是一個相當活躍的電子郵件列表,並配有一些優秀的Apple USB工程師。 – 2009-12-08 05:56:29

回答

3

我想通了。

問題是我從枚舉它們的函數接收到不正確的管道編號,然後調用這個函數 - 這是未觸及的Apple示例代碼。

類似於我正在寫入管道1並等待管道2的響應。通過大量的試驗和錯誤以及允許我在不同管道上發送和觀察數據的Windows實用程序,我意識到我需要寫入管道3並從管道4讀取。管道號可能會交換(我對數字不太好),但分組是OK的 - 必須使用3和4而不是1和2.

相關問題