folibis
folibis

Reputation: 12864

Implementing USB read timeout on MacOS and IOKit

I'm trying to implement USB driver for my application. It looks that all major function like initialization, reading and writing cold be easily realized using IOKit. But the problem I've faced is reading timeout, more truly missing of that functionality.

Actually, I use this tutorial to create my USB driver.

For example my code for reading looks like following:

QByteArray Read(UInt32 size)
{
    IOReturn result;
    char buffer[size];

    result = (*m_interface)->ReadPipe(m_interface, m_pipeIn, buffer, &size);
    if(result != kIOReturnSuccess)
    {
        SetError("Error reading from pipe", IErrorrable::ErrorTypes::Error, result);
        return QByteArray();
    }
    return QByteArray(buffer, size);
}

I have no clue how to implement reading timeout for this function. I would be very grateful if someone could help.

Upvotes: 1

Views: 411

Answers (1)

pmdj
pmdj

Reputation: 23438

Use the ReadPipeTO function instead of ReadPipe. There's also an async version, ReadPipeAsyncTO which may be of interest.

You may need to request a newer version of the IOUSBInterfaceInterface than what you're currently using, but that's not a problem as most of them go back to OS X versions from the PPC days.

Upvotes: 1

Related Questions