【问题标题】:ReadPipe hangs on Mac OS X 10.11ReadPipe 在 Mac OS X 10.11 上挂起
【发布时间】:2015-10-17 18:57:48
【问题描述】:

我使用了 Apple 示例中的代码:

// Send data through out pipe
ret = (*usbInterface)->WritePipe(usbInterface, bulkOutRef, (void *)kTestMessage, 4);
if (ret != kIOReturnSuccess)
{
   NSLog(@"Write failed (error: %x)\n", ret);
}
// Read data through in pipe 
numBytes = 64;
inp = malloc(numBytes);
ret = (*usbInterface)->ReadPipe(usbInterface, bulkInRef, inp, &numBytes);

使用GetPipeProperties 检查管道引用(并使用USB Prober 进行双重检查)。 我也尝试过异步版本,结果相同:写入工作(似乎可以),读取挂起。 我还尝试了使用usbtrace 进行一些调试:启动一次并退出后,它现在总是返回The trace facility is currently in use。 USB 设备是 Microchip USB 入门工具包 II。 任何的想法? 谢谢,

米歇尔

【问题讨论】:

  • 可能不是问题,但您的“bulkInRef”是什么?
  • 这是一个 Uint 8,对输入管道的引用。在我的例子中,值为 2。
  • 也许检查它是否是一个输入管道: (*usbInterface)->GetPipeProperties(usbInterface, 1, &directionOut, &number, &transferType, &maxPacketSize, &interval); (*usbInterface)->GetPipeProperties(usbInterface, 2, &direction2, &number, &transferType, &maxPacketSize, &interval);如果(方向输出!=方向2){}
  • 是的,谢谢,我已经检查过了,请看我的问题。
  • 您确定设备已正确编程以响应相关读取请求吗?如果没有,IOKit 就会挂在那里。使用允许指定超时的读取和写入管道方法变体通常是一个好主意。

标签: macos cocoa usb iokit


【解决方案1】:

问题是我必须在 OUT 管道上使用 WritePipe 向设备发送请求,然后在 IN 管道上使用 ReadPipe 读取响应。没看懂,是我的错。

【讨论】:

    猜你喜欢
    • 2016-05-10
    • 2016-12-22
    • 1970-01-01
    • 2016-04-09
    • 2016-03-20
    • 2016-10-08
    • 1970-01-01
    • 2016-07-13
    相关资源
    最近更新 更多