I'm trying to (re-)write a program that uses USB controlled scanners. I've got my USBIOInterfaceInterface
set up, so I can send and receive messages over the pipes. I am successfully calling WritePipeTO
and ReadPipeTO
synchronously but I want to read from the scanner asynchronously.
I've tried using ReadPipeAsyncTO
, but the callback never gets called until the call timesout. The reason Appears to be that I'm not registering the callback somewhere. If I add a CFRunLoopRun
after the async read, then it appears to work, but only by having many nested calls to CFRunLoopRun
, which can't be a good idea.
I've seen the functions:
err = (*usbInterfaceInterface)->CreateInterfaceAsyncEventSource(usbInterfaceInterface, &cfSource);
CFRunLoopAddSource(CFRunLoopGetCurrent(), cfSource, kCFRunLoopDefaultMode);
but I haven't figured out how to tell the Source what callback should be called when something happens on that interface. When I just create the source, and call the ReadPipeAsyncTO
, the callback doesn't get called until timeout.
Is there same sample code somewhere so I can see how these functions are SUPPOSED to work together?