我花了/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編程的新手,但今天我幾乎整天都把它翻了出來,沒有任何運氣。
Did一個快速的谷歌,看到圍繞這個東西的一些問題是相當複雜的。可能需要一段時間才能解決這個問題...我對這個問題很感興趣,因爲我想爲Mac編寫一些USB代碼,所以如果我有一些時間,我可以深入瞭解一下。與此同時,我發現了一個引用,暗示numBytesRead的值可能很重要。我認爲,您應該瞭解與Mac驅動程序軟件一樣多的設備,這一點很重要。 – 2009-12-08 04:23:06
我不知道答案,但如果您在這裏沒有任何運氣,問這個問題的好地方將是Apple USB開發郵件列表。 [http://lists.apple.com/mailman/listinfo/usb](http://lists.apple.com/mailman/listinfo/usb)這是一個相當活躍的電子郵件列表,並配有一些優秀的Apple USB工程師。 – 2009-12-08 05:56:29